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:
parent
ca7fe0555a
commit
d95c8b1b0f
2 changed files with 39 additions and 4 deletions
|
@ -38,9 +38,16 @@ module Psenv
|
||||||
end
|
end
|
||||||
|
|
||||||
def parameters
|
def parameters
|
||||||
ssm.
|
parameters = []
|
||||||
get_parameters_by_path(path: @path, with_decryption: true).
|
response = ssm.get_parameters_by_path(path: @path, with_decryption: true)
|
||||||
parameters
|
parameters << response.parameters
|
||||||
|
|
||||||
|
while response.next_page?
|
||||||
|
response = response.next_page
|
||||||
|
parameters << response.parameters
|
||||||
|
end
|
||||||
|
|
||||||
|
parameters.flatten
|
||||||
rescue StandardError => error
|
rescue StandardError => error
|
||||||
raise RetrieveError, error
|
raise RetrieveError, error
|
||||||
end
|
end
|
||||||
|
|
|
@ -41,7 +41,7 @@ RSpec.describe Psenv::Retriever do
|
||||||
|
|
||||||
subject { Psenv::Retriever.new("/psenv/test").call }
|
subject { Psenv::Retriever.new("/psenv/test").call }
|
||||||
|
|
||||||
context "with a successful request" do
|
context "with a single page request" do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
allow(ssm).to receive(:get_parameters_by_path) {
|
allow(ssm).to receive(:get_parameters_by_path) {
|
||||||
OpenStruct.new(
|
OpenStruct.new(
|
||||||
|
@ -60,6 +60,34 @@ RSpec.describe Psenv::Retriever do
|
||||||
end
|
end
|
||||||
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
|
context "when the request fails" do
|
||||||
before(:each) { allow(ssm).to receive(:get_parameters_by_path).and_raise }
|
before(:each) { allow(ssm).to receive(:get_parameters_by_path).and_raise }
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue