Module: Google::Cloud::Spanner::Admin::Database

Defined in:
lib/google/cloud/spanner/admin/database.rb,
lib/google/cloud/spanner/admin/database/credentials.rb

Defined Under Namespace

Classes: Configuration

Constant Summary collapse

Credentials =
Deprecated.

Use version-specific credentials classes

V1::DatabaseAdmin::Credentials

Class Method Summary collapse

Class Method Details

.configure {|@configure| ... } ⇒ ::Google::Cloud::Config

Configure the Google Cloud Spanner Database Admin library. This configuration can be applied globally to all clients.

The following configuration parameters are supported:

  • credentials (type: String, Hash, Google::Auth::Credentials) - The path to the keyfile as a String, the contents of the keyfile as a Hash, or a Google::Auth::Credentials object.
  • lib_name (type: String) - The library name as recorded in instrumentation and logging.
  • lib_version (type: String) - The library version as recorded in instrumentation and logging.
  • interceptors (type: Array<GRPC::ClientInterceptor>) - An array of interceptors that are run before calls are executed.
  • timeout (type: Numeric) - Default timeout in seconds.
  • emulator_host - (String) Host name of the emulator. Defaults to ENV["SPANNER_EMULATOR_HOST"].
  • metadata (type: Hash{Symbol=>String}) - Additional gRPC headers to be sent with the call.
  • retry_policy (type: Hash) - The retry policy. The value is a hash with the following keys:
    • :initial_delay (type: Numeric) - The initial delay in seconds.
    • :max_delay (type: Numeric) - The max delay in seconds.
    • :multiplier (type: Numeric) - The incremental backoff multiplier.
    • :retry_codes (type: Array<String>) - The error codes that should trigger a retry.

Examples:

Modify the global config, setting the timeout to 10 seconds for all admin databases.

require "google/cloud/spanner/admin/database"

::Google::Cloud::Spanner::Admin::Database.configure do |config|
  config.timeout = 10.0
end

Yields:



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/google/cloud/spanner/admin/database.rb', line 184

def self.configure
  @configure ||= begin
    namespace = ["Google", "Cloud", "Spanner"]
    parent_config = while namespace.any?
                      parent_name = namespace.join "::"
                      parent_const = const_get parent_name
                      break parent_const.configure if parent_const.respond_to? :configure
                      namespace.pop
                    end

    default_config = Database::Configuration.new parent_config
    default_config
  end
  yield @configure if block_given?
  @configure
end

.database_admin(project_id: nil, credentials: nil, universe_domain: nil, scope: nil, timeout: nil, endpoint: nil, project: nil, keyfile: nil, emulator_host: nil, lib_name: nil, lib_version: nil) ⇒ Admin::Database::V1::DatabaseAdmin::Client

Create a new client object for a DatabaseAdmin.

This returns an instance of Google::Cloud::Spanner::Admin::Database::V1::DatabaseAdmin::Client for version V1 of the API.

About DatabaseAdmin

Google Cloud Spanner Database Admin Service

The Cloud Spanner Database Admin API can be used to create, drop, and list databases. It also enables updating the schema of pre-existing databases. It can be also used to create, delete and list backups for a database and to restore from an existing backup.

For more information on connecting to Google Cloud see the Authentication Guide.

Raises:

  • (ArgumentError)


86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/google/cloud/spanner/admin/database.rb', line 86

def self.database_admin project_id: nil,
                        credentials: nil,
                        universe_domain: nil,
                        scope: nil,
                        timeout: nil,
                        endpoint: nil,
                        project: nil,
                        keyfile: nil,
                        emulator_host: nil,
                        lib_name: nil,
                        lib_version: nil
  project_id ||= project || default_project_id
  scope ||= configure.scope
  timeout ||= configure.timeout
  emulator_host ||= configure.emulator_host
  # TODO: This logic is part of UniverseDomainConcerns in gapic-common
  # but is being copied here because we need to determine the host up
  # front in order to build a gRPC channel. We should refactor this
  # somehow to allow this logic to live where it is supposed to.
  universe_domain ||= configure.universe_domain || ENV["GOOGLE_CLOUD_UNIVERSE_DOMAIN"] || "googleapis.com"
  endpoint ||= emulator_host || configure.endpoint
  endpoint ||=
    Google::Cloud::Spanner::Admin::Database::V1::DatabaseAdmin::Client::DEFAULT_ENDPOINT_TEMPLATE.sub(
      Gapic::UniverseDomainConcerns::ENDPOINT_SUBSTITUTION, universe_domain
    )
  credentials ||= keyfile
  lib_name ||= configure.lib_name
  lib_version ||= configure.lib_version

  if emulator_host
    credentials = :this_channel_is_insecure
  else
    credentials ||= default_credentials scope: scope
    unless credentials.is_a? Google::Auth::Credentials
      credentials = Spanner::Credentials.new credentials, scope: scope
    end

    if credentials.respond_to? :project_id
      project_id ||= credentials.project_id
    end
  end

  project_id = project_id.to_s # Always cast to a string
  raise ArgumentError, "project_id is missing" if project_id.empty?

  configure.quota_project ||= credentials.quota_project_id if credentials.respond_to? :quota_project_id

  Admin::Database::V1::DatabaseAdmin::Client.new do |config|
    config.universe_domain = universe_domain
    config.credentials = channel endpoint, credentials
    config.quota_project = configure.quota_project
    config.timeout = timeout if timeout
    config.endpoint = endpoint
    config.lib_name = lib_name_with_prefix lib_name, lib_version
    config.lib_version = Google::Cloud::Spanner::VERSION
    config. = { "google-cloud-resource-prefix" => "projects/#{project_id}" }
  end
end