Module: FirebaseAdmin::Configuration

Included in:
FirebaseAdmin
Defined in:
lib/firebase-admin/configuration.rb

Overview

Defines constants and methods related to configuration

Constant Summary collapse

VALID_OPTIONS_KEYS =

An array of valid keys in the options hash when configuring a API

%i[
  access_token
  adapter
  connection_options
  endpoint
  user_agent
  project_id
  loud_logger
  service_account_email
  service_account_private_key
].freeze
DEFAULT_ACCESS_TOKEN =

By default, don’t set a user access token

'owner'.freeze
DEFAULT_ADAPTER =
Note:

The default faraday adapter is Net::HTTP.

The adapter that will be used to connect if none is set

Faraday.default_adapter
DEFAULT_CONNECTION_OPTIONS =

By default, don’t set any connection options

{}.freeze
DEFAULT_ENDPOINT =
Note:

There is no reason to use any other endpoint at this time

The endpoint that will be used to connect if none is set

'https://identitytoolkit.googleapis.com/'.freeze
DEFAULT_FORMAT =
Note:

JSON is the only available format at this time

The response format appended to the path and sent in the ‘Accept’ header if none is set

:json
DEFAULT_USER_AGENT =

The user agent that will be sent to the API endpoint if none is set

"Firebase Admin Ruby Gem #{FirebaseAdmin::VERSION}".freeze
DEFAULT_PROJECT_ID =
''.freeze
DEFAULT_LOUD_LOGGER =

By default, don’t turn on loud logging

nil

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object

When this module is extended, set all configuration options to their default values



65
66
67
# File 'lib/firebase-admin/configuration.rb', line 65

def self.extended(base)
  base.reset
end

Instance Method Details

#configure {|_self| ... } ⇒ Object

Convenience method to allow configuration options to be set in a block

Yields:

  • (_self)

Yield Parameters:



70
71
72
# File 'lib/firebase-admin/configuration.rb', line 70

def configure
  yield self
end

#optionsObject

Create a hash of options and their values



75
76
77
78
79
# File 'lib/firebase-admin/configuration.rb', line 75

def options
  VALID_OPTIONS_KEYS.inject({}) do |option, key|
    option.merge!(key => send(key))
  end
end

#read_service_account_credentials(credentials_path) ⇒ Object



87
88
89
90
91
92
93
94
95
96
# File 'lib/firebase-admin/configuration.rb', line 87

def (credentials_path)
  if credentials_path && File.exist?(credentials_path)
    JSON.parse(File.read(credentials_path))
  else
    {}
  end
rescue StandardError => e
  raise InvalidCredentials,
        "Failed reading credentials from '#{ENV['GOOGLE_APPLICATION_CREDENTIALS']}'. Error: #{e.message}"
end

#resetObject

Reset all configuration options to defaults



99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/firebase-admin/configuration.rb', line 99

def reset
  self.access_token       = DEFAULT_ACCESS_TOKEN
  self.adapter            = DEFAULT_ADAPTER
  self.connection_options = DEFAULT_CONNECTION_OPTIONS
  self.endpoint           = DEFAULT_ENDPOINT
  self.user_agent         = DEFAULT_USER_AGENT
  self.project_id         = DEFAULT_PROJECT_ID
  self.loud_logger        = DEFAULT_LOUD_LOGGER
  @service_account_credentials = nil
  self. = nil
  self. = nil
end

#service_account_credentialsObject



81
82
83
84
85
# File 'lib/firebase-admin/configuration.rb', line 81

def 
  return {} unless ENV['GOOGLE_APPLICATION_CREDENTIALS']

  @service_account_credentials ||= (ENV['GOOGLE_APPLICATION_CREDENTIALS'])
end

#service_account_emailObject



52
53
54
55
56
# File 'lib/firebase-admin/configuration.rb', line 52

def 
  @service_account_email ||= .fetch('client_email') do
    ENV['GOOGLE_CLIENT_EMAIL']
  end
end

#service_account_private_keyObject



58
59
60
61
62
# File 'lib/firebase-admin/configuration.rb', line 58

def 
  @service_account_private_key ||= .fetch('private_key') do
    ENV['GOOGLE_PRIVATE_KEY']
  end
end