Module: Jets::Application::Configuration::Defaults

Extended by:
ActiveSupport::Concern
Included in:
Jets::Application::Configuration
Defined in:
lib/jets/application/configuration/defaults.rb

Overview

These are Jets specific defaults. The other defaults in Configuration come from using Rails components.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#apiObject

Returns the value of attribute api.



6
7
8
# File 'lib/jets/application/configuration/defaults.rb', line 6

def api
  @api
end

#api_modeObject

Returns the value of attribute api_mode.



6
7
8
# File 'lib/jets/application/configuration/defaults.rb', line 6

def api_mode
  @api_mode
end

#appObject

Returns the value of attribute app.



6
7
8
# File 'lib/jets/application/configuration/defaults.rb', line 6

def app
  @app
end

#buildObject

Returns the value of attribute build.



6
7
8
# File 'lib/jets/application/configuration/defaults.rb', line 6

def build
  @build
end

#cfnObject

Returns the value of attribute cfn.



6
7
8
# File 'lib/jets/application/configuration/defaults.rb', line 6

def cfn
  @cfn
end

#controllersObject

Returns the value of attribute controllers.



6
7
8
# File 'lib/jets/application/configuration/defaults.rb', line 6

def controllers
  @controllers
end

#default_iam_policyObject

Returns the value of attribute default_iam_policy.



6
7
8
# File 'lib/jets/application/configuration/defaults.rb', line 6

def default_iam_policy
  @default_iam_policy
end

#deployObject

Returns the value of attribute deploy.



6
7
8
# File 'lib/jets/application/configuration/defaults.rb', line 6

def deploy
  @deploy
end

#domainObject

Returns the value of attribute domain.



6
7
8
# File 'lib/jets/application/configuration/defaults.rb', line 6

def domain
  @domain
end

#environmentObject

Returns the value of attribute environment.



6
7
8
# File 'lib/jets/application/configuration/defaults.rb', line 6

def environment
  @environment
end

#eventsObject

Returns the value of attribute events.



6
7
8
# File 'lib/jets/application/configuration/defaults.rb', line 6

def events
  @events
end

#filter_parametersObject

Returns the value of attribute filter_parameters.



6
7
8
# File 'lib/jets/application/configuration/defaults.rb', line 6

def filter_parameters
  @filter_parameters
end

#functionObject

Returns the value of attribute function.



6
7
8
# File 'lib/jets/application/configuration/defaults.rb', line 6

def function
  @function
end

#gemsObject

Returns the value of attribute gems.



6
7
8
# File 'lib/jets/application/configuration/defaults.rb', line 6

def gems
  @gems
end

#helpersObject

Returns the value of attribute helpers.



6
7
8
# File 'lib/jets/application/configuration/defaults.rb', line 6

def helpers
  @helpers
end

#helpers_pathsObject

Returns the value of attribute helpers_paths.



6
7
8
# File 'lib/jets/application/configuration/defaults.rb', line 6

def helpers_paths
  @helpers_paths
end

#iam_policyObject

IAM policies must run lazily because they depend on @function.vpc_config Need the if Jets.application check because commands like

jets generate kingsman:controllers -h

will load Rails for generators and that will directly use a Jets config that does not call Jest.boot See: Jets::Generator



181
182
183
# File 'lib/jets/application/configuration/defaults.rb', line 181

def iam_policy
  @iam_policy
end

#ignore_pathsObject

Returns the value of attribute ignore_paths.



6
7
8
# File 'lib/jets/application/configuration/defaults.rb', line 6

def ignore_paths
  @ignore_paths
end

#inflectionsObject

Returns the value of attribute inflections.



6
7
8
# File 'lib/jets/application/configuration/defaults.rb', line 6

def inflections
  @inflections
end

#lambdaObject

Returns the value of attribute lambda.



6
7
8
# File 'lib/jets/application/configuration/defaults.rb', line 6

def lambda
  @lambda
end

#loggerObject

Returns the value of attribute logger.



6
7
8
# File 'lib/jets/application/configuration/defaults.rb', line 6

def logger
  @logger
end

#loggingObject

Returns the value of attribute logging.



6
7
8
# File 'lib/jets/application/configuration/defaults.rb', line 6

def logging
  @logging
end

#managed_iam_policyObject

Returns the value of attribute managed_iam_policy.



6
7
8
# File 'lib/jets/application/configuration/defaults.rb', line 6

def managed_iam_policy
  @managed_iam_policy
end

#managed_policy_definitionsObject

Returns the value of attribute managed_policy_definitions.



6
7
8
# File 'lib/jets/application/configuration/defaults.rb', line 6

def managed_policy_definitions
  @managed_policy_definitions
end

#modeObject

Returns the value of attribute mode.



6
7
8
# File 'lib/jets/application/configuration/defaults.rb', line 6

def mode
  @mode
end

#prewarmObject

Returns the value of attribute prewarm.



6
7
8
# File 'lib/jets/application/configuration/defaults.rb', line 6

def prewarm
  @prewarm
end

#proObject

Returns the value of attribute pro.



6
7
8
# File 'lib/jets/application/configuration/defaults.rb', line 6

def pro
  @pro
end

#routesObject

Returns the value of attribute routes.



6
7
8
# File 'lib/jets/application/configuration/defaults.rb', line 6

def routes
  @routes
end

#s3_eventObject

Returns the value of attribute s3_event.



6
7
8
# File 'lib/jets/application/configuration/defaults.rb', line 6

def s3_event
  @s3_event
end

#webpackerObject

Returns the value of attribute webpacker.



6
7
8
# File 'lib/jets/application/configuration/defaults.rb', line 6

def webpacker
  @webpacker
end

Instance Method Details

#default_corsObject



212
213
214
215
216
# File 'lib/jets/application/configuration/defaults.rb', line 212

def default_cors
  !!Gem.loaded_specs.detect do |gem_name, spec|
    gem_name == "rack-cors"
  end
end

#initializeObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/jets/application/configuration/defaults.rb', line 37

