Class: CloudSQLRubyConnector::Credentials::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/cloud_sql_ruby_connector/credentials/base.rb

Overview

Base class for all credential types

Direct Known Subclasses

Metadata, ServiceAccount, UserCredentials

Constant Summary collapse

SCOPES =
{
  admin: "https://www.googleapis.com/auth/sqlservice.admin",
  login: "https://www.googleapis.com/auth/sqlservice.login"
}.freeze
TOKEN_URI =
"https://oauth2.googleapis.com/token"

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.



28
29
30
31
32
# File 'lib/cloud_sql_ruby_connector/credentials/base.rb', line 28

def initialize
  @tokens = {}
  @token_expiries = {}
  @mutex = Mutex.new
end

Instance Method Details

#access_token(scope: :admin) ⇒ String

Get an access token for the specified scope

Parameters:

  • scope (Symbol) (defaults to: :admin)

    :admin or :login

Returns:

  • (String)

    the access token



37
38
39
40
41
42
# File 'lib/cloud_sql_ruby_connector/credentials/base.rb', line 37

def access_token(scope: :admin)
  @mutex.synchronize do
    refresh_token(scope) if token_expired?(scope)
    @tokens[scope]
  end
end