Skip to content

Commit

Permalink
rename instance var with method
Browse files Browse the repository at this point in the history
Signed-off-by: Sathish <sbabu@progress.com>
  • Loading branch information
sathish-progress committed May 13, 2022
1 parent 0975fc7 commit 8a29716
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions libraries/backend/azure_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ class AzureConnection
# @return [String] the graph api endpoint api version, e.g. v1.0
attr_reader :graph_api_endpoint_api_version

# @return [Hash] tenant_id, client_id, client_secret, subscription_id
attr_reader :credentials

# Creates a HTTP client.
def initialize(client_args)
# Validate parameter's type.
Expand All @@ -62,13 +59,6 @@ def initialize(client_args)
@key_vault_dns_suffix = @client_args[:endpoint].key_vault_dns_suffix
@graph_api_endpoint_api_version = @client_args[:endpoint].graph_api_endpoint_api_version

@credentials = {
tenant_id: ENV['AZURE_TENANT_ID'],
client_id: ENV['AZURE_CLIENT_ID'],
client_secret: ENV['AZURE_CLIENT_SECRET'],
subscription_id: ENV['AZURE_SUBSCRIPTION_ID'],
}

@connection ||= Faraday.new do |conn|
# Implement user provided HTTP client params for handling TimeOut exceptions.
# https://www.rubydoc.info/gems/faraday/Faraday/Request/Retry
Expand Down Expand Up @@ -161,17 +151,17 @@ def rest_api_call(opts)
#
def authenticate(resource)
# Validate the presence of credentials.
unless @credentials.values.compact.delete_if(&:empty?).size == 4
unless credentials.values.compact.delete_if(&:empty?).size == 4
raise HTTPClientError::MissingCredentials, 'The following must be set in the Environment:'\
" #{@credentials.keys}.\n"\
"Missing: #{@credentials.keys.select { |key| @credentials[key].nil? }}"
" #{credentials.keys}.\n"\
"Missing: #{credentials.keys.select { |key| credentials[key].nil? }}"
end
# Build up the url that is required to authenticate with Azure REST API
auth_url = "#{@client_args[:endpoint].active_directory_endpoint_url}#{@credentials[:tenant_id]}/oauth2/token"
auth_url = "#{@client_args[:endpoint].active_directory_endpoint_url}#{credentials[:tenant_id]}/oauth2/token"
body = {
grant_type: 'client_credentials',
client_id: @credentials[:client_id],
client_secret: @credentials[:client_secret],
client_id: credentials[:client_id],
client_secret: credentials[:client_secret],
resource: resource,
}
headers = {
Expand Down

0 comments on commit 8a29716

Please sign in to comment.