Handle pagination

The spec on this is pretty subpar. This is hacked in to resolve a
production issue!  Failed to realize that the Ruby SDK limits parameter
responses to 10 because the CLI does not.
This commit is contained in:
Andrew Tomaka 2018-05-07 11:19:35 -04:00
parent ca7fe0555a
commit d95c8b1b0f
Signed by: atomaka
GPG key ID: 61209BF70A5B18BE
2 changed files with 39 additions and 4 deletions

View file

@ -38,9 +38,16 @@ module Psenv
end
def parameters
ssm.
get_parameters_by_path(path: @path, with_decryption: true).
parameters
parameters = []
response = ssm.get_parameters_by_path(path: @path, with_decryption: true)
parameters << response.parameters
while response.next_page?
response = response.next_page
parameters << response.parameters
end
parameters.flatten
rescue StandardError => error
raise RetrieveError, error
end

View file

@ -41,7 +41,7 @@ RSpec.describe Psenv::Retriever do
subject { Psenv::Retriever.new("/psenv/test").call }
context "with a successful request" do
context "with a single page request" do
before(:each) do
allow(ssm).to receive(:get_parameters_by_path) {
OpenStruct.new(
@ -60,6 +60,34 @@ RSpec.describe Psenv::Retriever do
end
end
context "with multiple pages" do
before(:each) do
allow(ssm).to receive(:get_parameters_by_path) {
OpenStruct.new(
parameters: [{
name: "/psenv/test/API_KEY",
value: "value",
type: "String",
version: 1,
}],
next_page?: true,
next_page: OpenStruct.new(
parameters: [{
name: "/psenv/test/CLIENT_KEY",
value: "value",
type: "String",
version: 1,
}],
),
)
}
end
it "returns both parameters" do
expect(subject).to eq("API_KEY" => "value", "CLIENT_KEY" => "value")
end
end
context "when the request fails" do
before(:each) { allow(ssm).to receive(:get_parameters_by_path).and_raise }