aws-ssm-env 0.1.1 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (26) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +10 -1
  3. data/README.md +2 -2
  4. data/README_ja.md +1 -1
  5. data/lib/aws-ssm-env/fetcher.rb +5 -12
  6. data/lib/aws-ssm-env/fetchers/begins_with.rb +4 -5
  7. data/lib/aws-ssm-env/fetchers/factory.rb +11 -16
  8. data/lib/aws-ssm-env/fetchers/path.rb +4 -9
  9. data/lib/aws-ssm-env/loader.rb +7 -6
  10. data/lib/aws-ssm-env/naming_strategies/factory.rb +11 -11
  11. data/lib/aws-ssm-env/naming_strategies/snakecase.rb +4 -3
  12. data/lib/aws-ssm-env/version.rb +1 -1
  13. data/lib/aws-ssm-env.rb +2 -2
  14. data/spec/{aws-ssm-env/fetchers/begins_with_spec.rb → aws_ssm_env/begins_with_fetcher_spec.rb} +5 -5
  15. data/spec/{aws-ssm-env/fetchers/factory_spec.rb → aws_ssm_env/fetcher_factory_spec.rb} +2 -2
  16. data/spec/{aws-ssm-env → aws_ssm_env}/fetcher_spec.rb +38 -35
  17. data/spec/{aws-ssm-env → aws_ssm_env}/loader_spec.rb +9 -9
  18. data/spec/{aws-ssm-env/naming_strategies/factory_spec.rb → aws_ssm_env/naming_strategy_factory_spec.rb} +2 -2
  19. data/spec/{aws-ssm-env → aws_ssm_env}/parameter.rb +1 -0
  20. data/spec/{aws-ssm-env/fetchers/path_spec.rb → aws_ssm_env/path_fetcher_spec.rb} +2 -2
  21. data/spec/{aws-ssm-env/naming_strategies/snakecase_spec.rb → aws_ssm_env/snake_case_naming_strategy_spec.rb} +1 -1
  22. data/spec/{aws-ssm-env_spec.rb → aws_ssm_env_spec.rb} +25 -24
  23. data/spec/spec_helper.rb +2 -2
  24. metadata +49 -50
  25. /data/spec/{aws-ssm-env/naming_strategies/basename_spec.rb → aws_ssm_env/basename_naming_strategy_spec.rb} +0 -0
  26. /data/spec/{aws-ssm-env → aws_ssm_env}/naming_strategy_spec.rb +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 42b51ae8562dfef400fdc2a244ac04ee333d76e836b80b1cd722ca3027bde2d4
4
- data.tar.gz: 351176835c06d118460bb5455a34cfdd3198771b161aca9c1d8e66aac0eb0368
3
+ metadata.gz: be6a2edcd4a52513b69f9772ab8d2fc1a1fb0df183c23cc634e14e5ff326b4d7
4
+ data.tar.gz: 83d419751b1ac7ed482f5a7891eba301c7ed6cad5e91df1cbe5ce0772224f132
5
5
  SHA512:
6
- metadata.gz: 27a30b575fd1b1b1ca6b951df0bff61f61b549f59f8568039007d352ae61b65f5c204b88e43ef23f95cf9caff66d5437ac2fad8d3091a964b499747afc6b1615
7
- data.tar.gz: 7cab36b73fa5adeb5c2532695239777aa97be74128668b34ec8a48a57833f7b53dd19e7e68bd5518087fa1d4f9795685876d5f5a1170f6f15c915d3d84e8f74f
6
+ metadata.gz: 7272c39318b617cc4f61628cabeed3fb79292b7e0813959c51ef81f7390fb95374661d129f89aa16bfabee256ba54fd56275ba36134345a6f2bb175b0b56e013
7
+ data.tar.gz: b4b1bede2255c8ab6269e69b4b01636fd0b6700db00e4e6704ccbe6f17d17d5fbe92f54151ac6100fc0e01581faa734a0c865d0b07f309ed44f685264dea83c2
data/CHANGELOG.md CHANGED
@@ -1,7 +1,16 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.1.3 (2024-01-29)
4
+
5
+ - Change ruby supported versions #14
6
+
7
+ ## 0.1.2 (2020-12-02)
8
+
9
+ - Add ruby 2.7 to Travis CI test matrix #7
10
+ - Fix for early abort when next_token is not null #8
11
+ - drop ruby 2.4 support, and fix warnings #11
12
+
3
13
  ## 0.1.1 (2018-01-16)
4
14
 
5
15
  - Translate README.
6
16
  - Added ruby 2.5 tests.
7
-
data/README.md CHANGED
@@ -16,7 +16,7 @@ The naming of environment variables is optional and can be customized.
16
16
 
17
17
  ## Installation
18
18
 
19
- This gem has been tested with ruby version 2.2 to 2.5.
19
+ This gem has been tested with ruby version 2.7 to 3.3.
20
20
 
21
21
  ```
22
22
  gem install aws-ssm-env
@@ -67,7 +67,7 @@ Or, you can pass `ssm_client_args` as the argument for `AwsSsmEnv#load`:
67
67
 
