jets 3.0.15 → 3.0.19

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: 58e203dbd0ee79c9e7287badab576597b08f0b3f5fd3f1b5309bfa910cbf2858
4
- data.tar.gz: 1a29ba9a72f042b156312d47acdeebee565f6dc4a5c3d3ee109931723e59b583
3
+ metadata.gz: 628d962d35e5e497e1e5362ea11d5844c94e28f9e71877295edd046d291e6b81
4
+ data.tar.gz: 0a353487be640729460d85debb14d71064415847311ec952b5612e8a483e6a63
5
5
  SHA512:
6
- metadata.gz: 6c6f2d06e54b0837f30c9a064e48252330a72a770b1b0f51e1884ab4820291220565b696f505cfe5645a3de2d428a3c380bc2c7f8d8873ae8819f2f5f0c0a6ef
7
- data.tar.gz: 95a8262ad30c8a593a2c23fed954528e4d0801cd8260ae81e7c974f89d1e8c05c34c3778a7422f356de30c410bae9a9313ebf677e440d7b06d379aa7580421f8
6
+ metadata.gz: b36f4d843a60052f42935df53e4d801e74dba09237b03b2cee11835894d0a4574493b1b26793f2fdbc8e26b040bd911378752000201b0bcfaeda56727936f04f
7
+ data.tar.gz: ce8b72b84930ccd20727504c1955f4d1f4acf9c36e750207eb85ab2ccee6fd8a9d85e5f1ee6e449bf8a7e7925de3e55a08c3c294dd9eb0c8cb84cf98757412b2
data/CHANGELOG.md CHANGED
@@ -3,6 +3,21 @@
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.19] - 2021-10-20
7
+ - [#602](https://github.com/boltops-tools/jets/pull/602) pin zeitwerk to 2.4.x in gemfile
8
+
9
+ ## [3.0.18] - 2021-10-20
10
+ - [#596](https://github.com/boltops-tools/jets/pull/596) Serialize job data correctly
11
+ - [#598](https://github.com/boltops-tools/jets/pull/598) fixing issues when mounting
12
+ - [#599](https://github.com/boltops-tools/jets/pull/599) pin to zeitwerk 2.4.x
13
+ - [#600](https://github.com/boltops-tools/jets/pull/600) method override also on the lambda function side
14
+
15
+ ## [3.0.17] - 2021-09-15
16
+ - [#593](https://github.com/boltops-tools/jets/pull/593) Fix deploy for new projects. Added rescue block back into lib/jets/commands/deploy.rb
17
+
18
+ ## [3.0.16] - 2021-09-10
19
+ - [#590](https://github.com/boltops-tools/jets/pull/590) Improve Rate Limit Handling
20
+
6
21
  ## [3.0.15] - 2021-09-05
7
22
  - [#587](https://github.com/boltops-tools/jets/pull/587) Fix private method names
8
23
  - [#588](https://github.com/boltops-tools/jets/pull/588) custom domain: adjust rate limit for base mapping
data/jets.gemspec CHANGED
@@ -61,7 +61,7 @@ Gem::Specification.new do |spec|
61
61
  spec.add_dependency "shotgun"
62
62
  spec.add_dependency "text-table"
63
63
  spec.add_dependency "thor"
64
- spec.add_dependency "zeitwerk"
64
+ spec.add_dependency "zeitwerk", "~> 2.4.0"
65
65
 
66
66
  spec.add_development_dependency "bundler"
67
67
  spec.add_development_dependency "byebug"
@@ -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,7 +102,6 @@ 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
107
  rescue Aws::CloudFormation::Errors::ValidationError => e
@@ -136,18 +111,6 @@ module Jets::Commands
136
111
  else
137
112
  raise
138
113
  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
114
  end
152
115
 
153
116
  # All CloudFormation states listed here: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-describing-stacks.html
@@ -18,6 +18,7 @@ gem "mysql2", "~> 0.5.3"
18
18
  <% unless options[:mode] == 'job' -%>
19
19
  gem "dynomite"
20
20
  <% end -%>
21
+ gem "zeitwerk", "~> 2.4.0"
21
22
 
22
23
  # development and test groups are not bundled as part of the deployment
23
24
  group :development, :test do
@@ -43,7 +43,7 @@ class Jets::Controller
43
43
  # Most of the time, you want process! instead of dispatch!
44
44
  #
45
45
  def process!
46
- adapter = Jets::Controller::Rack::Adapter.new(event, context, meth)
46
+ adapter = Jets::Controller::Rack::Adapter.new(event, context)
47
47
  adapter.rack_vars(
48
48
  'jets.controller' => self,
49
49
  'lambda.context' => context,
@@ -75,6 +75,8 @@ class Jets::Controller
75
75
  # dispatch! is useful for megamode or mounted applications
76
76
  #
77
77
  def dispatch!
78
+ method_override!
79
+
78
80
  t1 = Time.now
79
81
  log_start
80
82
 
@@ -99,12 +101,30 @@ class Jets::Controller
99
101
  triplet # status, headers, body
100
102
  end
101
103
 
104
+ # Override @meth when POST with _method=delete
105
+ # By the time processing reaches dispatch which calls method_override!
106
+ # The Rack::MethodOverride middleware has overriden env['REQUEST_METHOD'] with DELETE
107
+ # and set env['rack.methodoverride.original_method']
108
+ def method_override!
109
+ env = request.env
110
+ if env['rack.methodoverride.original_method'] && env['REQUEST_METHOD'] == 'DELETE'
111
+ @original_meth = @meth
112
+ @meth = "delete"
113
+ end
114
+ end
115
+
116
+ def processing_log
117
+ processing = "Processing #{self.class.name}##{@meth}"
118
+ processing << " (original method #{@original_meth})" if @original_meth
119
+ processing
120
+ end
121
+
102
122
  # Documented interface method, careful not to rename
103
123
  def log_start
104
124
  # JSON.dump makes logging look pretty in CloudWatch logs because it keeps it on 1 line
105
125
  ip = request.ip
106
126
  Jets.logger.info "Started #{@event['httpMethod']} \"#{@event['path']}\" for #{ip} at #{Time.now}"
107
- Jets.logger.info "Processing #{self.class.name}##{@meth}"
127
+ Jets.logger.info processing_log
108
128
  Jets.logger.info " Event: #{event_log}"
109
129
  Jets.logger.info " Parameters: #{JSON.dump(filtered_parameters.to_h)}"
110
130
  end
@@ -5,13 +5,13 @@ module Jets::Controller::Rack
5
5
  extend Memoist
6
6
 
7
7
  # Returns back API Gateway response hash structure
8
- def self.process(event, context, meth)
9
- adapter = new(event, context, meth)
8
+ def self.process(event, context)
9
+ adapter = new(event, context)
10
10
  adapter.process
11
11
  end
12
12
 
13
- def initialize(event, context, meth)
14
- @event, @context, @meth = event, context, meth
13
+ def initialize(event, context)
14
+ @event, @context = event, context
15
15
  end
16
16
 
17
17
  # 1. Convert API Gateway event event to Rack env
@@ -27,12 +27,12 @@ module Jets::Controller::Rack
27
27
  def path_with_base_path
28
28
  resource = @event['resource']
29
29
  pathParameters = @event['pathParameters']
30
-
30
+
31
31
  if(!pathParameters.nil? and !resource.nil?)
32
32
  resource = pathParameters.reduce(resource) {|resource, parameter|
33
33
  key, value = parameter
34
- key = key.eql?("catchall") ? "{#{key}+}" : "{#{key}}"
35
- resource = resource.gsub(key, value)
34
+ resource = resource.gsub("{#{key}+}", value)
35
+ resource = resource.gsub("{#{key}}", value)
36
36
  resource
37
37
  }
38
38
  end
@@ -64,7 +64,9 @@ module Jets::Controller::Rack
64
64
  end
65
65
 
66
66
  def content_type
67
- headers['Content-Type'] || Jets::Controller::DEFAULT_CONTENT_TYPE
67
+ # Rack (local) uses Content-Type and APIGW (remote) uses content-type
68
+ # Rack::MethodOverride relys on content-type to detect content type properly.
69
+ headers['Content-Type'] || headers['content-type'] || Jets::Controller::DEFAULT_CONTENT_TYPE
68
70
  end
69
71
 
70
72
  def content_length
data/lib/jets/job/base.rb CHANGED
@@ -26,13 +26,13 @@ module Jets::Job
26
26
  end
27
27
 
28
28
  def perform_now(meth, event={}, context={})
29
- new(event, context, meth).send(meth)
29
+ new(event.try(:to_unsafe_h), context, meth).send(meth)
30
30
  end
31
31
 
32
32
  def perform_later(meth, event={}, context={})
33
33
  if on_lambda?
34
34
  function_name = "#{self.to_s.underscore}-#{meth}"
35
- call = Jets::Commands::Call.new(function_name, JSON.dump(event), invocation_type: "Event")
35
+ call = Jets::Commands::Call.new(function_name, JSON.dump(event.try(:to_unsafe_h)), invocation_type: "Event")
36
36
  call.run
37
37
  else
38
38
  puts "INFO: Not on AWS Lambda. In local mode perform_later executes the job with perform_now instead."
@@ -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.15"
2
+ VERSION = "3.0.19"
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.15
4
+ version: 3.0.19
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-09-05 00:00:00.000000000 Z
11
+ date: 2021-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionmailer
@@ -490,16 +490,16 @@ dependencies:
490
490
  name: zeitwerk
491
491
  requirement: !ruby/object:Gem::Requirement
492
492
  requirements:
493
- - - ">="
493
+ - - "~>"
494
494
  - !ruby/object:Gem::Version
495
- version: '0'
495
+ version: 2.4.0
496
496
  type: :runtime
497
497
  prerelease: false
498
498
  version_requirements: !ruby/object:Gem::Requirement
499
499
  requirements:
500
- - - ">="
500
+ - - "~>"
501
501
  - !ruby/object:Gem::Version
502
- version: '0'
502
+ version: 2.4.0
503
503
  - !ruby/object:Gem::Dependency
504
504
  name: bundler
505
505
  requirement: !ruby/object:Gem::Requirement
@@ -1095,7 +1095,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1095
1095
  - !ruby/object:Gem::Version
1096
1096
  version: '0'
1097
1097
  requirements: []
1098
- rubygems_version: 3.2.5
1098
+ rubygems_version: 3.1.6
1099
1099
  signing_key:
1100
1100
  specification_version: 4
1101
1101
  summary: Ruby Serverless Framework