Merge pull request #4 from atomaka/feature/paginate

Handle pagination
This commit is contained in:
Andrew Tomaka 2018-05-07 11:36:11 -04:00 committed by GitHub
commit 1d82e1fa48
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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 }