Skip to content

Commit

Permalink
Merge pull request #134 from smcavallo/support_multiple_profiles
Browse files Browse the repository at this point in the history
Support multiple profiles
  • Loading branch information
allmightyspiff committed Apr 2, 2018
2 parents 7889052 + 06e2a3a commit c93a234
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/softlayer/Config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ def Config.file_settings(*additional_files)
search_path.each do |file_path|
if File.readable? file_path
config = ConfigParser.new file_path
softlayer_section = config['softlayer']
profile_name = ENV['SL_PROFILE'] || 'softlayer'
softlayer_section = config[profile_name]

if softlayer_section
result[:api_key] = softlayer_section['api_key'] if softlayer_section['api_key']
Expand Down
38 changes: 38 additions & 0 deletions spec/Config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
require 'tempfile'

describe SoftLayer::Config do

before :each do
ENV.delete("SL_USERNAME")
ENV.delete("SL_API_KEY")
ENV.delete("SL_API_USER_AGENT")
ENV.delete("SL_PROFILE")
end

it "retrieves config information from environment variables" do
ENV.store("SL_USERNAME", "PoohBear")
ENV.store("SL_API_KEY", "DEADBEEFBADF00D")
Expand Down Expand Up @@ -41,6 +49,36 @@
expect(settings[:timeout]).to eq(40)
end

it "retrieves the properties from a custom file using a custom profile" do
ENV.store("SL_PROFILE", "softlayer_qa")
file = Tempfile.new('properties_from_file')
begin
file.puts("[softlayer_dev]")
file.puts("username = PoohBear")
file.puts("api_key = DEADBEEFBADF00D")
file.puts("timeout = 40")
file.puts("\n")
file.puts("[softlayer_qa]")
file.puts("username = Piglet")
file.puts("api_key = MOOOOOOOO")
file.puts("timeout = 60")
file.puts("\n")
file.puts("[softlayer_prod]")
file.puts("username = Eeyore")
file.puts("api_key = VEG_ALL_THE_WAY")
file.puts("timeout = 80")
file.close

settings = SoftLayer::Config.file_settings(file.path)
ensure
file.close
file.unlink
end

expect(settings[:username]).to eq("Piglet")
expect(settings[:api_key]).to eq("MOOOOOOOO")
expect(settings[:timeout]).to eq(60)
end

it "retrieves the timeout field as an integer when presented as a string" do
file = Tempfile.new('config_test')
Expand Down

0 comments on commit c93a234

Please sign in to comment.