Skip to content

Commit

Permalink
Merge pull request #583 from anjo-swe/ssm_parameter_pagination
Browse files Browse the repository at this point in the history
Added pagination support to ssm_parameter
  • Loading branch information
k1LoW authored Jan 4, 2024
2 parents 7be2a28 + 8c7193d commit 5e8b61f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 deletions.
27 changes: 17 additions & 10 deletions lib/awspec/helper/finder/ssm_parameter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@ module Awspec::Helper
module Finder
module SsmParameter
def find_ssm_parameter(name)
ssm_client.describe_parameters(
{
filters: [
{
key: 'Name',
values: [name]
}
]
}
).parameters[0]
req = {
filters: [
{
key: 'Name',
values: [name]
}
]
}
loop do
res = ssm_client.describe_parameters(req)
if res.parameters.size >= 1
return res.parameters.first
end
break if res.next_token.nil?

req[:next_token] = res.next_token
end
end

def find_parameter_tag(id, tag_key)
Expand Down
24 changes: 18 additions & 6 deletions lib/awspec/stub/ssm_parameter.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
# frozen_string_literal: true

Aws.config[:ssm] = {
stub_responses: {
describe_parameters: {
def describe_parameters_response(context)
next_token = 'eyJOZXh0VG9rZW4iOiBudWxsLCAiYm90b190cnVuY2F0ZV9hbW91bnQiOiAxfQ=='
if context.params[:next_token] == next_token
{
parameters: [
{
name: 'my-parameter',
type: 'SecureString',
key_id: 'alias/aws/ssm',
description: 'Some description',
version: 1,
next_token: nil
version: 1
}
]
],
next_token: nil
}
else
{
parameters: [],
next_token: next_token
}
end
end

Aws.config[:ssm] = {
stub_responses: {
describe_parameters: ->(context) { describe_parameters_response(context) }
}
}

0 comments on commit 5e8b61f

Please sign in to comment.