Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
72bce8e
removing redundant rstkr file
jercherng Jul 19, 2016
9891f85
adding function prototypes for configure function
jercherng Jul 19, 2016
2673047
add logic to configure method
jercherng Jul 20, 2016
9033406
moved Configure method to reflect placement in Action Dictionary as w…
jercherng Jul 20, 2016
155d80f
spell check 'regio' to 'region'
jercherng Jul 20, 2016
47e9ecd
adding quotes to label & fix whitespace issue
jercherng Jul 20, 2016
9bf6f57
put new_account_number outside loop scope
jercherng Jul 20, 2016
4480c64
increase verbosity of configure feature
jercherng Jul 20, 2016
d0238da
moved configure outside of switch statement to bypass need to login t…
jercherng Jul 20, 2016
b11627c
moved singleton method to Restacker from RestackerConfigure
jercherng Jul 20, 2016
13c9791
added load_config before calling configure to make sure file exists.
jercherng Jul 20, 2016
61e4200
move stdin and setter around
jercherng Jul 20, 2016
1efc27c
fixed logic, it was reversed.
jercherng Jul 20, 2016
0f816ce
added local scope for new account settings to allow loop to check for…
jercherng Jul 20, 2016
5f0fd67
added checking to role prefix to allow backslash
jercherng Jul 20, 2016
861e0a7
changed to use yaml::DBM#fetch() for backwards compatibility
jercherng Jul 21, 2016
0c13731
remove *, breaks functionality
jercherng Jul 21, 2016
bc5c632
change buggy gets(12).chomp to let regex on 315 deal with valid length
jercherng Jul 21, 2016
4d4a736
adding description for Restacker#configure() in restacker README
jercherng Jul 22, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 22 additions & 0 deletions source/bin/restacker
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down Expand Up @@ -116,6 +117,17 @@ 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.load_config(plane.to_sym)
Restacker.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
Expand Down Expand Up @@ -158,6 +170,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"
# RestackerConfig.rc_configure(options[:location])
when 'dump'
if options[:template]
# puts "Dumping stack parameters"
Expand Down
185 changes: 0 additions & 185 deletions source/bin/rstkr

This file was deleted.

2 changes: 1 addition & 1 deletion source/lib/base_stacker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
47 changes: 47 additions & 0 deletions source/lib/restacker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,51 @@ def self.dump_stack_params(options)
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.fetch(location, {}).fetch(:target)

new_account_number, new_role_name, new_role_prefix = ""

old_account_number = target[:account_number].to_s
# old_account_number[0...7] = "********"

print "Label [\"#{target[:label]}\"]: "
new_label = gets.chomp

loop do
print "Account Number [#{old_account_number}]: "

new_account_number = gets.chomp
break if (new_account_number =~ /\d{12,}/ || new_account_number.empty?)
end

loop do
print "Role Name [#{target[:role_name]}]: "
new_role_name = gets.chomp
break if (new_role_name =~ /[\w&&\S\-]/ || new_role_name.empty?)
end

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
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
end
end
end
3 changes: 0 additions & 3 deletions source/lib/restacker_config.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


class RestackerConfig
def self.load_config(plane)
begin
Expand All @@ -22,5 +20,4 @@ def self.load_config(plane)
end
config[plane]
end

end