Class: Firebase::Admin::Credentials

Inherits:
Object
  • Object
show all
Defined in:
lib/firebase/admin/credentials.rb

Overview

Firebase credentials.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(credentials) ⇒ Credentials

Constructs a Credential from the specified Google Credentials.

Parameters:

  • credentials (Google::Auth::ServiceAccountCredentials, Google::Auth::UserRefreshCredentials, Google::Auth::GCECredentials)

    The google credentials to connect with.

Raises:



56
57
58
59
# File 'lib/firebase/admin/credentials.rb', line 56

def initialize(credentials)
  raise ArgumentError, "credentials cannot be nil" if credentials.nil?
  @credentials = credentials
end

Instance Attribute Details

#credentialsObject (readonly)

Gets the google credentials



50
51
52
# File 'lib/firebase/admin/credentials.rb', line 50

def credentials
  @credentials
end

Class Method Details

.from_defaultFirebase::Admin::Credentials

Loads application default credentials.



44
45
46
# File 'lib/firebase/admin/credentials.rb', line 44

def from_default
  new(Google::Auth.get_application_default(SCOPE))
end

.from_file(file) ⇒ Firebase::Admin::Credentials

Loads google credentials from a specified file path.

Parameters:

  • file (File, String)

    The credentials file path

Returns:



25
26
27
28
# File 'lib/firebase/admin/credentials.rb', line 25

def from_file(file)
  json = file.is_a?(File) ? file.read : File.read(file)
  from_json(json)
end

.from_json(json) ⇒ Firebase::Admin::Credentials

Loads google credentials from a JSON string.

Parameters:

  • json (String)

    A JSON string containing valid google credentials.

Returns:



36
37
38
39
# File 'lib/firebase/admin/credentials.rb', line 36

def from_json(json)
  io = StringIO.new(json)
  new(Google::Auth::DefaultCredentials.make_creds(scope: SCOPE, json_key_io: io))
end

Instance Method Details

#apply!(hash, opts = {}) ⇒ Object

Apply the credentials



67
68
69
# File 'lib/firebase/admin/credentials.rb', line 67

def apply!(hash, opts = {})
  @credentials.apply!(hash, opts)
end

#project_idObject

Gets the google project id



62
63
64
# File 'lib/firebase/admin/credentials.rb', line 62

def project_id
  @credentials.project_id
end