Skip to content

Commit

Permalink
Support parameters in the format supported by "awscli".
Browse files Browse the repository at this point in the history
e.g.

    [
      {
        "ParameterKey": "string",
        "ParameterValue": "string",
        "UsePreviousValue": true|false
      }
    ]

It's irksome that aws-sdk doesn't support this out-of-the-box.
  • Loading branch information
mdub committed Nov 24, 2015
1 parent 10b7dcc commit cb20145
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 9 deletions.
4 changes: 3 additions & 1 deletion bin/stackup
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ Clamp do
return parameters unless parameters.is_a?(Array)
{}.tap do |result|
parameters.each do |p|
result[p["parameter_key"]] = p["parameter_value"]
key = p.fetch("ParameterKey") { p.fetch("parameter_key") }
value = p.fetch("ParameterValue") { p.fetch("parameter_value") }
result[key] = value
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions examples/parameters.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"parameter_key": "IndexDoc",
"parameter_value": "default.htm"
"ParameterKey": "IndexDoc",
"ParameterValue": "default.htm"
}
]
29 changes: 23 additions & 6 deletions lib/stackup/stack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,32 @@ def modify_stack
end

def normalise_parameters(arg)
return arg unless arg.is_a?(Hash)
arg.map do |key, value|
{
:parameter_key => key,
:parameter_value => value
}
if arg.is_a?(Hash)
return arg.map do |key, value|
{
:parameter_key => key,
:parameter_value => value
}
end
end
arg.map do |parameter|
normalise_parameter_keys(parameter)
end
end

def normalise_parameter_keys(input)
{}.tap do |output|
input.each do |key, value|
output[normalise_parameter_key(key)] = value
end
end
end

def normalise_parameter_key(s)
return s if s.is_a?(Symbol)
s.gsub(/([a-z])([A-Z])/, '\1_\2').downcase
end

end

end
24 changes: 24 additions & 0 deletions spec/stackup/stack_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,30 @@ def create_or_update

end

context "with :parameters in awscli form" do

before do
options[:parameters] = [{
"ParameterKey" => "foo",
"ParameterValue" => "bar"
}]
end

it "converts them to an Array" do
expected_parameters = [
{
"parameter_key" => "foo",
"parameter_value" => "bar"
}
]
create_or_update
expect(cf_client).to have_received(:create_stack) do |options|
expect(options[:parameters]).to eq(expected_parameters)
end
end

end

end

end
Expand Down

0 comments on commit cb20145

Please sign in to comment.