@@ -13,7 +13,7 @@ def self.get_plane(options)
1313 if options [ :location ]
1414 plane = options [ :location ]
1515 else
16- plane = find_default_plane ( )
16+ plane = default_plane
1717 end
1818 plane . to_sym
1919 end
@@ -66,15 +66,44 @@ def self.latest_amis(rhel=nil)
6666 latest_amis
6767 end
6868
69- private
69+ def self . target_config ( config )
70+ target_config = config . fetch ( :target )
71+ target = { }
72+ target [ :label ] = target_config . fetch ( :account_number )
73+ target [ :account_number ] = target_config . fetch ( :account_number )
74+ target [ :role_prefix ] = target_config . fetch ( :role_prefix , nil )
75+ target [ :role_name ] = target_config . fetch ( :role_name , nil )
76+ target
77+ end
78+
79+ def self . ctrl_config ( config )
80+ ctrl_config = config . fetch ( :ctrl )
81+ ctrl = { }
82+ ctrl [ :account_number ] = ctrl_config . fetch ( :account_number )
83+ ctrl [ :role_prefix ] = ctrl_config . fetch ( :role_prefix )
84+ ctrl [ :role_name ] = ctrl_config . fetch ( :role_name )
85+ ctrl
86+ end
87+
88+ def self . default_region
89+ find_config . fetch ( :region , nil )
90+ end
91+
92+ def self . default_profile
93+ find_config . fetch ( :profile , nil )
94+ end
95+
96+ def self . default_user
97+ find_config . fetch ( :username , nil )
98+ end
99+
70100 def self . find_config
71101 Dir . mkdir ( CONFIG_DIR ) unless Dir . exist? ( CONFIG_DIR )
72102 begin
73103 if File . exist? ( CONFIG_FILE )
74104 config = YAML . load_file ( CONFIG_FILE )
75105 else
76- config = YAML . load_file ( SAMPLE_FILE )
77- File . open ( CONFIG_FILE , 'w' ) { |f | f . write config . to_yaml }
106+ File . open ( CONFIG_FILE , 'w' ) { |f | f . write SAMPLE_FILE . to_yaml }
78107 end
79108 rescue Psych ::SyntaxError
80109 raise "Improperly formatted YAML file: #{ CONFIG_FILE } ."
@@ -84,7 +113,7 @@ def self.find_config
84113 config
85114 end
86115
87- def self . find_default_plane
116+ def self . default_plane
88117 find_config [ :default ] [ :label ] || raise ( Rainbow ( "Location was not provided and no default location was found in #{ CONFIG_FILE } ." ) . red )
89118 end
90119
0 commit comments