Class: AzIdentity::Identity::BaseClient

Inherits:
Object
  • Object
show all
Includes:
AzureEnvironment
Defined in:
lib/az_identity/identity/base_client.rb

Defined Under Namespace

Classes: FetchCredentialsError

Constant Summary collapse

DEFAULT_TIMEOUT_S =
30

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AzureEnvironment

#authority_url, #redis_resource, #storage_resource

Constructor Details

#initializeBaseClient

Returns a new instance of BaseClient.



19
20
21
# File 'lib/az_identity/identity/base_client.rb', line 19

def initialize
  @mutex = Mutex.new
end

Instance Attribute Details

#credentialsObject

Returns the value of attribute credentials.



17
18
19
# File 'lib/az_identity/identity/base_client.rb', line 17

def credentials
  @credentials
end

Instance Method Details

#fetch_credentialsObject

Raises:

  • (NotImplementedError)


23
24
25
# File 'lib/az_identity/identity/base_client.rb', line 23

def fetch_credentials
  raise NotImplementedError
end

#fetch_credentials_if_neededObject



27
28
29
30
31
32
33
34
35
# File 'lib/az_identity/identity/base_client.rb', line 27

def fetch_credentials_if_needed
  # Serialize refreshes so concurrent callers (for example pooled Redis
  # connections across threads) don't each hit the token endpoint.
  @mutex.synchronize do
    @credentials = fetch_credentials if @credentials.nil? || refresh_needed?

    credentials
  end
end

#refresh_needed?Boolean

Returns:

  • (Boolean)


37
38
39
40
41
# File 'lib/az_identity/identity/base_client.rb', line 37

def refresh_needed?
  return true unless @credentials

  @credentials.refresh_needed?
end