68
68
  ```ruby
69
69
  AwsSsmEnv.load(
70
- fetch: "/myservice/#{ENV['RAILS_ENV']}",
70
+ path: "/myservice/#{ENV['RAILS_ENV']}",
71
71
  ssm_client_args: {
72
72
  access_key_id: 'ACCESS_KEY_ID',
73
73
  secret_access_key: 'SECRET_ACCESS_KEY',
data/README_ja.md CHANGED
@@ -13,7 +13,7 @@ AWS EC2 Parameter Storeから取得したパラメータを環境変数として
13
13
 
14
14
  ## Installation
15
15
 
16
- このgemはRuby2.2から2.5まででテストされています。
16
+ このgemはRuby2.7から3.3まででテストされています。
17
17
 
18
18
  ```
19
19
  gem install aws-ssm-env
@@ -23,25 +23,20 @@ module AwsSsmEnv
23
23
  #
24
24
  # @see http://docs.aws.amazon.com/sdk-for-ruby/v3/api/index.html
25
25
  def initialize(**args)
26
- @client = create_ssm_client(args)
27
- @with_decryption = with_decryption?(args)
26
+ @client = create_ssm_client(**args)
27
+ @with_decryption = with_decryption?(**args)
28
28
  end
29
29
 
30
30
  # Iteratorパターンを実装したメソッド。AwsSsmEnv#load から呼び出される。
31
31
  # 実際のパラメータ取得はサブクラスで実装された fetch メソッドで行う。
32
32
  # @yield [consumer] 取得したパラメータを受け取って処理を行うブロック引数。
33
33
  # @yieldparam [Aws::SSM::Types::Parameter] parameter パラメータ
34
- def each
34
+ def each(&block)
35
35
  next_token = nil
36
36
  loop do
37
37
  response = fetch(next_token)
38
38
  next_token = response.next_token
39
- if response.parameters.empty?
40
- break
41
- end
42
- response.parameters.each do |p|
43
- yield(p)
44
- end
39
+ response.parameters.each(&block)
45
40
  if next_token.nil?
46
41
  break
47
42
  end
@@ -80,10 +75,8 @@ module AwsSsmEnv
80
75
  def with_decryption?(decryption: 'true', **)
81
76
  if decryption.nil?
82
77
  true
83
- elsif decryption.to_s.downcase == 'true'
84
- true
85
78
  else
86
- false
79
+ decryption.to_s.downcase == 'true'
87
80
  end
88
81
  end
89
82
 
@@ -16,7 +16,7 @@ module AwsSsmEnv
16
16
  # @option args [Integet] :fetch_size <optional> 一度のAPI実行で取得するパラメータ数。最大50。デフォルトは50。
17
17
  def initialize(**args)
18
18
  super
19
- @base_params = base_params(args)
19
+ @base_params = base_params(**args)
20
20
  end
21
21
 
22
22
  protected
@@ -44,6 +44,7 @@ module AwsSsmEnv
44
44
  if begins_with.nil?
45
45
  raise ArgumentError, ':begins_with is required.'
46
46
  end
