jets 2.2.0 → 2.2.1

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: 00d2f09e01d8be696832564080069855665cf1cc17111d0c6ade401a640bfe09
4
- data.tar.gz: 4ec605c411378a9c49745298eaa4b73d10478fdbdd7adb012ac32ca9b58e7fa8
3
+ metadata.gz: 6becd540bc99766696d49280636867ca4183ab2dc6a9cadec90c9837acd06352
4
+ data.tar.gz: '0918860cc1c3429635f1d3cba3db58301d0090e55c1382049d23d45f2763dfa2'
5
5
  SHA512:
6
- metadata.gz: 14b548c897b3331ef31b86edede38d1f2b9e4a01c050be39676a839afc5ecfa4b03b911e9da351c98858e8e7b4f063fdacd89425f0dd64540eb6db3ec68e9e34
7
- data.tar.gz: 16b66bd00dbadf6afc08526a4610dc2b12688986c94425ed93adda048ccf605bf30caf9b8b6b998dc91c9a5c6cea265ec6410c95d3b3c9055914cf2c6227ab77
6
+ metadata.gz: 8fd318bf3aaa6039226e32a93703ebe5ad89e66b1c739378c525a160a7ae0f902b1709ea421b3849472243f5d3fe3f00ac35f91d7102accf856ceda28f6e3ae9
7
+ data.tar.gz: b7c0d69d5230806fbd630ac857abb8dd091f6f1dee8a3708f7f1485c57abcd3c063ae2250843a6a91503f23980a19ec8bbb7a388ade6168ec3ab5ac2547a98f7
data/CHANGELOG.md CHANGED
@@ -3,6 +3,9 @@
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
+ ## [2.2.1]
7
+ - #369 clean up authorizers and bug fixes
8
+
6
9
  ## [2.2.0]
7
10
  - #368 API Gateway Authorizer Concept Support
8
11
 
@@ -33,7 +33,8 @@ module Jets::Authorizer
33
33
  # function associated with the cognito authorizer.
34
34
  def cognito_authorizer(props={})
35
35
  resources = [props]
36
- meth = props[:name]
36
+ # Authorizer name can have dashes, but "method" name should be underscored for correct logical id.
37
+ meth = props[:name].gsub('-','_')
37
38
  resource = Jets::Resource::ApiGateway::Authorizer.new(props)
38
39
 
39
40
  # Mimic task to grab base_replacements, namely namespace.
@@ -31,17 +31,14 @@ module Jets::Authorizer::Helpers
31
31
  props[:usage_identifier_key] = usage_identifier_key if usage_identifier_key
32
32
  end
33
33
 
34
- props = Jets::Camelizer.transform(props) # keys get converted from Symbols to Strings as part of this
35
- # Only top-level keys and keys under context are pascalized
36
- props.transform_keys! { |k| pascalize(k) }
37
- if props['context']
38
- props['context'].transform_keys! { |k| pascalize(k) }
39
- end
34
+ props.transform_keys! { |k| pascalize(k) } # Only top-level keys are pascalized
35
+ # policyDocument is camelized, everything else is left alone
36
+ props["policyDocument"] = Jets::Camelizer.transform(props["policyDocument"])
40
37
  props
41
38
  end
42
39
 
43
40
  def pascalize(value)
44
- new_value = value.camelize
41
+ new_value = value.to_s.camelize
45
42
  first_char = new_value[0..0].downcase
46
43
  new_value[0] = first_char
47
44
  new_value
@@ -24,6 +24,10 @@ module Jets::Cfn::Builders
24
24
  add_parameter(route.authorizer_id, description: route.authorizer_metadata)
25
25
  end
26
26
  end
27
+
28
+ if @app_class.authorizer
29
+ add_parameter(@app_class.authorizer_id, description: @app_class.authorizer_metadata)
30
+ end
27
31
  end
28
32
 
29
33
  def add_routes
@@ -31,24 +31,34 @@ class Jets::Controller
31
31
  end
32
32
  end
33
33
 
34
- def authorizer_logical_id(action_name)
34
+ def authorizer_metadata
35
+ Jets::Router::Route::Authorizer.metadata(auth_to)
36
+ end
37
+
38
+ # Used to add to parameter to controller templates
39
+ def authorizer_id
40
+ Jets::Router::Route::Authorizer.logical_id(auth_to)
41
+ end
42
+
43
+ # Used to add to the API::Gateway Method selectively
44
+ def authorizer_logical_id_for(action_name)
35
45
  return unless auth_to
36
46
 
37
47
  only = auth_options[:only].map(&:to_s) if auth_options && auth_options[:only]
38
48
  except = auth_options[:except].map(&:to_s) if auth_options && auth_options[:except]
39
49
 
40
50
  if except and !except.include?(action_name)
41
- logical_id = Jets::Router::Route.authorizer_logical_id(auth_to)
51
+ logical_id = Jets::Router::Route::Authorizer.logical_id(auth_to)
42
52
  end
43
53
 
44
54
  # only overrides except
45
55
  if only and only.include?(action_name)
