mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[core] Allow FOG_CREDENTIAL env variable for config
Say your ~/.fog had multiple stanzas: :default: :aws_access_key_id: aaa test: :aws_access_key_id: bbb prod: :aws_access-key_id: ccc Choose a stanza with an environment variable: $ FOG_CREDENTIAL=prod fog
This commit is contained in:
parent
9b3eb02541
commit
e48ac6e8c3
2 changed files with 19 additions and 2 deletions
|
@ -13,7 +13,7 @@ module Fog
|
||||||
|
|
||||||
# @return [String, Symbol] The credential to use in Fog
|
# @return [String, Symbol] The credential to use in Fog
|
||||||
def self.credential
|
def self.credential
|
||||||
@credential ||= :default
|
@credential ||= ENV["FOG_CREDENTIAL"] || :default
|
||||||
end
|
end
|
||||||
|
|
||||||
# @return [String] The path for configuration_file
|
# @return [String] The path for configuration_file
|
||||||
|
|
|
@ -2,12 +2,29 @@ Shindo.tests do
|
||||||
before do
|
before do
|
||||||
@old_home = ENV['HOME']
|
@old_home = ENV['HOME']
|
||||||
@old_rc = ENV['FOG_RC']
|
@old_rc = ENV['FOG_RC']
|
||||||
|
@old_credential = ENV['FOG_CREDENTIAL']
|
||||||
Fog.instance_variable_set('@credential_path', nil) # kill memoization
|
Fog.instance_variable_set('@credential_path', nil) # kill memoization
|
||||||
|
Fog.instance_variable_set('@credential', nil) # kill memoization
|
||||||
end
|
end
|
||||||
|
|
||||||
after do
|
after do
|
||||||
ENV['HOME'] = @old_home
|
ENV['HOME'] = @old_home
|
||||||
ENV['FOG_RC'] = @ld_rc
|
ENV['FOG_RC'] = @old_rc
|
||||||
|
ENV['FOG_CREDENTIAL'] = @old_credential
|
||||||
|
end
|
||||||
|
|
||||||
|
tests('credential') do
|
||||||
|
returns(:default, "is :default") { Fog.credential }
|
||||||
|
|
||||||
|
returns("foo", "can be set directly") do
|
||||||
|
Fog.credential = "foo"
|
||||||
|
Fog.credential
|
||||||
|
end
|
||||||
|
|
||||||
|
returns("bar", "can be set with environment variable") do
|
||||||
|
ENV["FOG_CREDENTIAL"] = "bar"
|
||||||
|
Fog.credential
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
tests('credentials_path') do
|
tests('credentials_path') do
|
||||||
|
|
Loading…
Reference in a new issue