Skip to content

Commit 5670232

Browse files
authored
Merge pull request #3 from jercherng/feature-configure
Configure feature
2 parents 32e2227 + 4d4a736 commit 5670232

File tree

6 files changed

+71
-189
lines changed

6 files changed

+71
-189
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ ACTIONS
3030
deploy Deploys a new stack
3131
migrate Migrates from green to blue stack
3232
remove Removes the given deployment
33+
configure Configure the target account in the restacker.yml file
3334
dump Dumps the default configuration for a given template or module
3435
console Opens the AWS Console
3536

source/bin/restacker

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ ACTIONS = {
1212
deploy: 'Deploys a new stack',
1313
migrate: 'Migrates from green to blue stack',
1414
remove: 'Removes the given deployment',
15+
configure: 'Configure the target account in the restacker.yml file',
1516
dump: 'Dumps the default configuration for a given template or module',
1617
console: 'Opens the AWS Console'
1718
}
@@ -116,6 +117,17 @@ begin
116117
puts(VERSION) || exit(0) if options[:version]
117118
usage("Please specify an ACTION") && exit(0) if action.nil?
118119

120+
if action == 'configure'
121+
plane = options[:location] ? options[:location] : DEFAULT_PLANE
122+
if !plane
123+
puts "Location not specified, plane is set to default: [#{DEFAULT_PLANE}]"
124+
end
125+
puts "Configuring target plane [#{plane}]: "
126+
RestackerConfig.load_config(plane.to_sym)
127+
Restacker.configure(plane.to_sym)
128+
exit(0)
129+
end
130+
119131
if ACTIONS.keys.push(:aws).include?(action.to_sym)
120132
restacker = Restacker.new(options.to_h) unless ['dump'].include?(action)
121133
case action
@@ -158,6 +170,16 @@ begin
158170
else
159171
usage "Please specify a stack name (-n) to remove"
160172
end
173+
# when 'configure'
174+
# plane = ""
175+
# if !options[:location]
176+
# puts "Location not specified, default plane #{DEFAULT_PLANE} used."
177+
# plane = DEFAULT_PLANE
178+
# else
179+
# plane = options[:location]
180+
# end
181+
# puts "Configuring target account for plane [#{plane}]:\n"
182+
# RestackerConfig.rc_configure(options[:location])
161183
when 'dump'
162184
if options[:template]
163185
# puts "Dumping stack parameters"

source/bin/rstkr

Lines changed: 0 additions & 185 deletions
This file was deleted.

source/lib/base_stacker.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class BaseStacker
2121
def initialize(options)
2222
@plane = options[:location] ? options[:location].to_sym : DEFAULT_PLANE
2323
config = RestackerConfig.load_config(@plane)
24-
# use default regio if not passed in from cli
24+
# use default region if not passed in from cli
2525
config[:region] = options[:region] if options[:region]
2626
options[:region] = config[:region] unless options[:region]
2727
@cf, @creds = Auth.login(options, config, @plane)

source/lib/restacker.rb

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,4 +290,51 @@ def self.dump_stack_params(options)
290290
end
291291
end
292292
end
293+
294+
def self.configure(location)
295+
puts "config file location: #{CONFIG_FILE}"
296+
config = YAML.load_file(CONFIG_FILE)
297+
if !config
298+
puts "Make sure your ~/.restacker/restacker.yml file is configured. \n
299+
See source/restacker-sample.yml for example."
300+
exit(1)
301+
end
302+
target = config.fetch(location, {}).fetch(:target)
303+
304+
new_account_number, new_role_name, new_role_prefix = ""
305+
306+
old_account_number = target[:account_number].to_s
307+
# old_account_number[0...7] = "********"
308+
309+
print "Label [\"#{target[:label]}\"]: "
310+
new_label = gets.chomp
311+
312+
loop do
313+
print "Account Number [#{old_account_number}]: "
314+
315+
new_account_number = gets.chomp
316+
break if (new_account_number =~ /\d{12,}/ || new_account_number.empty?)
317+
end
318+
319+
loop do
320+
print "Role Name [#{target[:role_name]}]: "
321+
new_role_name = gets.chomp
322+
break if (new_role_name =~ /[\w&&\S\-]/ || new_role_name.empty?)
323+
end
324+
325+
loop do
326+
print "Role Prefix [#{target[:role_prefix]}]: "
327+
new_role_prefix = gets.chomp
328+
break if (new_role_prefix =~ /[\w&&\S\-\/]/ || new_role_prefix.empty?)
329+
end
330+
331+
target[:label] = new_label.empty? ? target[:label] : new_label
332+
target[:account_number] = new_account_number.empty? ? target[:account_number] : new_account_number
333+
target[:role_name] = new_role_name.empty? ? target[:role_name] : new_role_name
334+
target[:role_prefix] = new_role_prefix.empty? ? target[:role_prefix] : new_role_prefix
335+
336+
File.open(CONFIG_FILE, 'w') do |f|
337+
f.write config.to_yaml
338+
end
339+
end
293340
end

source/lib/restacker_config.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
class RestackerConfig
42
def self.load_config(plane)
53
begin
@@ -22,5 +20,4 @@ def self.load_config(plane)
2220
end
2321
config[plane]
2422
end
25-
2623
end

0 commit comments

Comments
 (0)