46
- logical_id = Jets::Router::Route.authorizer_logical_id(auth_to)
56
+ logical_id = Jets::Router::Route::Authorizer.logical_id(auth_to)
47
57
  end
48
58
 
49
59
  # if both only and except are not set then always set the logical_id
50
60
  if !only && !except
51
- logical_id = Jets::Router::Route.authorizer_logical_id(auth_to)
61
+ logical_id = Jets::Router::Route::Authorizer.logical_id(auth_to)
52
62
  end
53
63
 
54
64
  logical_id
@@ -56,7 +66,7 @@ class Jets::Controller
56
66
 
57
67
  # Autoamtically sets authorization_type for the specific route based on the controller authorizer
58
68
  def infer_authorization_type_for(action_name)
59
- return unless authorizer_logical_id(action_name)
69
+ return unless authorizer_logical_id_for(action_name)
60
70
  Jets::Authorizer::Base.authorization_type(auth_to)
61
71
  end
62
72
 
@@ -5,7 +5,7 @@ class Jets::Resource::ApiGateway::Method
5
5
  if @route.authorizer
6
6
  logical_id = @route.authorizer_id
7
7
  elsif controller_klass.authorizer
8
- logical_id = controller_klass.authorizer_logical_id(@route.action_name)
8
+ logical_id = controller_klass.authorizer_logical_id_for(@route.action_name)
9
9
  end
10
10
 
11
11
  "!Ref #{logical_id}" if logical_id
@@ -6,7 +6,7 @@
6
6
  class Jets::Router
7
7
  class Route
8
8
  include Util
9
- include Authorization
9
+ include Authorizer
10
10
 
11
11
  CAPTURE_REGEX = "([^/]*)" # as string
12
12
 
@@ -1,30 +1,15 @@
1
1
  class Jets::Router::Route
2
- module Authorization
3
- extend ActiveSupport::Concern
4
-
5
- class_methods do
6
- # Use by both Route and Controller
7
- def authorizer_logical_id(authorizer, prefix_class: true)
8
- klass, meth = authorizer.split("#")
9
- words = [meth, "authorizer"]
10
- words.unshift(klass) if prefix_class
11
- words.join('_').camelize # logical_id
12
- end
13
- end
14
-
2
+ module Authorizer
15
3
  # IE: main#protect => MainProtectAuthorizer
16
4
  def authorizer_id(prefix_class: true)
17
5
  return unless authorizer
18
- self.class.authorizer_logical_id(authorizer, prefix_class: prefix_class)
6
+ logical_id(authorizer, prefix_class: prefix_class)
19
7
  end
20
8
 
21
9
  # Metadata about the authorizer class that can be used later. Stored in the Authorizer template parameters.
22
10
  # In app_class.rb `def controller_params` it is used to build the input parameters for controller templates.
23
11
  def authorizer_metadata
24
- klass = authorizer.split("#").first
25
- authorizer_class = "#{klass}_authorizer".camelize
26
- logical_id = authorizer_id(prefix_class: false)
27
- "#{authorizer_class}.#{logical_id}"
12
+ metadata(authorizer)
28
13
  end
29
14
 
30
15
  def authorizer
@@ -39,10 +24,30 @@ class Jets::Router::Route
39
24
  @options[:api_key_required]
40
25
  end
41
26
 
27
+ module ModuleMethods
28
+ def logical_id(authorizer, prefix_class: true)
29
+ klass, meth = authorizer.split("#")
30
+ words = [meth, "authorizer"]
31
+ words.unshift(klass) if prefix_class
32
+ words.join('_').camelize # logical_id
33
+ end
34
+
35
+ def metadata(authorizer)
36
+ klass = authorizer.split("#").first
37
+ authorizer_class = "#{klass}_authorizer".camelize
38
+ logical_id = logical_id(authorizer, prefix_class: false)
39
+ # IE: MainAuthorizer.ProtectAuthorizer
40
+ "#{authorizer_class}.#{logical_id}"
41
+ end
42
+ end
43
+ include ModuleMethods # so available as instance methods
44
+ extend ModuleMethods # so also available as module method. IE: Jets::Router::Route::Authorizer.metadata(auth_to)
45
+
42
46
  private
43
47
  def inferred_authorization_type
44
48
  return unless authorizer
45
49
  Jets::Authorizer::Base.authorization_type(authorizer)
46
50
  end
51
+
47
52
  end
48
53
  end
data/lib/jets/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Jets
2
- VERSION = "2.2.0"
2
+ VERSION = "2.2.1"
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: 2.2.0
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-09-11 00:00:00.000000000 Z
11
+ date: 2019-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionmailer
@@ -940,7 +940,7 @@ files:
940
940
  - lib/jets/router/resources/filter.rb
941
941
  - lib/jets/router/resources/options.rb
942
942
  - lib/jets/router/route.rb
943
- - lib/jets/router/route/authorization.rb
943
+ - lib/jets/router/route/authorizer.rb
944
944
  - lib/jets/router/scope.rb
945
945
  - lib/jets/router/util.rb
946
946
  - lib/jets/rule/base.rb