Skip to content

Commit a141012

Browse files
author
Peter Benjamin
committed
Refactor restacker_config
1 parent 85b6e04 commit a141012

1 file changed

Lines changed: 10 additions & 21 deletions

File tree

source/lib/restacker_config.rb

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class RestackerConfig
22
def self.load_config(plane)
3-
plane = get_plane if plane.nil?
3+
plane = find_plane if plane.nil?
44
config = find_config
55
if config[plane].nil?
66
puts "Plane not found (#{plane}). Please see #{CONFIG_FILE}."
@@ -9,15 +9,6 @@ def self.load_config(plane)
99
config[plane]
1010
end
1111

12-
def self.get_plane(options)
13-
if options[:location]
14-
plane = options[:location]
15-
else
16-
plane = default_plane
17-
end
18-
plane.to_sym
19-
end
20-
2112
def self.configure(location)
2213
config = find_config()
2314
puts Rainbow("Configuration file location:").white.bright + " #{CONFIG_FILE}"
@@ -85,16 +76,18 @@ def self.ctrl_config(config)
8576
ctrl
8677
end
8778

88-
def self.default_region
89-
find_config.fetch(:region, nil)
79+
def self.find_profile(options)
80+
plane = find_plane(options)
81+
options[:profile] || find_config[plane][:profile] || find_config[:default][:profile]
9082
end
9183

92-
def self.default_profile
93-
find_config.fetch(:profile, nil)
84+
def self.find_user(options)
85+
plane = find_plane(options)
86+
options[:username] || find_config[plane].fetch(:username, nil) || ENV['USER']
9487
end
9588

96-
def self.default_user
97-
find_config.fetch(:username, nil)
89+
def self.find_plane(options)
90+
(options[:location] || find_config[:default][:label]).to_sym || raise(Rainbow("Location was not provided and no default location was found in #{CONFIG_FILE}.").red)
9891
end
9992

10093
def self.find_config
@@ -113,11 +106,7 @@ def self.find_config
113106
config
114107
end
115108

116-
def self.default_plane
117-
find_config[:default][:label] || raise(Rainbow("Location was not provided and no default location was found in #{CONFIG_FILE}.").red)
118-
end
119-
120-
def self.bucket
109+
def self.bucket(options)
121110
find_config[:ctrl][:bucket][:name]
122111
end
123112

0 commit comments

Comments
 (0)