From 72bce8eb42e9146ea0858c7d720c27b4d9c37c96 Mon Sep 17 00:00:00 2001 From: AxialLP7 Date: Tue, 19 Jul 2016 16:16:49 -0700 Subject: [PATCH 01/19] removing redundant rstkr file --- source/bin/rstkr | 185 ----------------------------------------------- 1 file changed, 185 deletions(-) delete mode 100755 source/bin/rstkr diff --git a/source/bin/rstkr b/source/bin/rstkr deleted file mode 100755 index 6b0450f..0000000 --- a/source/bin/rstkr +++ /dev/null @@ -1,185 +0,0 @@ -#!/usr/bin/env ruby -require 'optparse' -require 'ostruct' -require_relative '../lib/restacker' -require_relative '../lib/restacker_config' -require_relative '../lib/aws_cli' - -ACTIONS = { - list: 'Lists current stack names', - describe: 'Describes a stack parameters and template', - restack: 'Restacks a given deployment', - deploy: 'Deploys a new stack', - migrate: 'Migrates from green to blue stack', - remove: 'Removes the given deployment', - dump: 'Dumps the default configuration for a given template or module', - console: 'Opens the AWS Console' -} -ACTIONS_HELP = "ACTIONS\n\n" + ACTIONS.to_yaml.sub("---\n", '').gsub(': ', "\t").gsub(':', " ") -NOTES = "Notes: - - If no template file path is provided when restacking #{File.basename($0)} will use the same - template as if currently deployed. - - Deployed stack name will be in the form of NAME-DATE using today's date" - -class Parser - def self.parse(options) - opts = OpenStruct.new - - opt_parser = OptionParser.new do |o| - o.banner = "Usage: #{File.basename($0)} [ACTION] [OPTONS]\n\n#{ACTIONS_HELP}\n\nOPTIONS\n\n" - - o.on('-c PROFILE', '--credentials=PROFILE', 'Specify the AWS profile credential (~/.aws/config) to use') do |profile| - opts[:profile] = profile - end - - o.on('-d', '--debug', 'Show stack traces') do |debug| - opts[:debug] = debug - end - - o.on('-e PARAMS', '--environment-params=PARAMS', 'Parameters to add to the instance environment (/etc/profile.d) in the form of', 'k1=v1,k2=v2. E.g., -p SCORING_URL=https://scoring...') do |params| - opts[:env_params] = params - end - - o.on("-h", "--help", "Prints these wonderful lines...") do - puts o - puts "\n#{NOTES}" - exit - end - - o.on('-l LOCATION', '--location=LOCATION', 'Where to deploy, ksp, kvp, kcp...') do |location| - opts[:location] = location - end - - o.on('-m MODULE', '--migrate-module=MODULE', 'Migration module to execute') do |_module| - opts[:module] = _module - end - - o.on('-n NAME', '--name=NAME', 'Stack prefix stack name (alphanumeric with dashes)') do |name| - opts[:name] = name - end - - o.on('-o OPTIONS', '--migrate-options=OPTIONS', 'Options required by migration module to migrate from green to', 'blue stack in the form of k1=v1,k2=v2. E.g., -p EIP=1.2.3.4') do |options| - opts[:options] = options - end - - o.on('-p PARAMS', '--params=PARAMS', 'Parameters to override current stack parameters in the form of', 'k1=v1,k2=v2. E.g., -p AmiId=ami-a4jd7928') do |params| - opts[:params] = params - end - - o.on('-P FILE', '--parameters-file=FILE', 'YAML formated parameters file (as generated by the dump command) containing parameters to override stack parameters') do |file| - opts[:params_file] = file - end - - o.on('-r REGION', '--region=REGION', "The region where the stack to be restacked exists") do |region| - opts[:region] = region - end - - o.on('-t PATH', '--template=PATH', 'Template file path to override current stack template') do |template| - opts[:template] = template - end - - o.on('-u USERNAME', '--username=USERNAME', 'Your username, defaults to $USER') do |username| - opts[:username] = username - end - - o.on('-v', '--verbose', 'Show more output') do |verbose| - opts[:verbose] = verbose - end - - o.on('-V', '--version', 'Display the version') do |version| - opts[:version] = version - end - end - - begin - return opts, opt_parser.parse!(options) - rescue OptionParser::InvalidOption => e - puts e.message - exit(1) - end - end -end - -def usage(msg) - puts msg, "\n" - Parser.parse %w[--help] -end - -# parse options -options, unparsed = Parser.parse(ARGV) - -# set the username to $USER if not specified -options[:username] = ENV['USER'] if options[:username].nil? - -begin - action = unparsed.pop - puts(VERSION) || exit(0) if options[:version] - usage("Please specify an ACTION") && exit(0) if action.nil? - - if ACTIONS.keys.push(:aws).include?(action.to_sym) - restacker = Restacker.new(options.to_h) unless ['dump'].include?(action) - case action - when 'list' - puts "Listing stacks" - restacker.list_stacks - when 'desc', 'describe' - if options[:name] - puts "Describing #{options[:name]}" - restacker.describe_stack(options[:name]) - else - usage "Please specify a stack name (-n) to describe" - end - when 'restack' - if options[:name] - puts "Restacking #{options[:name]}" - restacker.restack_by_name(options[:name]) - puts "Now run migrate followed by remove" - else - usage "Please specify a stack name (-n) to restack" - end - when 'deploy' - if options[:template] && options[:name] - restacker.deploy_stack(options[:template], options[:name]) - else - usage "Please specify stack name (-n) and template (-t) to deploy" - end - when 'migrate' - if options[:name] && options[:options] && options[:module] - puts "Migrating #{options[:name]}, #{options[:options]}, #{options[:module]}" - # restacker = Restacker.new(options.to_h) - # restacker.restack_by_name(stack_name) - else - usage "Please specify a stack name (-n), options (-o) and module (-m) to migrate" - end - when 'remove' - if options[:name] - puts "Removing stack" - restacker.delete_stack(options[:name]) - else - usage "Please specify a stack name (-n) to remove" - end - when 'dump' - if options[:template] - # puts "Dumping stack parameters" - Restacker.dump_stack_params(options) - else - usage "Please specify a stack template (-t) or module (-m)" - end - when 'console' - AwsCli.new(options).console(options) - when 'aws' - AwsCli.new(options).cmd(options[:params], options[:debug]) - end - else - usage "Unknown ACTION: #{action}" - end -rescue => e - puts options[:debug] - if options[:debug] - puts e.class - puts e.message - usage $@ - else - usage e.message - end -end From 9891f8507396416108792ffc34637ccb298ce159 Mon Sep 17 00:00:00 2001 From: AxialLP7 Date: Tue, 19 Jul 2016 16:42:20 -0700 Subject: [PATCH 02/19] adding function prototypes for configure function --- source/bin/restacker | 3 +++ source/lib/restacker.rb | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/source/bin/restacker b/source/bin/restacker index 6b0450f..766794b 100755 --- a/source/bin/restacker +++ b/source/bin/restacker @@ -12,6 +12,7 @@ ACTIONS = { deploy: 'Deploys a new stack', migrate: 'Migrates from green to blue stack', remove: 'Removes the given deployment', + configure: 'Configure the target account in the restacker.yml file', dump: 'Dumps the default configuration for a given template or module', console: 'Opens the AWS Console' } @@ -165,6 +166,8 @@ begin else usage "Please specify a stack template (-t) or module (-m)" end + when 'configure' + restacker.configure when 'console' AwsCli.new(options).console(options) when 'aws' diff --git a/source/lib/restacker.rb b/source/lib/restacker.rb index 5452f0c..a9a824a 100644 --- a/source/lib/restacker.rb +++ b/source/lib/restacker.rb @@ -272,6 +272,10 @@ def deploy_stack(template, name) create_stack(template, name, get_merged_params(template_param_keys)) end + def configure() + + end + def self.dump_stack_params(options) begin template = JSON.parse(File.open(options[:template]).read) From 26730473b979d754f9207f22607e820f0192a64e Mon Sep 17 00:00:00 2001 From: AxialLP7 Date: Tue, 19 Jul 2016 17:15:27 -0700 Subject: [PATCH 03/19] add logic to configure method --- source/lib/restacker.rb | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/source/lib/restacker.rb b/source/lib/restacker.rb index a9a824a..cd8ab76 100644 --- a/source/lib/restacker.rb +++ b/source/lib/restacker.rb @@ -273,7 +273,33 @@ def deploy_stack(template, name) end def configure() - + config = YAML.load CONFIG_FILE + target = config.dig(config.keys[0], :target) + + print "Label [#{target[:label]}]:" + target[:label] = gets.chomp() + + loop do + old_account_number = target[:account_number].to_s + old_account_number[0...7] = '********' + + print "Account Number [#{old_account_number}]: " + + new_account_number = gets.chomp + break if new_account_number =~ /\d/ + end + + target[:account_number] = new_account_number + + print "Role Name [#{target[:role_name]}]" + target[:role_name] = gets.chomp + + print "Role Prefix [#{target[:role_prefix]}]" + target[:role_prefix] = gets.chomp + + File.open(CONFIG_FILE, 'w') do |h| + h.write config.to_yaml + end end def self.dump_stack_params(options) From 90334060c6ff6e908d63cffdc72e19d0654d2214 Mon Sep 17 00:00:00 2001 From: AxialLP7 Date: Tue, 19 Jul 2016 18:49:42 -0700 Subject: [PATCH 04/19] moved Configure method to reflect placement in Action Dictionary as well as description --- source/bin/restacker | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/bin/restacker b/source/bin/restacker index 766794b..8f1dc53 100755 --- a/source/bin/restacker +++ b/source/bin/restacker @@ -159,6 +159,9 @@ begin else usage "Please specify a stack name (-n) to remove" end + when 'configure' + puts "Configuring target account" + restacker.configure when 'dump' if options[:template] # puts "Dumping stack parameters" @@ -166,8 +169,6 @@ begin else usage "Please specify a stack template (-t) or module (-m)" end - when 'configure' - restacker.configure when 'console' AwsCli.new(options).console(options) when 'aws' From 155d80f94aa5f5fbd94c0ab2bad1ea33274d7fe7 Mon Sep 17 00:00:00 2001 From: AxialLP7 Date: Tue, 19 Jul 2016 18:50:12 -0700 Subject: [PATCH 05/19] spell check 'regio' to 'region' --- source/lib/base_stacker.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/lib/base_stacker.rb b/source/lib/base_stacker.rb index 2a2f838..fc171fb 100644 --- a/source/lib/base_stacker.rb +++ b/source/lib/base_stacker.rb @@ -21,7 +21,7 @@ class BaseStacker def initialize(options) @plane = options[:location] ? options[:location].to_sym : DEFAULT_PLANE config = RestackerConfig.load_config(@plane) - # use default regio if not passed in from cli + # use default region if not passed in from cli config[:region] = options[:region] if options[:region] options[:region] = config[:region] unless options[:region] @cf, @creds = Auth.login(options, config, @plane) From 47e9ecd7af8b60df39bd34e570c78d0fdebdde59 Mon Sep 17 00:00:00 2001 From: AxialLP7 Date: Tue, 19 Jul 2016 18:52:08 -0700 Subject: [PATCH 06/19] adding quotes to label & fix whitespace issue --- source/lib/restacker.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/lib/restacker.rb b/source/lib/restacker.rb index cd8ab76..24bfb86 100644 --- a/source/lib/restacker.rb +++ b/source/lib/restacker.rb @@ -276,7 +276,7 @@ def configure() config = YAML.load CONFIG_FILE target = config.dig(config.keys[0], :target) - print "Label [#{target[:label]}]:" + print "Label [\"#{target[:label]}\"]: " target[:label] = gets.chomp() loop do @@ -291,14 +291,14 @@ def configure() target[:account_number] = new_account_number - print "Role Name [#{target[:role_name]}]" + print "Role Name [#{target[:role_name]}]: " target[:role_name] = gets.chomp - print "Role Prefix [#{target[:role_prefix]}]" + print "Role Prefix [#{target[:role_prefix]}]: " target[:role_prefix] = gets.chomp File.open(CONFIG_FILE, 'w') do |h| - h.write config.to_yaml + h.write configuration_file.to_yaml end end From 9bf6f57a2545e5c8521098546576bb0beaf30de7 Mon Sep 17 00:00:00 2001 From: AxialLP7 Date: Tue, 19 Jul 2016 18:55:07 -0700 Subject: [PATCH 07/19] put new_account_number outside loop scope --- source/lib/restacker.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/source/lib/restacker.rb b/source/lib/restacker.rb index 24bfb86..40846be 100644 --- a/source/lib/restacker.rb +++ b/source/lib/restacker.rb @@ -276,13 +276,15 @@ def configure() config = YAML.load CONFIG_FILE target = config.dig(config.keys[0], :target) + new_account_number = "" + + old_account_number = target[:account_number].to_s + old_account_number[0...7] = "********" + print "Label [\"#{target[:label]}\"]: " - target[:label] = gets.chomp() + target[:label] = gets.chomp loop do - old_account_number = target[:account_number].to_s - old_account_number[0...7] = '********' - print "Account Number [#{old_account_number}]: " new_account_number = gets.chomp From 4480c64b872d25c46770e2aba48b667fd912a07e Mon Sep 17 00:00:00 2001 From: AxialLP7 Date: Tue, 19 Jul 2016 19:13:08 -0700 Subject: [PATCH 08/19] increase verbosity of configure feature --- source/bin/restacker | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/source/bin/restacker b/source/bin/restacker index 8f1dc53..b297ddd 100755 --- a/source/bin/restacker +++ b/source/bin/restacker @@ -160,7 +160,14 @@ begin usage "Please specify a stack name (-n) to remove" end when 'configure' - puts "Configuring target account" + plane = "" + if !options[:location] + puts "Location not specified, default plane #{DEFAULT_PLANE} used." + plane = DEFAULT_PLANE + else + plane = options[:location] + end + puts "Configuring target account for plane [#{plane}]:\n" restacker.configure when 'dump' if options[:template] From d0238da8818f0754bedc5e06d947956836210f5d Mon Sep 17 00:00:00 2001 From: AxialLP7 Date: Wed, 20 Jul 2016 14:51:03 -0700 Subject: [PATCH 09/19] moved configure outside of switch statement to bypass need to login to configure file --- source/bin/restacker | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/source/bin/restacker b/source/bin/restacker index b297ddd..ed35dad 100755 --- a/source/bin/restacker +++ b/source/bin/restacker @@ -117,6 +117,16 @@ begin puts(VERSION) || exit(0) if options[:version] usage("Please specify an ACTION") && exit(0) if action.nil? + if action == 'configure' + plane = options[:location] ? options[:location] : DEFAULT_PLANE + if !plane + puts "Location not specified, plane is set to default: [#{DEFAULT_PLANE}]" + end + puts "Configuring target plane [#{plane}]: " + RestackerConfig.rc_configure(plane.to_sym) + exit(0) + end + if ACTIONS.keys.push(:aws).include?(action.to_sym) restacker = Restacker.new(options.to_h) unless ['dump'].include?(action) case action @@ -159,16 +169,16 @@ begin else usage "Please specify a stack name (-n) to remove" end - when 'configure' - plane = "" - if !options[:location] - puts "Location not specified, default plane #{DEFAULT_PLANE} used." - plane = DEFAULT_PLANE - else - plane = options[:location] - end - puts "Configuring target account for plane [#{plane}]:\n" - restacker.configure + # when 'configure' + # plane = "" + # if !options[:location] + # puts "Location not specified, default plane #{DEFAULT_PLANE} used." + # plane = DEFAULT_PLANE + # else + # plane = options[:location] + # end + # puts "Configuring target account for plane [#{plane}]:\n" + # RestackerConfig.rc_configure(options[:location]) when 'dump' if options[:template] # puts "Dumping stack parameters" From b11627c9e4f44206c180f5a11715fc236d4686d9 Mon Sep 17 00:00:00 2001 From: AxialLP7 Date: Wed, 20 Jul 2016 15:33:40 -0700 Subject: [PATCH 10/19] moved singleton method to Restacker from RestackerConfigure --- source/bin/restacker | 3 +- source/lib/restacker.rb | 62 +++++++++++++++++++--------------- source/lib/restacker_config.rb | 3 -- 3 files changed, 36 insertions(+), 32 deletions(-) diff --git a/source/bin/restacker b/source/bin/restacker index ed35dad..5a166b5 100755 --- a/source/bin/restacker +++ b/source/bin/restacker @@ -123,7 +123,8 @@ begin puts "Location not specified, plane is set to default: [#{DEFAULT_PLANE}]" end puts "Configuring target plane [#{plane}]: " - RestackerConfig.rc_configure(plane.to_sym) + + Restacker.configure(plane.to_sym) exit(0) end diff --git a/source/lib/restacker.rb b/source/lib/restacker.rb index 40846be..e738207 100644 --- a/source/lib/restacker.rb +++ b/source/lib/restacker.rb @@ -272,9 +272,33 @@ def deploy_stack(template, name) create_stack(template, name, get_merged_params(template_param_keys)) end - def configure() - config = YAML.load CONFIG_FILE - target = config.dig(config.keys[0], :target) + def self.dump_stack_params(options) + begin + template = JSON.parse(File.open(options[:template]).read) + params = {} + template["Parameters"].each do |key, value| + params[key] = value['Default'] + end + puts params.to_yaml + rescue JSON::ParserError => e + puts "Error parsing #{options[:template]}" + if options[:verbose] + $stderr.puts e.message + else + $stderr.puts e.message.each_line.first + end + end + end + + def self.configure(location) + puts "config file location: #{CONFIG_FILE}" + config = YAML.load_file(CONFIG_FILE) + if !config + puts "Make sure your ~/.restacker/restacker.yml file is configured. \n + See source/restacker-sample.yml for example." + exit(1) + end + target = config.dig(location, :target) new_account_number = "" @@ -287,38 +311,20 @@ def configure() loop do print "Account Number [#{old_account_number}]: " - new_account_number = gets.chomp - break if new_account_number =~ /\d/ + new_account_number = gets(12).chomp + break if (new_account_number =~ /\d/ || new_account_number.empty?) + end + if !new_account_number.empty? + target[:account_number] = new_account_number end - - target[:account_number] = new_account_number - print "Role Name [#{target[:role_name]}]: " target[:role_name] = gets.chomp print "Role Prefix [#{target[:role_prefix]}]: " target[:role_prefix] = gets.chomp - File.open(CONFIG_FILE, 'w') do |h| - h.write configuration_file.to_yaml - end - end - - def self.dump_stack_params(options) - begin - template = JSON.parse(File.open(options[:template]).read) - params = {} - template["Parameters"].each do |key, value| - params[key] = value['Default'] - end - puts params.to_yaml - rescue JSON::ParserError => e - puts "Error parsing #{options[:template]}" - if options[:verbose] - $stderr.puts e.message - else - $stderr.puts e.message.each_line.first - end + File.open(CONFIG_FILE, 'w') do |f| + f.write config.to_yaml end end end diff --git a/source/lib/restacker_config.rb b/source/lib/restacker_config.rb index e8ce24d..0dc40c7 100644 --- a/source/lib/restacker_config.rb +++ b/source/lib/restacker_config.rb @@ -1,5 +1,3 @@ - - class RestackerConfig def self.load_config(plane) begin @@ -22,5 +20,4 @@ def self.load_config(plane) end config[plane] end - end From 13c9791e0288e0da934a264ce4c33bd9e5ed5c34 Mon Sep 17 00:00:00 2001 From: AxialLP7 Date: Wed, 20 Jul 2016 15:34:41 -0700 Subject: [PATCH 11/19] added load_config before calling configure to make sure file exists. --- source/bin/restacker | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/bin/restacker b/source/bin/restacker index 5a166b5..8ef5863 100755 --- a/source/bin/restacker +++ b/source/bin/restacker @@ -123,7 +123,7 @@ begin puts "Location not specified, plane is set to default: [#{DEFAULT_PLANE}]" end puts "Configuring target plane [#{plane}]: " - + RestackerConfig.load_config(plane.to_sym) Restacker.configure(plane.to_sym) exit(0) end From 61e42006730b77e44f4f625f6ab3d47957b1a770 Mon Sep 17 00:00:00 2001 From: AxialLP7 Date: Wed, 20 Jul 2016 15:42:11 -0700 Subject: [PATCH 12/19] move stdin and setter around --- source/lib/restacker.rb | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/source/lib/restacker.rb b/source/lib/restacker.rb index e738207..b07a07f 100644 --- a/source/lib/restacker.rb +++ b/source/lib/restacker.rb @@ -306,7 +306,7 @@ def self.configure(location) old_account_number[0...7] = "********" print "Label [\"#{target[:label]}\"]: " - target[:label] = gets.chomp + new_label = gets.chomp loop do print "Account Number [#{old_account_number}]: " @@ -314,14 +314,19 @@ def self.configure(location) new_account_number = gets(12).chomp break if (new_account_number =~ /\d/ || new_account_number.empty?) end - if !new_account_number.empty? - target[:account_number] = new_account_number - end - print "Role Name [#{target[:role_name]}]: " - target[:role_name] = gets.chomp + # loop do + print "Role Name [#{target[:role_name]}]: " + new_role_name = gets.chomp + # break if (new_role_name =~ /[\w\-]/ || new_role_name.empty?) + # end print "Role Prefix [#{target[:role_prefix]}]: " - target[:role_prefix] = gets.chomp + new_role_prefix = gets.chomp + + target[:label] = new_label ? new_label : target[:label] + target[:account_number] = new_account_number ? new_account_number : target[:account_number] + target[:role_name] = new_role_name ? new_role_name : target[:role_name] + target[:role_prefix] = new_role_prefix ? new_role_prefix : target[:role_prefix] File.open(CONFIG_FILE, 'w') do |f| f.write config.to_yaml From 1efc27cec4061c0d1b41b784cac1ee240389d7e2 Mon Sep 17 00:00:00 2001 From: AxialLP7 Date: Wed, 20 Jul 2016 15:46:17 -0700 Subject: [PATCH 13/19] fixed logic, it was reversed. --- source/lib/restacker.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/lib/restacker.rb b/source/lib/restacker.rb index b07a07f..dd11b07 100644 --- a/source/lib/restacker.rb +++ b/source/lib/restacker.rb @@ -323,10 +323,10 @@ def self.configure(location) print "Role Prefix [#{target[:role_prefix]}]: " new_role_prefix = gets.chomp - target[:label] = new_label ? new_label : target[:label] - target[:account_number] = new_account_number ? new_account_number : target[:account_number] - target[:role_name] = new_role_name ? new_role_name : target[:role_name] - target[:role_prefix] = new_role_prefix ? new_role_prefix : target[:role_prefix] + target[:label] = new_label.empty? ? target[:label] : new_label + target[:account_number] = new_account_number.empty? ? target[:account_number] : new_account_number + target[:role_name] = new_role_name.empty? ? target[:role_name] : new_role_name + target[:role_prefix] = new_role_prefix.empty? ? target[:role_prefix] : new_role_prefix File.open(CONFIG_FILE, 'w') do |f| f.write config.to_yaml From 0f816cef58c7b67d98374085165a77b05bced009 Mon Sep 17 00:00:00 2001 From: AxialLP7 Date: Wed, 20 Jul 2016 15:58:28 -0700 Subject: [PATCH 14/19] added local scope for new account settings to allow loop to check for valid input --- source/lib/restacker.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/lib/restacker.rb b/source/lib/restacker.rb index dd11b07..a3cd1ea 100644 --- a/source/lib/restacker.rb +++ b/source/lib/restacker.rb @@ -300,7 +300,7 @@ def self.configure(location) end target = config.dig(location, :target) - new_account_number = "" + new_account_number, new_role_name, new_role_prefix = "" old_account_number = target[:account_number].to_s old_account_number[0...7] = "********" @@ -315,11 +315,11 @@ def self.configure(location) break if (new_account_number =~ /\d/ || new_account_number.empty?) end - # loop do + loop do print "Role Name [#{target[:role_name]}]: " new_role_name = gets.chomp - # break if (new_role_name =~ /[\w\-]/ || new_role_name.empty?) - # end + break if (new_role_name =~ /[\w&&\S\-]/ || new_role_name.empty?) + end print "Role Prefix [#{target[:role_prefix]}]: " new_role_prefix = gets.chomp From 5f0fd67f21fff6ed0292408642dc5b9df17986ae Mon Sep 17 00:00:00 2001 From: AxialLP7 Date: Wed, 20 Jul 2016 16:00:37 -0700 Subject: [PATCH 15/19] added checking to role prefix to allow backslash --- source/lib/restacker.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/source/lib/restacker.rb b/source/lib/restacker.rb index a3cd1ea..8088f53 100644 --- a/source/lib/restacker.rb +++ b/source/lib/restacker.rb @@ -320,8 +320,12 @@ def self.configure(location) new_role_name = gets.chomp break if (new_role_name =~ /[\w&&\S\-]/ || new_role_name.empty?) end - print "Role Prefix [#{target[:role_prefix]}]: " - new_role_prefix = gets.chomp + + loop do + print "Role Prefix [#{target[:role_prefix]}]: " + new_role_prefix = gets.chomp + break if (new_role_prefix =~ /[\w&&\S\-\/]/ || new_role_prefix.empty?) + end target[:label] = new_label.empty? ? target[:label] : new_label target[:account_number] = new_account_number.empty? ? target[:account_number] : new_account_number From 861e0a7387bb242784494a713b5b5deceec75ee6 Mon Sep 17 00:00:00 2001 From: AxialLP7 Date: Wed, 20 Jul 2016 22:25:10 -0700 Subject: [PATCH 16/19] changed to use yaml::DBM#fetch() for backwards compatibility --- source/lib/restacker.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/lib/restacker.rb b/source/lib/restacker.rb index 8088f53..ebf090b 100644 --- a/source/lib/restacker.rb +++ b/source/lib/restacker.rb @@ -298,7 +298,7 @@ def self.configure(location) See source/restacker-sample.yml for example." exit(1) end - target = config.dig(location, :target) + target = config.fetch(location, {}).fetch(:target) new_account_number, new_role_name, new_role_prefix = "" From 0c13731aa2edacf96fd5f219f38e8572a4eb1539 Mon Sep 17 00:00:00 2001 From: AxialLP7 Date: Wed, 20 Jul 2016 23:57:00 -0700 Subject: [PATCH 17/19] remove *, breaks functionality --- source/lib/restacker.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/lib/restacker.rb b/source/lib/restacker.rb index ebf090b..908dfea 100644 --- a/source/lib/restacker.rb +++ b/source/lib/restacker.rb @@ -303,7 +303,7 @@ def self.configure(location) new_account_number, new_role_name, new_role_prefix = "" old_account_number = target[:account_number].to_s - old_account_number[0...7] = "********" + # old_account_number[0...7] = "********" print "Label [\"#{target[:label]}\"]: " new_label = gets.chomp From bc5c632fbc47dc863fafc61711854e9cfe50d780 Mon Sep 17 00:00:00 2001 From: AxialLP7 Date: Wed, 20 Jul 2016 23:57:44 -0700 Subject: [PATCH 18/19] change buggy gets(12).chomp to let regex on 315 deal with valid length --- source/lib/restacker.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/lib/restacker.rb b/source/lib/restacker.rb index 908dfea..512b85c 100644 --- a/source/lib/restacker.rb +++ b/source/lib/restacker.rb @@ -311,8 +311,8 @@ def self.configure(location) loop do print "Account Number [#{old_account_number}]: " - new_account_number = gets(12).chomp - break if (new_account_number =~ /\d/ || new_account_number.empty?) + new_account_number = gets.chomp + break if (new_account_number =~ /\d{12,}/ || new_account_number.empty?) end loop do From 4d4a7366dea552a202d6e19624ee7ea5b1b3aa1d Mon Sep 17 00:00:00 2001 From: AxialLP7 Date: Thu, 21 Jul 2016 18:15:04 -0700 Subject: [PATCH 19/19] adding description for Restacker#configure() in restacker README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 978db45..5616a9b 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ ACTIONS deploy Deploys a new stack migrate Migrates from green to blue stack remove Removes the given deployment + configure Configure the target account in the restacker.yml file dump Dumps the default configuration for a given template or module console Opens the AWS Console