Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added pagination support to ssm_parameter #583

Merged
merged 3 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) }
}
}
Loading