diff --git a/lib/uc3-ssm.rb b/lib/uc3-ssm.rb index fad8c28..3da9433 100644 --- a/lib/uc3-ssm.rb +++ b/lib/uc3-ssm.rb @@ -86,8 +86,7 @@ def parameters_for_path(**options) path_list.each do |root_path| begin options[:path] = root_path - resp = @client.get_parameters_by_path(options) - param_list += resp.parameters if !resp.nil? && resp.parameters.any? + param_list += fetch_param_list(options) rescue Aws::SSM::Errors::ParameterNotFound @logger.debug "ParameterNotFound for path '#{root_path}' in parameters_by_path" next @@ -239,6 +238,20 @@ def retrieve_ssm_value(key) rescue StandardError => e raise ConfigResolverError, "Cannot read SSM parameter #{key} - #{e.message}" end + + # Recursively gather the parameters from SSM + def fetch_param_list(**options) + param_list = [] + resp = @client.get_parameters_by_path(options) + return param_list unless resp.present? && resp.parameters.any? + + param_list += resp.parameters + options[:next_token] = resp.next_token + + param_list += fetch_param_list(options) if options[:next_token].present? + param_list + end + end # rubocop:enable Metrics/ClassLength end diff --git a/lib/uc3-ssm/version.rb b/lib/uc3-ssm/version.rb index fd72ec8..5927d3a 100644 --- a/lib/uc3-ssm/version.rb +++ b/lib/uc3-ssm/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Uc3Ssm - VERSION = '0.3.0' + VERSION = '0.3.1' end diff --git a/spec/test/resolver_spec.rb b/spec/test/resolver_spec.rb index fc84d1d..be63a7b 100644 --- a/spec/test/resolver_spec.rb +++ b/spec/test/resolver_spec.rb @@ -77,7 +77,7 @@ def mock_ssm_not_found(name) it 'throws ConfigResolverError if no ssm_root_path and path is not fully qualified' do expect do @resolver.parameters_for_path(path: 'badpath') - end.to raise_exception(Uc3Ssm::ConfigResolverError) + end.to raise_exception(Uc3Ssm::ConfigResolverError) end it 'searches over ssm_root_path when options[path] not specified' do allow_any_instance_of(Aws::SSM::Client).to receive(:get_parameters_by_path).with(path: '/root/path/') @@ -122,6 +122,15 @@ def mock_ssm_not_found(name) .with(path: '/other/path/foo').and_return(resp2) expect(@resolver_prefix_list.parameters_for_path(path: 'foo')).to eql(%w[c d]) end + it 'returns more than 10 params' do + resp1 = OpenStruct.new(parameters: %w[0 1 2 3 4 5 6 7 8 9], next_token: "foo") + resp2 = OpenStruct.new(parameters: %w[a]) + allow_any_instance_of(Aws::SSM::Client).to receive(:fetch_param_list) + .with(path: '/root/path/foo').and_return(resp1) + allow_any_instance_of(Aws::SSM::Client).to receive(:get_parameters_by_path) + .with(path: '/other/path/foo', next_token: "foo").and_return(resp2) + expect(@resolver_prefix_list.parameters_for_path(path: 'foo')).to eql(%w[0 1 2 3 4 5 6 7 8 9 a]) + end end describe '#parameter_for_key(key)' do