Class: CloudSQLRubyConnector::Credentials::ServiceAccount

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

Overview

Service Account credentials from JSON key file

Constant Summary

Constants inherited from Base

Base::SCOPES, Base::TOKEN_URI

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#access_token

Constructor Details

#initialize(data) ⇒ ServiceAccount

Returns a new instance of ServiceAccount.



41
42
43
44
45
46
# File 'lib/cloud_sql_ruby_connector/credentials/service_account.rb', line 41

def initialize(data)
  super()
  validate_required_fields!(data)
  @client_email = data["client_email"]
  @private_key = OpenSSL::PKey::RSA.new(data["private_key"])
end

Instance Attribute Details

#client_emailObject (readonly)

Returns the value of attribute client_email.



26
27
28
# File 'lib/cloud_sql_ruby_connector/credentials/service_account.rb', line 26

def client_email
  @client_email
end

Class Method Details

.from_file(path) ⇒ ServiceAccount, UserCredentials

Load credentials from a JSON file

Parameters:

  • path (String)

    path to the JSON key file

Returns:



31
32
33
34
35
36
37
38
39
# File 'lib/cloud_sql_ruby_connector/credentials/service_account.rb', line 31

def self.from_file(path)
  data = JSON.parse(File.read(path))

  if data["type"] == "authorized_user"
    UserCredentials.new(data)
  else
    new(data)
  end
end