Skip to content

Commit d95c8b1

Browse files
committed
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.
1 parent ca7fe05 commit d95c8b1

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

lib/psenv/retriever.rb

+10-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,16 @@ def ssm
3838
end
3939

4040
def parameters
41-
ssm.
42-
get_parameters_by_path(path: @path, with_decryption: true).
43-
parameters
41+
parameters = []
42+
response = ssm.get_parameters_by_path(path: @path, with_decryption: true)
43+
parameters << response.parameters
44+
45+
while response.next_page?
46+
response = response.next_page
47+
parameters << response.parameters
48+
end
49+
50+
parameters.flatten
4451
rescue StandardError => error
4552
raise RetrieveError, error
4653
end

spec/retriever_spec.rb

+29-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
subject { Psenv::Retriever.new("/psenv/test").call }
4343

44-
context "with a successful request" do
44+
context "with a single page request" do
4545
before(:each) do
4646
allow(ssm).to receive(:get_parameters_by_path) {
4747
OpenStruct.new(
@@ -60,6 +60,34 @@
6060
end
6161
end
6262

63+
context "with multiple pages" do
64+
before(:each) do
65+
allow(ssm).to receive(:get_parameters_by_path) {
66+
OpenStruct.new(
67+
parameters: [{
68+
name: "/psenv/test/API_KEY",
69+
value: "value",
70+
type: "String",
71+
version: 1,
72+
}],
73+
next_page?: true,
74+
next_page: OpenStruct.new(
75+
parameters: [{
76+
name: "/psenv/test/CLIENT_KEY",
77+
value: "value",
78+
type: "String",
79+
version: 1,
80+
}],
81+
),
82+
)
83+
}
84+
end
85+
86+
it "returns both parameters" do
87+
expect(subject).to eq("API_KEY" => "value", "CLIENT_KEY" => "value")
88+
end
89+
end
90+
6391
context "when the request fails" do
6492
before(:each) { allow(ssm).to receive(:get_parameters_by_path).and_raise }
6593

0 commit comments

Comments
 (0)