def initialize(*)
  Jets::Dotenv.load!
  super
  @api = ActiveSupport::OrderedOptions.new
  @api.api_key_required = false # Turn off API key required
  @api.authorization_type = "NONE"
  @api.authorizers = ActiveSupport::OrderedOptions.new
  @api.authorizers.default_token_source = "Auth" # method.request.header.Auth
  @api.auto_replace = nil # https://github.com/boltops-tools/jets/issues/391
  @api.binary_media_types = ['multipart/form-data']

  @api.cors = default_cors
  @api.endpoint_policy = nil # required when endpoint_type is EDGE
  @api.endpoint_type = 'EDGE' # PRIVATE, EDGE, REGIONAL
  @api.vpc_endpoint_ids = nil

  @api_mode = nil

  @app = ActiveSupport::OrderedOptions.new
  @app.domain = nil

  @build = ActiveSupport::OrderedOptions.new
  @build.prebundle_copy = []

  @cfn = ActiveSupport::OrderedOptions.new
  @cfn.build = ActiveSupport::OrderedOptions.new
  @cfn.build.controllers = "one_lambda_for_all_controllers" # also: one_lambda_per_controller one_lambda_for_all_controllers
  @cfn.build.resource_tags = {} # tags to add to all resources
  @cfn.build.routes = "one_apigw_method_for_all_routes" # also: one_apigw_method_per_route

  @controllers = ActiveSupport::OrderedOptions.new
  @controllers.default_protect_from_forgery = nil

  @deploy = ActiveSupport::OrderedOptions.new
  @deploy.stagger = ActiveSupport::OrderedOptions.new
  @deploy.stagger.enabled = false
  @deploy.stagger.batch_size = 10

  # @domain.name = "#{Jets.project_namespace}.coolapp.com" # Default is nil
  # @domain.cert_arn = "..."
  # @domain.route53 controls whether or not to create the managed route53 record.
  # Useful to disable this when user wants to manage the route themself like pointing
  # it to CloudFront for blue-green deployments instead.
  @domain = ActiveSupport::OrderedOptions.new
  @domain.base_path = '' # empty path represents root
  @domain.endpoint_type = "REGIONAL" # EDGE or REGIONAL. Default to EDGE because CloudFormation update is faster
  @domain.route53 = true

  @environment = ActiveSupport::OrderedOptions.new

  @events = ActiveSupport::OrderedOptions.new

  @events.dynamodb = ActiveSupport::OrderedOptions.new
  @events.dynamodb.table_namespace = true # true will use Jets.table_name
  @events.dynamodb.table_namespace_separator = '_'

  @events.s3 = ActiveSupport::OrderedOptions.new
  @events.s3.configure_bucket = true
  # These notification_configuration properties correspond to the ruby aws-sdk
  #   s3.put_bucket_notification_configuration
  # in jets/s3_bucket.rb, not the CloudFormation Bucket properties. The CloudFormation
  # bucket properties have a similiar structure but is slightly different so it can be confusing.
  #
  #   Ruby aws-sdk S3 Docs: https://amzn.to/2N7m5Lr
  @events.s3.notification_configuration = {
    topic_configurations: [
      {
        events: ["s3:ObjectCreated:*"],
        topic_arn: "!Ref SnsTopic", # must use this logical id
      },
    ],
  }

  # Deprecated: Use @events.s3.configure_bucket instead
  # Leaving in as a comment for now. Will remove comment in the future
  # Already print a deprecation warning in jets/stack/s3_event.rb
  @s3_event = ActiveSupport::OrderedOptions.new
  # @s3_event.configure_bucket = true
  # @s3_event.notification_configuration = {
  #   topic_configurations: [
  #     {
  #       events: ["s3:ObjectCreated:*"],
  #       topic_arn: "!Ref SnsTopic", # must use this logical id
  #     },
  #   ],
  # }

  @filter_parameters = []

  # default function.memory_size memory setting based on:
  # https://medium.com/epsagon/how-to-make-lambda-faster-memory-performance-benchmark-be6ebc41f0fc
  @function = ActiveSupport::OrderedOptions.new
  @function.ephemeral_storage = { size: 512 } # megabytes
  @function.memory_size = 1536
  @function.timeout = 30

  # Old deprecated
  @gems = ActiveSupport::OrderedOptions.new
  @gems.clean = false
  @gems.disable = false
  @gems.source = "https://api.serverlessgems.com/api/v1"
  # New
  @pro = ActiveSupport::OrderedOptions.new
  @pro.disable = false

  @helpers = ActiveSupport::OrderedOptions.new
  @helpers.host = nil # nil by default. Other examples: https://myurl.com:8888
  @helpers_paths = []

  @inflections = ActiveSupport::OrderedOptions.new
  @inflections.irregular = {}

  # Custom user lambda layers
  @lambda = ActiveSupport::OrderedOptions.new
  @lambda.layers = []

  @logger = ActiveSupport::Logger.new($stderr)
  @logger.formatter = ActiveSupport::Logger::SimpleFormatter.new # jets v5 default: no timestamps
  @logger.level = :debug # Logger::DEBUG - default to debug for development mode and to see ActionMailer logs

  @logging = ActiveSupport::OrderedOptions.new
  @logging.event = false # jets v5 behavior

  @mode = nil # job api html

  @prewarm = ActiveSupport::OrderedOptions.new
  @prewarm.enable = true
  @prewarm.public_ratio = 3
  @prewarm.rate = '30 minutes'

  @routes = ActiveSupport::OrderedOptions.new
  @routes.allow_sibling_conflicts = true # users/:id and users/:user_id/articles

  @default_iam_policy = self.class.default_iam_policy
  @managed_policy_definitions = []
  @managed_iam_policy = []
end

#load_defaults(target_version) ⇒ Object



244
245
246
247
248
249
250
251
252
253
254
# File 'lib/jets/application/configuration/defaults.rb', line 244

def load_defaults(target_version)
  load_rails_defaults "7.0"

  case target_version.to_s
  when "5.0"
    @host_authorization = { exclude: ->(request) do
        request.host =~ /localhost/ || request.domain == "amazonaws.com"
      end
    }
  end
end

#vpc_iam_policy_statementObject



197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/jets/application/configuration/defaults.rb', line 197

def vpc_iam_policy_statement
  {
    Action: %w[
      ec2:CreateNetworkInterface
      ec2:DeleteNetworkInterface
      ec2:DescribeNetworkInterfaces
      ec2:DescribeVpcs
      ec2:DescribeSubnets
      ec2:DescribeSecurityGroups
    ],
    Effect: "Allow",
    Resource: "*",
  }
end