Class: Train::Transports::Helpers::Azure::FileCredentials

Inherits:
Object
  • Object
show all
Defined in:
lib/train/transports/helpers/azure/file_credentials.rb

Class Method Summary collapse

Class Method Details

.creds(subscription_id, credentials) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/train/transports/helpers/azure/file_credentials.rb', line 29

def self.creds(subscription_id, credentials)
  {
    subscription_id: subscription_id,
    tenant_id: credentials[subscription_id]["tenant_id"],
    client_id: credentials[subscription_id]["client_id"],
    client_secret: credentials[subscription_id]["client_secret"],
  }
end

.parse(subscription_id: nil, credentials_file: nil, **_) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/train/transports/helpers/azure/file_credentials.rb', line 10

def self.parse(subscription_id: nil, credentials_file: nil, **_)
  return {} if credentials_file.nil?
  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
  creds(subscription_id, credentials)
end

.parser(subscription_id, subscription_number, credentials) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/train/transports/helpers/azure/file_credentials.rb', line 19

def self.parser(subscription_id, subscription_number, credentials)
  if subscription_id
    SubscriptionIdFileParser.new(subscription_id, credentials)
  elsif !subscription_number.nil?
    SubscriptionNumberFileParser.new(subscription_number.to_i, credentials)
  else
    FileParser.new(credentials)
  end
end