-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from burtcorp/cuffdown-specs
Repair cuffdown with --region option
- Loading branch information
Showing
5 changed files
with
117 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,5 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'cuffsert/metadata' | ||
require 'cuffsert/rxcfclient' | ||
require 'yaml' | ||
require 'cuffdown/main' | ||
|
||
module CuffDown | ||
def self.parameters(stack) | ||
(stack[:parameters] || []).map do |param| | ||
{ | ||
'Name' => param[:parameter_key], | ||
'Value' => param[:parameter_value], | ||
} | ||
end | ||
end | ||
|
||
def self.tags(stack) | ||
(stack[:tags] || []).map do |param| | ||
{ | ||
'Name' => param[:key], | ||
'Value' => param[:value], | ||
} | ||
end | ||
end | ||
|
||
def self.dump(name, params, tags, output) | ||
result = { | ||
'Format' => 'v1', | ||
'Suffix' => name, | ||
'Parameters' => params, | ||
'Tags' => tags, | ||
} | ||
YAML.dump(result, output) | ||
end | ||
|
||
def self.run(args) | ||
meta = CuffSert::StackConfig.new | ||
meta.stackname = args[0] | ||
client = CuffSert::RxCFClient.new | ||
stack = client.find_stack_blocking(meta) | ||
unless stack | ||
STDERR.puts "No such stack #{meta.stackname}" | ||
exit(1) | ||
end | ||
stack = stack.to_h | ||
self.dump( | ||
stack[:stack_name], | ||
self.parameters(stack), | ||
self.tags(stack), | ||
STDOUT | ||
) | ||
end | ||
end | ||
|
||
CuffDown.run(ARGV) | ||
CuffDown.run(ARGV, STDOUT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
require 'cuffbase' | ||
require 'cuffsert/metadata' | ||
require 'cuffsert/rxcfclient' | ||
require 'optparse' | ||
require 'yaml' | ||
|
||
module CuffDown | ||
def self.parse_cli_args(argv) | ||
args = {} | ||
parser = OptionParser.new do |opts| | ||
opts.banner = 'Output CuffSert-formatted metadata from an existing stack.' | ||
opts.separator('') | ||
opts.separator('Usage: cuffdown stack-name') | ||
CuffBase.shared_cli_args(opts, args) | ||
end | ||
stackname, _ = parser.parse(argv) | ||
args[:stackname] = stackname | ||
args | ||
end | ||
|
||
def self.parameters(stack) | ||
(stack[:parameters] || []).map do |param| | ||
{ | ||
'Name' => param[:parameter_key], | ||
'Value' => param[:parameter_value], | ||
} | ||
end | ||
end | ||
|
||
def self.tags(stack) | ||
(stack[:tags] || []).map do |param| | ||
{ | ||
'Name' => param[:key], | ||
'Value' => param[:value], | ||
} | ||
end | ||
end | ||
|
||
def self.dump(name, params, tags, output) | ||
result = { | ||
'Format' => 'v1', | ||
'Suffix' => name, | ||
'Parameters' => params, | ||
'Tags' => tags, | ||
} | ||
YAML.dump(result, output) | ||
end | ||
|
||
def self.run(argv, output) | ||
cli_args = self.parse_cli_args(argv) | ||
meta = CuffSert::StackConfig.new | ||
meta.stackname = cli_args[:stackname] | ||
client = CuffSert::RxCFClient.new(cli_args[:aws_region]) | ||
stack = client.find_stack_blocking(meta) | ||
unless stack | ||
STDERR.puts "No such stack #{meta.stackname}" | ||
exit(1) | ||
end | ||
stack = stack.to_h | ||
self.dump( | ||
stack[:stack_name], | ||
self.parameters(stack), | ||
self.tags(stack), | ||
output | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require 'cuffdown/main' | ||
require 'spec_helpers' | ||
|
||
describe CuffDown do | ||
include_context 'stack states' | ||
|
||
describe '.run' do | ||
let(:cli_args) { ['some-stack'] } | ||
let(:output) { StringIO.new } | ||
let :stack_complete do | ||
super().merge( | ||
:parameters => [ | ||
{:parameter_key => 'p1', :parameter_value => 'v1'} | ||
] | ||
) | ||
end | ||
|
||
let(:cfmock) { double(:cfmock) } | ||
|
||
before do | ||
allow(Aws::CloudFormation::Client).to receive(:new).and_return(cfmock) | ||
allow(cfmock).to receive(:describe_stacks).and_return(stack_complete_describe) | ||
CuffDown.run(cli_args, output) | ||
end | ||
|
||
it 'outputs parameter values for the stack' do | ||
expect(output.string).to match(/Name: p1.*Value: v1/m) | ||
end | ||
|
||
context 'when invoked with an explicit region' do | ||
let(:cli_args) { ['--region', 'rp-north-1', 'stack-name'] } | ||
|
||
it 'passes region to the ClodFormation client' do | ||
expect(Aws::CloudFormation::Client).to have_received(:new).with(hash_including(:region => 'rp-north-1')) | ||
end | ||
end | ||
end | ||
end |