class Kumogata::Client
Public Class Methods
new(options)
click to toggle source
# File lib/kumogata/client.rb, line 2 def initialize(options) @options = options @options = Hashie::Mash.new(@options) unless @options.kind_of?(Hashie::Mash) @cloud_formation = AWS::CloudFormation.new @outputs_filter = Kumogata::OutputsFilter.new(@options) @post_processing = Kumogata::PostProcessing.new(@options) end
Public Instance Methods
convert(path_or_url)
click to toggle source
# File lib/kumogata/client.rb, line 34 def convert(path_or_url) template = open_template(path_or_url) output_format = @options.output_format unless output_format output_format = case @options.format || guess_format(path_or_url) when :ruby then :json when :json then :ruby when :yaml then :json when :js then :json when :json5 then :json end end case output_format when :ruby devaluate_template(template).chomp.colorize_as(:ruby) when :json, :json5 JSON.pretty_generate(template).colorize_as(:json) when :yaml YAML.dump(template).colorize_as(:yaml) when :js '(' + JSON.pretty_generate(template).colorize_as(:json) + ')' when :coffee raise 'Output to CoffeeScript is not implemented' end end
create(path_or_url, stack_name = nil)
click to toggle source
# File lib/kumogata/client.rb, line 10 def create(path_or_url, stack_name = nil) validate_stack_name(stack_name) @options.delete_stack = false if stack_name template = open_template(path_or_url) update_deletion_policy(template) add_encryption_password(template) outputs = create_stack(template, stack_name) unless @options.detach? @outputs_filter.filter!(outputs) @post_processing.run(:create, outputs) outputs end end
delete(stack_name)
click to toggle source
# File lib/kumogata/client.rb, line 79 def delete(stack_name) validate_stack_name(stack_name) if @options.force? or agree("Are you sure you want to delete `#{stack_name}`? ".yellow) delete_stack(stack_name) end unless @options.detach? true end end
diff(path_or_url1, path_or_url2)
click to toggle source
# File lib/kumogata/client.rb, line 135 def diff(path_or_url1, path_or_url2) templates = [path_or_url1, path_or_url2].map do |path_or_url| template = nil if path_or_url =~ %r|\Astack://(.*)| stack_name = $1 || '' validate_stack_name(stack_name) template = export_template(stack_name) else template = open_template(path_or_url) end JSON.pretty_generate(template) end diff_opts = @options.ignore_all_space? ? '-uw' : '-u' opts = {:include_diff_info => true, :diff => diff_opts} diff = Diffy::Diff.new(*templates, opts).to_s diff.sub(/^(\e\[\d+m)?\-\-\-(\s+)(\S+)/m) { "#{$1}---#{$2}#{path_or_url1}"} .sub(/^(\e\[\d+m)?\+\+\+(\s+)(\S+)/m) { "#{$1}+++#{$2}#{path_or_url2}"} end
export(stack_name)
click to toggle source
# File lib/kumogata/client.rb, line 98 def export(stack_name) validate_stack_name(stack_name) template = export_template(stack_name) format = @options.format || :ruby case format when :ruby devaluate_template(template).chomp.colorize_as(:ruby) when :json JSON.pretty_generate(template).colorize_as(:json) else raise "Unknown format: #{format}" end end
list(stack_name = nil)
click to toggle source
# File lib/kumogata/client.rb, line 91 def list(stack_name = nil) validate_stack_name(stack_name) stacks = describe_stacks(stack_name) JSON.pretty_generate(stacks).colorize_as(:json) end
show_events(stack_name)
click to toggle source
# File lib/kumogata/client.rb, line 114 def show_events(stack_name) validate_stack_name(stack_name) events = describe_events(stack_name) JSON.pretty_generate(events).colorize_as(:json) end
show_outputs(stack_name)
click to toggle source
# File lib/kumogata/client.rb, line 121 def show_outputs(stack_name) validate_stack_name(stack_name) outputs = describe_outputs(stack_name) JSON.pretty_generate(outputs).colorize_as(:json) end
show_resources(stack_name)
click to toggle source
# File lib/kumogata/client.rb, line 128 def show_resources(stack_name) validate_stack_name(stack_name) resources = describe_resources(stack_name) JSON.pretty_generate(resources).colorize_as(:json) end
update(path_or_url, stack_name)
click to toggle source
# File lib/kumogata/client.rb, line 62 def update(path_or_url, stack_name) validate_stack_name(stack_name) @options.delete_stack = false template = open_template(path_or_url) update_deletion_policy(template, :update_metadate => true) add_encryption_password(template) outputs = update_stack(template, stack_name) unless @options.detach? @outputs_filter.filter!(outputs) @post_processing.run(:update, outputs) outputs end end
validate(path_or_url)
click to toggle source
# File lib/kumogata/client.rb, line 27 def validate(path_or_url) template = open_template(path_or_url) add_encryption_password_for_validation(template) validate_template(template) true end