47
+
47
48
  {
48
49
  parameter_filters: to_parameter_filters(begins_with),
49
50
  max_results: detect_max_results(fetch_size)
@@ -51,9 +52,7 @@ module AwsSsmEnv
51
52
  end
52
53
 
53
54
  def detect_max_results(fetch_size)
54
- if fetch_size.nil?
55
- MAX_FETCH_SIZE
56
- elsif fetch_size.to_i > MAX_FETCH_SIZE
55
+ if fetch_size.nil? || fetch_size.to_i > MAX_FETCH_SIZE
57
56
  MAX_FETCH_SIZE
58
57
  else
59
58
  fetch_size.to_i
@@ -62,7 +61,7 @@ module AwsSsmEnv
62
61
 
63
62
  def to_parameter_filters(begins_with)
64
63
  values = Array(begins_with)
65
- [ BASE_FILTER.merge(values: values) ]
64
+ [BASE_FILTER.merge(values: values)]
66
65
  end
67
66
 
68
67
  def fetch_params(next_token)
@@ -19,16 +19,17 @@ module AwsSsmEnv
19
19
  fetch_type = args[:fetch]
20
20
  case fetch_type
21
21
  when nil
22
- default_fetcher(args)
22
+ default_fetcher(**args)
23
23
  when PATH_FETCHER
24
- create_path_fetcher(args)
24
+ create_path_fetcher(**args)
25
25
  when BEGINS_WITH_FETCHER
26
- create_begins_with_fetcher(args)
26
+ create_begins_with_fetcher(**args)
27
27
  else
28
28
  unless fetcher_instance?(fetch_type)
29
- raise ArgumentError, 'Possible values for :fetch are either :path, :begins_with, ' \
30
- + '"AwsSsmEnv::Fetcher" implementation class, an object with "each" method.'
29
+ raise ArgumentError,
30
+ 'Possible values for :fetch are either :path, :begins_with, "AwsSsmEnv::Fetcher" implementation class, an object with "each" method.' # rubocop:disable Layout/LineLength
31
31
  end
32
+
32
33
  fetch_type
33
34
  end
34
35
  end
@@ -37,30 +38,24 @@ module AwsSsmEnv
37
38
 
38
39
  def default_fetcher(**args)
39
40
  if args.key?(:begins_with)
40
- create_begins_with_fetcher(args)
41
+ create_begins_with_fetcher(**args)
41
42
  else
42
- create_path_fetcher(args)
43
+ create_path_fetcher(**args)
43
44
  end
44
45
  end
45
46
 
46
47
  def create_path_fetcher(**args)
47
48
  require 'aws-ssm-env/fetchers/path'
48
- AwsSsmEnv::PathFetcher.new(args)
49
+ AwsSsmEnv::PathFetcher.new(**args)
49
50
  end
50
51
 
51
52
  def create_begins_with_fetcher(**args)
52
53
  require 'aws-ssm-env/fetchers/begins_with'
53
- AwsSsmEnv::BeginsWithFetcher.new(args)
54
+ AwsSsmEnv::BeginsWithFetcher.new(**args)
54
55
  end
55
56
 
56
57
  def fetcher_instance?(object)
57
- if object.is_a?(AwsSsmEnv::Fetcher)
58
- true
59
- elsif object.respond_to?(:each)
60
- true
61
- else
62
- false
63
- end
58
+ object.is_a?(AwsSsmEnv::Fetcher) || object.respond_to?(:each)
64
59
  end
65
60
  end
66
61
  end
@@ -18,7 +18,7 @@ module AwsSsmEnv
18
18
  # @option args [Integer] :fetch_size <optional> 一度のAPI実行で取得するパラメータ数。最大10。デフォルトは10。
19
19
  def initialize(**args)
20
20
  super
21
- @base_params = base_params(args)
21
+ @base_params = base_params(**args)
22
22
  end
23
23
 
24
24
  protected
@@ -38,6 +38,7 @@ module AwsSsmEnv
38
38
  if path.nil?
39
39
  raise ArgumentError, 'path is required.'
40
40
  end
41
+
41
42
  {
42
43
  path: path,
43
44
  recursive: recursive?(recursive),
@@ -47,17 +48,11 @@ module AwsSsmEnv
47
48
  end
48
49
 
49
50
  def recursive?(recursive)
50
- if recursive.to_s.downcase == 'true'
51
- true
52
- else
53
- false
54
- end
51
+ recursive.to_s.downcase == 'true'
55
52
  end
56
53
 
57
54
  def detect_max_results(fetch_size)
58
- if fetch_size.nil?
59
- MAX_FETCH_SIZE
60
- elsif fetch_size.to_i > 10
55
+ if fetch_size.nil? || fetch_size.to_i > 10
61
56
  MAX_FETCH_SIZE
62
57
  else
63
58
  fetch_size.to_i
@@ -10,11 +10,11 @@ module AwsSsmEnv
10
10
  class Loader
11
11
  # メイン処理。引数の詳細は AwsSsmEnv#load を参照。
12
12
  def self.load(**args)
13
- new(args).load
13
+ new(**args).load
14
14
  end
15
15
 
16
16
  def initialize(**args)
17
- parse_options(args)
17
+ parse_options(**args)
18
18
  if @logger
19
19
  @logger.debug("#{self.class.name} overwrite: #{@overwrite}")
20
20
  @logger.debug("#{self.class.name} fetcher: #{@fetcher}")
@@ -25,7 +25,7 @@ module AwsSsmEnv
25
25
  def load
26
26
  @fetcher.each do |parameter|
27
27
  var_name = @naming_strategy.parse_name(parameter)
28
- @logger.debug("#{self.class.name} #{parameter.name} parameter value into ENV['#{var_name}']") if @logger
28
+ @logger&.debug("#{self.class.name} #{parameter.name} parameter value into ENV['#{var_name}']")
29
29
  send(@applier, var_name, parameter.value)
30
30
  end
31
31
  end
@@ -34,9 +34,9 @@ module AwsSsmEnv
34
34
 
35
35
  def parse_options(**options)
36
36
  @logger = options[:logger]
37
- @fetcher = AwsSsmEnv::FetcherFactory.create_fetcher(options)
38
- @naming_strategy = AwsSsmEnv::NamingStrategyFactory.create_naming_strategy(options)
39
- @overwrite = overwrite?(options)
37
+ @fetcher = AwsSsmEnv::FetcherFactory.create_fetcher(**options)
38
+ @naming_strategy = AwsSsmEnv::NamingStrategyFactory.create_naming_strategy(**options)
39
+ @overwrite = overwrite?(**options)
40
40
  if @overwrite
41
41
  @applier = :apply!
42
42
  else
@@ -57,6 +57,7 @@ module AwsSsmEnv
57
57
  if ENV[name]
58
58
  return
59
59
  end
60
+
60
61
  apply!(name, value)
61
62
  end
62
63
 
@@ -18,13 +18,14 @@ module AwsSsmEnv
18
18
  def create_naming_strategy(**args)
19
19
  naming_strategy = args[:naming]
20
20
  if naming_strategy.nil?
21
- return default_strategy(args)
21
+ return default_strategy(**args)
22
22
  end
23
+
23
24
  case naming_strategy
24
25
  when BASENAME_STRATEGY
25
- create_basename_strategy(args)
26
+ create_basename_strategy(**args)
26
27
  when SNAKE_CASE_STRATEGY
27
- create_snakecase_strategy(args)
28
+ create_snakecase_strategy(**args)
28
29
  else
29
30
  unknown_naming_strategy(naming_strategy)
30
31
  end
@@ -33,34 +34,33 @@ module AwsSsmEnv
33
34
  private
34
35
 
35
36
  def default_strategy(**args)
36
- create_basename_strategy(args)
37
+ create_basename_strategy(**args)
37
38
  end
38
39
 
39
40
  def create_basename_strategy(**args)
40
41
  require 'aws-ssm-env/naming_strategies/basename'
41
- AwsSsmEnv::BasenameNamingStrategy.new(args)
42
+ AwsSsmEnv::BasenameNamingStrategy.new(**args)
42
43
  end
43
44
 
44
45
  def create_snakecase_strategy(**args)
45
46
  require 'aws-ssm-env/naming_strategies/snakecase'
46
- AwsSsmEnv::SnakeCaseNamingStrategy.new(args)
47
+ AwsSsmEnv::SnakeCaseNamingStrategy.new(**args)
47
48
  end
48
49
 
49
50
  def unknown_naming_strategy(naming_strategy)
50
51
  unless naming_strategy_instance?(naming_strategy)
51
- raise ArgumentError, 'Possible values for :naming are either :basename, :snakecase, ' \
52
- + '"AwsSsmEnv::NamingStrategy" implementation class, an object with "parse_name" method.'
52
+ raise ArgumentError,
53
+ 'Possible values for :naming are either :basename, :snakecase, "AwsSsmEnv::NamingStrategy" implementation class, an object with "parse_name" method.' # rubocop:disable Layout/LineLength
53
54
  end
55
+
54
56
  naming_strategy
55
57
  end
56
58
 
57
59
  def naming_strategy_instance?(object)
58
60
  if object.is_a?(AwsSsmEnv::NamingStrategy)
59
61
  true
60
- elsif object.respond_to?(:parse_name)
61
- true
62
62
  else
63
- false
63
+ object.respond_to?(:parse_name)
64
64
  end
65
65
  end
66
66
  end
@@ -17,11 +17,12 @@ module AwsSsmEnv
17
17
  # @option args [String, Regexp] :delimiter
18
18
  # アンダースコアに変換する区切り文字。デフォルトはスラッシュ('/')。 TODO: AwsSsmEnv#loadとREADMEに反映
19
19
  def initialize(**args)
20
+ super
20
21
  @logger = args[:logger]
21
- @delimiter = detect_delimiter(args)
22
- removed_prefix = detect_prefix(args).sub(%r{/\z}, '')
22
+ @delimiter = detect_delimiter(**args)
23
+ removed_prefix = detect_prefix(**args).sub(%r{/\z}, '')
23
24
  @removed_prefix = /\A#{Regexp.escape(removed_prefix)}/
24
- @logger.debug("#{self.class.name} removed_prefix is #{@removed_prefix}") if @logger
25
+ @logger&.debug("#{self.class.name} removed_prefix is #{@removed_prefix}")
25
26
  end
26
27
 
27
28
  # @see AwsSsmEnv::NamingStrategy#parse_name
@@ -1,3 +1,3 @@
1
1
  module AwsSsmEnv
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.1.3'.freeze
3
3
  end
data/lib/aws-ssm-env.rb CHANGED
@@ -149,12 +149,12 @@ module AwsSsmEnv
149
149
  #
150
150
  # @see AwsSsmEnv::Loader#load
151
151
  def load(**args)
152
- AwsSsmEnv::Loader.load(args)
152
+ AwsSsmEnv::Loader.load(**args)
153
153
  end
154
154
 
155
155
  # `overwrite`オプションを付与した AwsSsmEnv::Loader#load の委譲メソッド。
156
156
  # @see AwsSsmEnv::Loader#load
157
157
  def load!(**args)
158
- AwsSsmEnv::Loader.load(args.merge(overwrite: true))
158
+ AwsSsmEnv::Loader.load(**args.merge(overwrite: true))
159
159
  end
160
160
  end
@@ -2,9 +2,9 @@ require 'spec_helper'
2
2
  require 'aws-ssm-env/fetchers/begins_with'
3
3
 
4
4
  describe AwsSsmEnv::BeginsWithFetcher do
5
- let(:fetcher) { described_class.new(args) }
6
- let(:args) { { begins_with: [ '/foo', '/bar' ] } }
7
- let(:base_params) { fetcher.instance_variable_get(:'@base_params') }
5
+ let(:fetcher) { described_class.new(**args) }
6
+ let(:args) { { begins_with: ['/foo', '/bar'] } }
7
+ let(:base_params) { fetcher.instance_variable_get(:@base_params) }
8
8
  let(:parameter_filter) { base_params[:parameter_filters][0] }
9
9
 
10
10
  describe '#initialize' do
@@ -24,7 +24,7 @@ describe AwsSsmEnv::BeginsWithFetcher do
24
24
  let(:args) { { begins_with: '/foo' } }
25
25
 
26
26
  it 'parameter_filter[:values] is [ begins_with value ]' do
27
- expect(parameter_filter[:values]).to eq([ args[:begins_with] ])
27
+ expect(parameter_filter[:values]).to eq([args[:begins_with]])
28
28
  end
29
29
  end
30
30
 
@@ -84,7 +84,7 @@ describe AwsSsmEnv::BeginsWithFetcher do
84
84
  end
85
85
 
86
86
  context 'when describe_parameters return not empty parameters' do
87
- let!(:dummy_parameters) { [ Parameter.new('foo'), Parameter.new('bar') ] }
87
+ let!(:dummy_parameters) { [Parameter.new('foo'), Parameter.new('bar')] }
88
88
  let!(:dummy_response) { AwsSsmEnv::FetchResult.new(dummy_parameters, 'next_token') }
89
89
 
90
90
  before do
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe AwsSsmEnv::FetcherFactory do
4
4
  describe '#create_fetcher' do
5
- let(:fetcher) { described_class.create_fetcher(args) }
5
+ let(:fetcher) { described_class.create_fetcher(**args) }
6
6
 
7
7
  context 'when fetch was not set' do
8
8
  context 'when begins_with was not set' do
@@ -56,7 +56,7 @@ describe AwsSsmEnv::FetcherFactory do
56
56
  end
57
57
  end
58
58
 
59
- context 'in other cases' do
59
+ context 'when in other cases' do
60
60
  it 'raise error' do
61
61
  expect { described_class.create_fetcher(fetch: 'foo') }.to raise_error(ArgumentError)
62
62
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe AwsSsmEnv::Fetcher do
4
- let(:fetcher) { described_class.new(args) }
4
+ let(:fetcher) { described_class.new(**args) }
5
5
  let(:args) { {} }
6
6
  let(:client) { fetcher.send(:client) }
7
7
  let(:ssm_client_args) {
@@ -83,61 +83,64 @@ describe AwsSsmEnv::Fetcher do
83
83
  end
84
84
 
85
85
  describe '#each' do
86
- let(:parameters) { [ Parameter.new('foo', 'foo'), Parameter.new('bar', 'bar') ] }
86
+ let(:parameters) { [Parameter.new('foo', 'foo'), Parameter.new('bar', 'bar')] }
87
87
  let(:fetcher) {
88
88
  mock_class = Class.new(described_class) do
89
- def initialize(response); @response = response; end
90
- protected def fetch(_); @response; end
89
+ def initialize(responses)
90
+ super()
91
+ @responses = responses
92
+ end
93
+
94
+ protected
95
+
96
+ def fetch(_); @responses.shift; end
91
97
  end
92
- mock_class.new(dummy_response)
98
+ mock_class.new(responses)
93
99
  }
94
100
 
101
+ def call_count
102
+ called = 0
103
+ fetcher.each do |_|
104
+ called += 1
105
+ end
106
+ called
107
+ end
108
+
95
109
  context 'when fetch returns empty parameters at first' do
96
- let(:dummy_response) { AwsSsmEnv::FetchResult::EMPTY }
110
+ let(:responses) { [AwsSsmEnv::FetchResult::EMPTY] }
97
111
 
98
112
  it 'consumer is not called' do
99
- called = false
100
- fetcher.each do |_|
101
- called = true
102
- end
103
- expect(called).to be_falsey
113
+ expect(call_count).to eq(0)
114
+ end
115
+ end
116
+
117
+ context 'when fetch returns empty params and next_token at first, fetch returns two parameters and empty next_token at second' do
118
+ let(:responses) {
119
+ [AwsSsmEnv::FetchResult.new([], 'next_token'),
120
+ AwsSsmEnv::FetchResult.new(parameters, nil)]
121
+ }
122
+
123
+ it 'consumer is called twice' do
124
+ expect(call_count).to eq(2)
104
125
  end
105
126
  end
106
127
 
107
128
  context 'when fetch returns two parameters at first and empty next_token' do
108
- let(:dummy_response) { AwsSsmEnv::FetchResult.new(parameters, nil) }
129
+ let(:responses) { [AwsSsmEnv::FetchResult.new(parameters, nil)] }
109
130
 
110
131
  it 'consumer is called twice' do
111
- called = 0
112
- fetcher.each do |_|
113
- called += 1
114
- end
115
- expect(called).to eq(2)
132
+ expect(call_count).to eq(2)
116
133
  end
117
134
  end
118
135
 
119
136
  context 'when fetch returns two parameters and next_token at first, fetch returns two parameters and empty next_token at second' do
120
- let(:fetcher) {
121
- mock_class = Class.new(described_class) do
122
- def initialize(parameters); @parameters = parameters; @count = 0; end
123
- protected def fetch(_)
124
- if @count == 0
125
- @count = 1
126
- AwsSsmEnv::FetchResult.new(@parameters, 'next_token')
127
- else
128
- AwsSsmEnv::FetchResult.new(@parameters, nil)
129
- end
130
- end
131
- end
132
- mock_class.new(parameters)
137
+ let(:responses) {
138
+ [AwsSsmEnv::FetchResult.new(parameters, 'next_token'),
139
+ AwsSsmEnv::FetchResult.new(parameters, nil)]
133
140
  }
134
141
 
135
142
  it 'consumer is called four times' do
136
- called = 0
137
- fetcher.each do |_|
138
- called += 1
139
- end
140
- expect(called).to eq(4)
143
+ expect(call_count).to eq(4)
141
144
  end
142
145
  end
143
146
  end
@@ -4,7 +4,7 @@ describe AwsSsmEnv::Loader do
4
4
  let(:args) { { path: '/foo' } }
5
5
 
6
6
  describe '#initialize' do
7
- let(:loader) { described_class.new(args) }
7
+ let(:loader) { described_class.new(**args) }
8
8
 
9
9
  it 'has fetcher and naming_strategy' do
10
10
  expect(loader.instance_variable_get(:@fetcher)).to be_a(AwsSsmEnv::PathFetcher)
@@ -52,14 +52,14 @@ describe AwsSsmEnv::Loader do
52
52
  ENV['foo'] = nil
53
53
  ENV['fizz'] = 'fizz'
54
54
 
55
- loader = described_class.new(args)
55
+ loader = described_class.new(**args)
56
56
  loader.instance_variable_set(:@fetcher,
57
- [ Parameter.new('foo', 'bar'), Parameter.new('fizz', 'buzz') ])
57
+ [Parameter.new('foo', 'bar'), Parameter.new('fizz', 'buzz')])
58
58
 
59
59
  loader.load
60
60
 
61
- expect(ENV['foo']).to eq('bar')
62
- expect(ENV['fizz']).to eq('fizz')
61
+ expect(ENV.fetch('foo', nil)).to eq('bar')
62
+ expect(ENV.fetch('fizz', nil)).to eq('fizz')
63
63
  end
64
64
  end
65
65
 
@@ -70,14 +70,14 @@ describe AwsSsmEnv::Loader do
70
70
  ENV['foo'] = nil
71
71
  ENV['fizz'] = 'fizz'
72
72
 
73
- loader = described_class.new(args)
73
+ loader = described_class.new(**args)
74
74
  loader.instance_variable_set(:@fetcher,
75
- [ Parameter.new('foo', 'bar'), Parameter.new('fizz', 'buzz') ])
75
+ [Parameter.new('foo', 'bar'), Parameter.new('fizz', 'buzz')])
76
76
 
77
77
  loader.load
78
78
 
79
- expect(ENV['foo']).to eq('bar')
80
- expect(ENV['fizz']).to eq('buzz')
79
+ expect(ENV.fetch('foo', nil)).to eq('bar')
80
+ expect(ENV.fetch('fizz', nil)).to eq('buzz')
81
81
  end
82
82
  end
83
83
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe AwsSsmEnv::NamingStrategyFactory do
4
4
  describe '#create_naming_strategy' do
5
- let(:naming_strategy) { described_class.create_naming_strategy(args) }
5
+ let(:naming_strategy) { described_class.create_naming_strategy(**args) }
6
6
 
7
7
  context 'when naming was not set' do
8
8
  let(:args) { { naming: nil } }
@@ -48,7 +48,7 @@ describe AwsSsmEnv::NamingStrategyFactory do
48
48
  end
49
49
  end
50
50
 
51
- context 'in other cases' do
51
+ context 'when in other cases' do
52
52
  it 'raise error' do
53
53
  expect { described_class.create_naming_strategy(naming: 'foo') }.to raise_error(ArgumentError)
54
54
  end
@@ -1,5 +1,6 @@
1
1
  class Parameter
2
2
  attr_reader :name, :value
3
+
3
4
  def initialize(*args)
4
5
  @name = args[0]
5
6
  @value = args[1]
@@ -2,9 +2,9 @@ require 'spec_helper'
2
2
  require 'aws-ssm-env/fetchers/path'
3
3
 
4
4
  describe AwsSsmEnv::PathFetcher do
5
- let(:fetcher) { described_class.new(args) }
5
+ let(:fetcher) { described_class.new(**args) }
6
6
  let(:args) { { path: '/path' } }
7
- let(:base_params) { fetcher.instance_variable_get(:'@base_params') }
7
+ let(:base_params) { fetcher.instance_variable_get(:@base_params) }
8
8
 
9
9
  describe '#initialize' do
10
10
  context 'when path was not set' do
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
  require 'aws-ssm-env/naming_strategies/snakecase'
3
3
 
4
4
  describe AwsSsmEnv::SnakeCaseNamingStrategy do
5
- let(:strategy) { described_class.new(args) }
5
+ let(:strategy) { described_class.new(**args) }
6
6
  let(:name) { 'path.to.db/password' }
7
7
  let(:env_name) { strategy.parse_name(Parameter.new(name)) }
8
8
 
@@ -1,6 +1,17 @@
1
1
  require 'spec_helper'
2
2
  require 'logger'
3
3
 
4
+ PARAMETERS = [
5
+ { name: "/test/#{RUBY_VERSION}/aws-ssm-env/db_password", value: 'db_password', type: :SecureString },
6
+ { name: "/test/#{RUBY_VERSION}/aws-ssm-env/db/username", value: 'db_username', type: :String },
7
+ { name: "/test/#{RUBY_VERSION}/aws-ssm-env/roles", value: 'admin,guest', type: :StringList },
8
+ { name: "test.#{RUBY_VERSION}.aws-ssm-env.db_password", value: 'db_password', type: :SecureString },
9
+ { name: "test.#{RUBY_VERSION}.aws-ssm-env.username", value: 'db_username', type: :String },
10
+ { name: "test.#{RUBY_VERSION}.aws-ssm-env.roles", value: 'admin,guest', type: :StringList },
11
+ ].freeze
12
+
13
+ ENV_NAMES = %w[db_password username roles].freeze
14
+
4
15
  describe AwsSsmEnv do
5
16
  let(:ssm_client) {
6
17
  stub_responses = {
@@ -24,8 +35,8 @@ describe AwsSsmEnv do
24
35
 
25
36
  described_class.load(client: ssm_client, path: '/path')
26
37
 
27
- expect(ENV['foo']).to eq('bar')
28
- expect(ENV['fizz']).to eq('fizz')
38
+ expect(ENV.fetch('foo', nil)).to eq('bar')
39
+ expect(ENV.fetch('fizz', nil)).to eq('fizz')
29
40
  end
30
41
  end
31
42
 
@@ -36,8 +47,8 @@ describe AwsSsmEnv do
36
47
 
37
48
  described_class.load!(client: ssm_client, path: '/path', logger: logger)
38
49
 
39
- expect(ENV['foo']).to eq('bar')
40
- expect(ENV['fizz']).to eq('buzz')
50
+ expect(ENV.fetch('foo', nil)).to eq('bar')
51
+ expect(ENV.fetch('fizz', nil)).to eq('buzz')
41
52
  end
42
53
  end
43
54
  end
@@ -54,17 +65,7 @@ describe AwsSsmEnv do
54
65
  # allowed_pattern: "AllowedPattern",
55
66
  # })
56
67
  #
57
- describe 'Integration test', integration: true do
58
- PARAMETERS = [
59
- { name: "/test/#{RUBY_VERSION}/aws-ssm-env/db_password", value: 'db_password', type: :SecureString },
60
- { name: "/test/#{RUBY_VERSION}/aws-ssm-env/db/username", value: 'db_username', type: :String },
61
- { name: "/test/#{RUBY_VERSION}/aws-ssm-env/roles", value: 'admin,guest', type: :StringList },
62
- { name: "test.#{RUBY_VERSION}.aws-ssm-env.db_password", value: 'db_password', type: :SecureString },
63
- { name: "test.#{RUBY_VERSION}.aws-ssm-env.username", value: 'db_username', type: :String },
64
- { name: "test.#{RUBY_VERSION}.aws-ssm-env.roles", value: 'admin,guest', type: :StringList },
65
- ].freeze
66
- ENV_NAMES = %w[db_password username roles].freeze
67
-
68
+ describe 'Integration test', :integration do
68
69
  def remove_env_all
69
70
  ENV_NAMES.each do |name|
70
71
  ENV[name] = nil
@@ -100,18 +101,18 @@ describe AwsSsmEnv do
100
101
  context 'when recursive is true' do
101
102
  it 'set environment variables from EC2 Parameter Store parameters' do
102
103
  described_class.load(path: "/test/#{RUBY_VERSION}/aws-ssm-env", recursive: true, logger: logger)
103
- expect(ENV['db_password']).to eq('db_password')
104
- expect(ENV['username']).to eq('db_username')
105
- expect(ENV['roles']).to eq('admin,guest')
104
+ expect(ENV.fetch('db_password', nil)).to eq('db_password')
105
+ expect(ENV.fetch('username', nil)).to eq('db_username')
106
+ expect(ENV.fetch('roles', nil)).to eq('admin,guest')
106
107
  end
107
108
  end
108
109
 
109
110
  context 'when recursive is false' do
110
111
  it 'set environment variables from EC2 Parameter Store parameters' do
111
112
  described_class.load(path: "/test/#{RUBY_VERSION}/aws-ssm-env", recursive: false, logger: logger)
112
- expect(ENV['db_password']).to eq('db_password')
113
- expect(ENV['username']).to be_nil
114
- expect(ENV['roles']).to eq('admin,guest')
113
+ expect(ENV.fetch('db_password', nil)).to eq('db_password')
114
+ expect(ENV.fetch('username', nil)).to be_nil
115
+ expect(ENV.fetch('roles', nil)).to eq('admin,guest')
115
116
  end
116
117
  end
117
118
  end
@@ -119,9 +120,9 @@ describe AwsSsmEnv do
119
120
  describe 'begins_with fetcher' do
120
121
  it 'set environment variables from EC2 Parameter Store parameters' do
121
122
  described_class.load(begins_with: "test.#{RUBY_VERSION}.aws-ssm-env.", naming: :snakecase, delimiter: '.', logger: logger)
122
- expect(ENV['DB_PASSWORD']).to eq('db_password')
123
- expect(ENV['USERNAME']).to eq('db_username')
124
- expect(ENV['ROLES']).to eq('admin,guest')
123
+ expect(ENV.fetch('DB_PASSWORD', nil)).to eq('db_password')
124
+ expect(ENV.fetch('USERNAME', nil)).to eq('db_username')
125
+ expect(ENV.fetch('ROLES', nil)).to eq('admin,guest')
125
126
  end
126
127
  end
127
128
  end
data/spec/spec_helper.rb CHANGED
@@ -15,8 +15,8 @@ else
15
15
  end
16
16
 
17
17
  require 'aws-ssm-env'
18
- require 'aws-ssm-env/parameter'
18
+ require 'aws_ssm_env/parameter'
19
19
 
20
20
  RSpec.configure do |config|
21
- config.filter_run_excluding(integration: true) unless ENV['CI']
21
+ config.filter_run_excluding(integration: true)
22
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws-ssm-env
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryohei Sonoda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-16 00:00:00.000000000 Z
11
+ date: 2024-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-ssm
@@ -28,86 +28,86 @@ dependencies:
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 13.1.0
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 13.1.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 3.12.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 3.12.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rubocop
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.48.1
61
+ version: 1.60.2
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.48.1
68
+ version: 1.60.2
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rubocop-rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 2.26.1
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 2.26.1
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: simplecov
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: 0.16.1
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: 0.16.1
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: simplecov-console
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">="
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '0'
103
+ version: 0.9.1
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '0'
110
+ version: 0.9.1
111
111
  description: Set parameters acquired from AWS EC2 Parameter Store as environment variables.
112
112
  email:
113
113
  - ryohei-sonoda@m3.com
@@ -130,24 +130,24 @@ files:
130
130
  - lib/aws-ssm-env/naming_strategies/snakecase.rb
131
131
  - lib/aws-ssm-env/naming_strategy.rb
132
132
  - lib/aws-ssm-env/version.rb
133
- - spec/aws-ssm-env/fetcher_spec.rb
134
- - spec/aws-ssm-env/fetchers/begins_with_spec.rb
135
- - spec/aws-ssm-env/fetchers/factory_spec.rb
136
- - spec/aws-ssm-env/fetchers/path_spec.rb
137
- - spec/aws-ssm-env/loader_spec.rb
138
- - spec/aws-ssm-env/naming_strategies/basename_spec.rb
139
- - spec/aws-ssm-env/naming_strategies/factory_spec.rb
140
- - spec/aws-ssm-env/naming_strategies/snakecase_spec.rb
141
- - spec/aws-ssm-env/naming_strategy_spec.rb
142
- - spec/aws-ssm-env/parameter.rb
143
- - spec/aws-ssm-env_spec.rb
133
+ - spec/aws_ssm_env/basename_naming_strategy_spec.rb
134
+ - spec/aws_ssm_env/begins_with_fetcher_spec.rb
135
+ - spec/aws_ssm_env/fetcher_factory_spec.rb
136
+ - spec/aws_ssm_env/fetcher_spec.rb
137
+ - spec/aws_ssm_env/loader_spec.rb
138
+ - spec/aws_ssm_env/naming_strategy_factory_spec.rb
139
+ - spec/aws_ssm_env/naming_strategy_spec.rb
140
+ - spec/aws_ssm_env/parameter.rb
141
+ - spec/aws_ssm_env/path_fetcher_spec.rb
142
+ - spec/aws_ssm_env/snake_case_naming_strategy_spec.rb
143
+ - spec/aws_ssm_env_spec.rb
144
144
  - spec/spec_helper.rb
145
145
  homepage: https://github.com/sonodar/aws-ssm-env-ruby
146
146
  licenses:
147
147
  - Apache-2.0
148
148
  metadata:
149
149
  source_code_uri: https://github.com/sonodar/aws-ssm-env-ruby
150
- changelog_uri: https://github.com/sonodar/aws-ssm-env-ruby/tree/master/aws-ssm-env-ruby/CHANGELOG.md
150
+ changelog_uri: https://github.com/sonodar/aws-ssm-env-ruby/tree/master/CHANGELOG.md
151
151
  post_install_message:
152
152
  rdoc_options: []
153
153
  require_paths:
@@ -156,28 +156,27 @@ required_ruby_version: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - ">="
158
158
  - !ruby/object:Gem::Version
159
- version: '2.2'
159
+ version: '2.7'
160
160
  required_rubygems_version: !ruby/object:Gem::Requirement
161
161
  requirements:
162
162
  - - ">="
163
163
  - !ruby/object:Gem::Version
164
164
  version: '0'
165
165
  requirements: []
166
- rubyforge_project:
167
- rubygems_version: 2.7.4
166
+ rubygems_version: 3.3.26
168
167
  signing_key:
169
168
  specification_version: 4
170
169
  summary: Set parameters acquired from AWS EC2 Parameter Store as environment variables.
171
170
  test_files:
172
- - spec/aws-ssm-env/fetcher_spec.rb
173
- - spec/aws-ssm-env/fetchers/begins_with_spec.rb
174
- - spec/aws-ssm-env/fetchers/factory_spec.rb
175
- - spec/aws-ssm-env/fetchers/path_spec.rb
176
- - spec/aws-ssm-env/loader_spec.rb
177
- - spec/aws-ssm-env/naming_strategies/basename_spec.rb
178
- - spec/aws-ssm-env/naming_strategies/factory_spec.rb
179
- - spec/aws-ssm-env/naming_strategies/snakecase_spec.rb
180
- - spec/aws-ssm-env/naming_strategy_spec.rb
181
- - spec/aws-ssm-env/parameter.rb
182
- - spec/aws-ssm-env_spec.rb
171
+ - spec/aws_ssm_env/basename_naming_strategy_spec.rb
172
+ - spec/aws_ssm_env/begins_with_fetcher_spec.rb
173
+ - spec/aws_ssm_env/fetcher_factory_spec.rb
174
+ - spec/aws_ssm_env/fetcher_spec.rb
175
+ - spec/aws_ssm_env/loader_spec.rb
176
+ - spec/aws_ssm_env/naming_strategy_factory_spec.rb
177
+ - spec/aws_ssm_env/naming_strategy_spec.rb
178
+ - spec/aws_ssm_env/parameter.rb
179
+ - spec/aws_ssm_env/path_fetcher_spec.rb
180
+ - spec/aws_ssm_env/snake_case_naming_strategy_spec.rb
181
+ - spec/aws_ssm_env_spec.rb
183
182
  - spec/spec_helper.rb