Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes an issue where the credential file was nil #337

Merged
merged 1 commit into from
Aug 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/train/transports/helpers/azure/file_credentials.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class FileCredentials
DEFAULT_FILE = ::File.join(Dir.home, '.azure', 'credentials')

def self.parse(subscription_id: nil, credentials_file: DEFAULT_FILE, **_)
credentials_file = DEFAULT_FILE if credentials_file.nil?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idiomatic ruby would have this as credentials_file ||= DEFAULT_FILE, but this should get you the same result.

return {} unless ::File.readable?(credentials_file)
credentials = IniFile.load(::File.expand_path(credentials_file))
subscription_id = parser(subscription_id, ENV['AZURE_SUBSCRIPTION_NUMBER'], credentials).subscription_id
Expand Down
8 changes: 8 additions & 0 deletions test/unit/transports/helpers/azure/file_credentials_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@

let(:options) { { credentials_file: cred_file_multiple_entries.path } }

it 'handles a nil file' do
options[:credentials_file] = nil

result = Train::Transports::Helpers::Azure::FileCredentials.parse(options)

assert_empty(result)
end

it 'returns empty hash when no credentials file detected' do
result = Train::Transports::Helpers::Azure::FileCredentials.parse({})

Expand Down