jets 3.0.12 → 3.0.16

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df619199e09ad52bd8f622f765867bb6560d3818a3b6297d9f82dd9ed7b4a9a4
4
- data.tar.gz: d66d07f780595a0075caeadd6869a7e26aa85edb3b5af1c4a9680d2958201dd7
3
+ metadata.gz: e612ac00d993cb94a8458bbf238abc72e898ddbb4b6205c9d0d7a8d2e5388a6c
4
+ data.tar.gz: e2d13089ca64351b1b4c0c8672b31b17e0708e1caf817eab40abc957775fccf5
5
5
  SHA512:
6
- metadata.gz: a77badece003642190f7f7054d690d1c716d3d74a835275ac639dda48fa4f42fd80158e2559ff7ddfea175cb7e53a5bc353071d11448162c9b919a8a61620a76
7
- data.tar.gz: b2cc100b93f46fc0625146ef6ac6d5579fb814aa764d30440abda2b5f31e9e236e9eff7a3fc5d159fdf1cb4a992a00429fbe42625e14b7b32da4a28b8b2ad6a7
6
+ metadata.gz: 4db9003f65f11b9a47101159dd80e6576bb12a34989de95227b27882db575d5b61b8d2c2b11965fd933f50156e7197ae80e30da498c12a10bcd868934e96a2b9
7
+ data.tar.gz: ca781f60467a266f48abb452cbb1f1aa0ee7c5734315e9d3886786c37d2519466749dc04e28aca50ba470c6260763dc3ef5c2e34ad0a8ee1f883f231db623d0d
data/CHANGELOG.md CHANGED
@@ -3,6 +3,23 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *loosely tries* to adhere to [Semantic Versioning](http://semver.org/).
5
5
 
6
+ ## [3.0.16] - 2021-09-10
7
+ - [#590](https://github.com/boltops-tools/jets/pull/590) Improve Rate Limit Handling
8
+
9
+ ## [3.0.15] - 2021-09-05
10
+ - [#587](https://github.com/boltops-tools/jets/pull/587) Fix private method names
11
+ - [#588](https://github.com/boltops-tools/jets/pull/588) custom domain: adjust rate limit for base mapping
12
+ - [#589](https://github.com/boltops-tools/jets/pull/589) Ujs
13
+
14
+ ## [3.0.14] - 2021-09-01
15
+ - [#583](https://github.com/boltops-tools/jets/pull/583) Don't overwrite content_type when rendering json or xml with content_type specified
16
+ - [#584](https://github.com/boltops-tools/jets/pull/584) Adds an override flag to change behaviour when Jets is behind an ELB running Jets Server
17
+ - [#585](https://github.com/boltops-tools/jets/pull/585) add_stage controller method
18
+ - [#586](https://github.com/boltops-tools/jets/pull/586) JETS_ELB env var flag
19
+
20
+ ## [3.0.13] - 2021-08-17
21
+ - [#582](https://github.com/boltops-tools/jets/pull/582) use Shotgun::Static middleware always
22
+
6
23
  ## [3.0.12] - 2021-08-08
7
24
  - [#578](https://github.com/boltops-tools/jets/pull/578) Update "jets delete" documentation to be --yes instead of --skip
8
25
  - [#580](https://github.com/boltops-tools/jets/pull/580) Use active support instead of actionview
@@ -16,52 +16,80 @@ module Jets::AwsServices
16
16
  include StackStatus
17
17
 
18
18
  def apigateway
19
- Aws::APIGateway::Client.new
19
+ Aws::APIGateway::Client.new(aws_options)
20
20
  end
21
21
  global_memoize :apigateway
22
22
 
23
23
  def cfn
24
- Aws::CloudFormation::Client.new
24
+ Aws::CloudFormation::Client.new(aws_options)
25
25
  end
26
26
  global_memoize :cfn
27
27
 
28
28
  def dynamodb
29
- Aws::DynamoDB::Client.new
29
+ Aws::DynamoDB::Client.new(aws_options)
30
30
  end
31
31
  global_memoize :dynamodb
32
32
 
33
33
  def aws_lambda
34
- Aws::Lambda::Client.new
34
+ Aws::Lambda::Client.new(aws_options)
35
35
  end
36
36
  global_memoize :aws_lambda
37
37
 
38
38
  def logs
39
- Aws::CloudWatchLogs::Client.new
39
+ Aws::CloudWatchLogs::Client.new(aws_options)
40
40
  end
41
41
  global_memoize :logs
42
42
 
43
43
  def s3
44
- Aws::S3::Client.new
44
+ Aws::S3::Client.new(aws_options)
45
45
  end
46
46
  global_memoize :s3
47
47
 
48
48
  def s3_resource
49
- Aws::S3::Resource.new
49
+ Aws::S3::Resource.new(aws_options)
50
50
  end
51
51
  global_memoize :s3_resource
52
52
 
53
53
  def sns
54
- Aws::SNS::Client.new
54
+ Aws::SNS::Client.new(aws_options)
55
55
  end
56
56
  global_memoize :sns
57
57
 
58
58
  def sqs
59
- Aws::SQS::Client.new
59
+ Aws::SQS::Client.new(aws_options)
60
60
  end
61
61
  global_memoize :sqs
62
62
 
63
63
  def sts
64
- Aws::STS::Client.new
64
+ Aws::STS::Client.new(aws_options)
65
65
  end
66
66
  global_memoize :sts
67
+
68
+ # Override the AWS retry settings with Jets AWS clients.
69
+ #
70
+ # The aws-sdk-core has exponential backup with this formula:
71
+ #
72
+ # 2 ** c.retries * c.config.retry_base_delay
73
+ #
74
+ # So the max delay will be 2 ** 7 * 0.6 = 76.8s
75
+ #
76
+ # Only scoping this to deploy because dont want to affect people's application that use the aws sdk.
77
+ #
78
+ # There is also additional rate backoff logic elsewhere, since this is only scoped to deploys.
79
+ #
80
+ # Useful links:
81
+ # https://github.com/aws/aws-sdk-ruby/blob/master/gems/aws-sdk-core/lib/aws-sdk-core/plugins/retry_errors.rb
82
+ # https://docs.aws.amazon.com/apigateway/latest/developerguide/limits.html
83
+ #
84
+ def aws_options
85
+ options = {
86
+ retry_limit: 7, # default: 3
87
+ retry_base_delay: 0.6, # default: 0.3
88
+ }
89
+ options.merge!(
90
+ log_level: :debug,
91
+ logger: Logger.new($stdout),
92
+ ) if ENV['JETS_DEBUG_AWS_SDK']
93
+ options
94
+ end
67
95
  end
@@ -26,20 +26,7 @@ class Jets::Commands::Clean
26
26
  end
27
27
 
28
28
  def delete_log_group(log_group_name)
29
- retries = 0
30
29
  logs.delete_log_group(log_group_name: log_group_name)
31
- rescue Aws::CloudWatchLogs::Errors::ThrottlingException => e
32
- retries += 1
33
- seconds = 2 ** retries
34
-
35
- puts "WARN: delete_log_group #{e.class} #{e.message}".color(:yellow)
36
- puts "Backing off and will retry in #{seconds} seconds."
37
- sleep(seconds)
38
- if seconds > 90 # 2 ** 6 is 64 so will give up after 6 retries
39
- puts "Giving up after #{retries} retries"
40
- else
41
- retry
42
- end
43
30
  end
44
31
 
45
32
  def clean_deploys
@@ -44,27 +44,7 @@ class Jets::Commands::Delete
44
44
  end
45
45
 
46
46
  def confirm_project_exists
47
- retries = 0
48
- begin
49
- cfn.describe_stacks(stack_name: parent_stack_name)
50
- rescue Aws::CloudFormation::Errors::ValidationError
51
- # Aws::CloudFormation::Errors::ValidationError is thrown when the stack
52
- # does not exist
53
- puts "The parent stack #{Jets.config.project_namespace.color(:green)} for the project #{Jets.config.project_name.color(:green)} does not exist. So it cannot be deleted."
54
- exit 0
55
- rescue Aws::CloudFormation::Errors::Throttling => e
56
- retries += 1
57
- seconds = 2 ** retries
58
-
59
- puts "WARN: confirm_project_exists #{e.class} #{e.message}".color(:yellow)
60
- puts "Backing off and will retry in #{seconds} seconds."
61
- sleep(seconds)
62
- if seconds > 90 # 2 ** 6 is 64 so will give up after 6 retries
63
- puts "Giving up after #{retries} retries"
64
- else
65
- retry
66
- end
67
- end
47
+ cfn.describe_stacks(stack_name: parent_stack_name)
68
48
  end
69
49
 
70
50
  def empty_s3_bucket
@@ -9,7 +9,6 @@ module Jets::Commands
9
9
  end
10
10
 
11
11
  def run
12
- aws_config_update!
13
12
  deployment_env = Jets.config.project_namespace.color(:green)
14
13
  puts "Deploying to Lambda #{deployment_env} environment..."
15
14
  return if @options[:noop]
@@ -37,29 +36,6 @@ module Jets::Commands
37
36
  ship(stack_type: :full, s3_bucket: s3_bucket)
38
37
  end
39
38
 
40
- # Override the AWS retry settings during a deploy.
41
- #
42
- # The aws-sdk-core has expondential backup with this formula:
43
- #
44
- # 2 ** c.retries * c.config.retry_base_delay
45
- #
46
- # So the max delay will be 2 ** 7 * 0.6 = 76.8s
47
- #
48
- # Only scoping this to deploy because dont want to affect people's application that use the aws sdk.
49
- #
50
- # There is also additional rate backoff logic elsewhere, since this is only scoped to deploys.
51
- #
52
- # Useful links:
53
- # https://github.com/aws/aws-sdk-ruby/blob/master/gems/aws-sdk-core/lib/aws-sdk-core/plugins/retry_errors.rb
54
- # https://docs.aws.amazon.com/apigateway/latest/developerguide/limits.html
55
- #
56
- def aws_config_update!
57
- Aws.config.update(
58
- retry_limit: 7, # default: 3
59
- retry_base_delay: 0.6, # default: 0.3
60
- )
61
- end
62
-
63
39
  def create_s3_event_buckets
64
40
  buckets = Jets::Job::Base.s3_events.keys
65
41
  buckets.each do |bucket|
@@ -126,28 +102,8 @@ module Jets::Commands
126
102
  end
127
103
 
128
104
  def find_stack(stack_name)
129
- retries = 0
130
105
  resp = cfn.describe_stacks(stack_name: stack_name)
131
106
  resp.stacks.first
132
- rescue Aws::CloudFormation::Errors::ValidationError => e
133
- # example: Stack with id demo-dev does not exist
134
- if e.message =~ /Stack with/ && e.message =~ /does not exist/
135
- nil
136
- else
137
- raise
138
- end
139
- rescue Aws::CloudFormation::Errors::Throttling => e
140
- retries += 1
141
- seconds = 2 ** retries
142
-
143
- puts "WARN: find_stack #{e.class} #{e.message}".color(:yellow)
144
- puts "Backing off and will retry in #{seconds} seconds."
145
- sleep(seconds)
146
- if seconds > 90 # 2 ** 6 is 64 so will give up after 6 retries
147
- puts "Giving up after #{retries} retries"
148
- else
149
- retry
150
- end
151
107
  end
152
108
 
153
109
  # All CloudFormation states listed here: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-describing-stacks.html
@@ -114,7 +114,14 @@ JS
114
114
  after = "const { environment } = require('@rails/webpacker')\n"
115
115
  insert_into_file("config/webpack/environment.js", jquery, after: after)
116
116
 
117
- run("yarn add bootstrap jquery popper.js postcss-cssnext @rails/ujs")
117
+ jets_ujs =<<-JS
118
+ import Jets from "@rubyonjets/ujs-compat"
119
+ Jets.start()
120
+ JS
121
+ after = "Rails.start()\n"
122
+ insert_into_file("app/javascript/packs/application.js", jets_ujs, after: after)
123
+
124
+ run("yarn add bootstrap jquery popper.js postcss-cssnext @rails/ujs @rubyonjets/ujs-compat")
118
125
  end
119
126
 
120
127
  def git_init
@@ -5,17 +5,17 @@ class Jets::Controller::Middleware::Local
5
5
  end
6
6
 
7
7
  def find_route
8
- Jets::Router::Finder.new(method, path).run
8
+ Jets::Router::Finder.new(path, method).run
9
9
  end
10
10
 
11
11
  private
12
12
  attr_reader :env
13
13
 
14
- def path
14
+ def method
15
15
  env["REQUEST_METHOD"] || "GET"
16
16
  end
17
17
 
18
- def method
18
+ def path
19
19
  env["PATH_INFO"].sub(/^\//,'')
20
20
  end
21
21
  end
@@ -70,6 +70,7 @@ module Jets::Controller::Middleware
70
70
 
71
71
  def on_aws?(env)
72
72
  return false if Jets.env.test? # usually with test we're passing in full API Gateway fixtures with the HTTP_X_AMZN_TRACE_ID
73
+ return false if ENV['JETS_ELB'] # If we're using an ELB and Jets is inside a container running jets server, we don't want to pretend we're on AWS.
73
74
  on_cloud9 = !!(env['HTTP_HOST'] =~ /cloud9\..*\.amazonaws\.com/)
74
75
  !!env['HTTP_X_AMZN_TRACE_ID'] && !on_cloud9
75
76
  end
@@ -7,16 +7,7 @@ class Jets::Controller
7
7
  raise "redirect_to url parameter must be a String. Please pass in a string"
8
8
  end
9
9
 
10
- uri = URI.parse(url)
11
- # if no location.host, we been provided a relative host
12
- if !uri.host && actual_host
13
- url = "/#{url}" unless url.starts_with?('/')
14
- url = add_stage_name(url)
15
- redirect_url = actual_host + url
16
- else
17
- redirect_url = url
18
- end
19
-
10
+ redirect_url = add_stage(url)
20
11
  redirect_url = ensure_protocol(redirect_url)
21
12
 
22
13
  aws_proxy = Rendering::RackRenderer.new(self,
@@ -33,6 +33,8 @@ class Jets::Controller
33
33
  end
34
34
 
35
35
  def adjust_content_type!(options)
36
+ return if options.key?(:content_type)
37
+
36
38
  if options.key?(:json)
37
39
  options[:content_type] = "application/json"
38
40
  elsif options.key?(:xml)
@@ -60,15 +62,26 @@ class Jets::Controller
60
62
  rest.merge(template: template)
61
63
  end
62
64
 
63
- # Add API Gateway Stage Name
64
- def add_stage_name(url)
65
+ # Example usage:
66
+ #
67
+ # render json: {success: true, location: add_stage(posts_path)}
68
+ #
69
+ def add_stage(url)
65
70
  return url unless actual_host
66
71
 
67
- Jets::Controller::Stage.add(actual_host, url)
72
+ uri = URI.parse(url)
73
+ # if no location.host, we been provided a relative host
74
+ if !uri.host && actual_host
75
+ url = "/#{url}" unless url.starts_with?('/')
76
+ url = Jets::Controller::Stage.add(actual_host, url)
77
+ actual_host + url
78
+ else
79
+ url
80
+ end
68
81
  end
69
82
 
70
83
  def url_for(url)
71
- add_stage_name(url)
84
+ add_stage(url)
72
85
  end
73
86
 
74
87
  # Actual host can be headers["origin"] when cloudfront is in front.
@@ -56,7 +56,7 @@ class <%= controller_class_name %>Controller < ApplicationController
56
56
  def delete
57
57
  @<%= orm_instance.destroy %>
58
58
  if request.xhr?
59
- render json: {success: true}
59
+ render json: {success: true, location: <%= table_name %>_path}
60
60
  else
61
61
  redirect_to <%= table_name %>_path
62
62
  end
@@ -4,6 +4,25 @@ require 'aws-sdk-cloudformation'
4
4
  class BasePathMapping
5
5
  def initialize(event, stage_name)
6
6
  @event, @stage_name = event, stage_name
7
+ aws_config_update!
8
+ end
9
+
10
+ # Override the AWS retry settings. The aws-sdk-core has expondential backup with this formula:
11
+ #
12
+ # 2 ** c.retries * c.config.retry_base_delay
13
+ #
14
+ # So the max delay will be 2 ** 7 * 0.6 = 76.8s
15
+ #
16
+ # Useful links:
17
+ #
18
+ # https://github.com/aws/aws-sdk-ruby/blob/master/gems/aws-sdk-core/lib/aws-sdk-core/plugins/retry_errors.rb
19
+ # https://docs.aws.amazon.com/apigateway/latest/developerguide/limits.html
20
+ #
21
+ def aws_config_update!
22
+ Aws.config.update(
23
+ retry_limit: 7, # default: 3
24
+ retry_base_delay: 0.6, # default: 0.3
25
+ )
7
26
  end
8
27
 
9
28
  # Cannot use update_base_path_mapping to update the base_mapping because it doesnt
@@ -1,3 +1,5 @@
1
+ require "shotgun"
2
+
1
3
  module Jets::Middleware
2
4
  class DefaultStack
3
5
  attr_reader :config, :app
@@ -8,7 +10,7 @@ module Jets::Middleware
8
10
 
9
11
  def build_stack
10
12
  Stack.new do |middleware|
11
- middleware.use Shotgun::Static if Jets.env.development?
13
+ middleware.use Shotgun::Static
12
14
  middleware.use Rack::Runtime
13
15
  middleware.use Jets::Controller::Middleware::Cors if cors_enabled?
14
16
  middleware.use Rack::MethodOverride # must come before Middleware::Local for multipart post forms to work
@@ -59,26 +59,11 @@ class Jets::Resource::ApiGateway::RestApi::Routes::Change
59
59
 
60
60
  def method_uri(resource_id, http_method)
61
61
  # https://docs.aws.amazon.com/apigateway/latest/developerguide/limits.html
62
- retries = 0
63
- begin
64
- resp = apigateway.get_method(
65
- rest_api_id: rest_api_id,
66
- resource_id: resource_id,
67
- http_method: http_method
68
- )
69
- rescue Aws::APIGateway::Errors::TooManyRequestsException => e
70
- retries += 1
71
- seconds = 2 ** retries
72
-
73
- puts "WARN: method_uri #{e.class} #{e.message}".color(:yellow)
74
- puts "Backing off and will retry in #{seconds} seconds."
75
- sleep(seconds)
76
- if seconds > 90 # 2 ** 6 is 64 so will give up after 6 retries
77
- puts "Giving up after #{retries} retries"
78
- else
79
- retry
80
- end
81
- end
62
+ resp = apigateway.get_method(
63
+ rest_api_id: rest_api_id,
64
+ resource_id: resource_id,
65
+ http_method: http_method
66
+ )
82
67
  resp.method_integration.uri
83
68
  end
84
69
 
data/lib/jets/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Jets
2
- VERSION = "3.0.12"
2
+ VERSION = "3.0.16"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jets
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.12
4
+ version: 3.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-08-08 00:00:00.000000000 Z
11
+ date: 2021-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionmailer