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.

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

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.

Yields:

Returns:

  • (::Google::Cloud::Config)

    The default configuration used by this library


175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/google/cloud/spanner/admin/database.rb', line 175

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, 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.

rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize, Metrics/MethodLength

Parameters:

  • project_id (String) (defaults to: nil)

    Project identifier for the Spanner service you are connecting to. If not present, the default project for the credentials is used.

  • credentials (String, Hash, Google::Auth::Credentials) (defaults to: nil)

    The path to the keyfile as a String, the contents of the keyfile as a Hash, or a Google::Auth::Credentials object. (See Credentials) If emulator_host is present, this becomes optional and the value is internally overriden with :this_channel_is_insecure.

  • scope (String, Array<String>) (defaults to: nil)

    The OAuth 2.0 scopes controlling the set of resources and operations that the connection can access. See Using OAuth 2.0 to Access Google APIs.

    The default scopes are:

    • https://www.googleapis.com/auth/spanner
    • https://www.googleapis.com/auth/spanner.data
  • timeout (Integer) (defaults to: nil)

    Default timeout to use in requests. Optional.

  • endpoint (String) (defaults to: nil)

    Override of the endpoint host name. Optional. If the param is nil, uses emulator_host or the default endpoint.

  • project (String) (defaults to: nil)

    Alias for the project_id argument. Deprecated.

  • keyfile (String) (defaults to: nil)

    Alias for the credentials argument. Deprecated.

  • emulator_host (String) (defaults to: nil)

    Spanner emulator host. Optional. If the param is nil, uses the value of the emulator_host config.

  • lib_name (String) (defaults to: nil)

    Library name. This will be added as a prefix to the API call tracking header x-goog-api-client with provided lib version for telemetry. Optional. For example prefix looks like spanner-activerecord/0.0.1 gccl/1.13.1. Here, spanner-activerecord/0.0.1 is provided custom library name and version and gccl/1.13.1 represents the Cloud Spanner Ruby library with version.

  • lib_version (String) (defaults to: nil)

    Library version. This will be added as a prefix to the API call tracking header x-goog-api-client with provided lib name for telemetry. Optional. For example prefix look like spanner-activerecord/0.0.1 gccl/1.13.1. Here, spanner-activerecord/0.0.1 is provided custom library name and version and gccl/1.13.1 represents the Cloud Spanner Ruby library with version.

Returns:

  • (Admin::Database::V1::DatabaseAdmin::Client)

    A client object of version V1.

Raises:

  • (ArgumentError)

85
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
# File 'lib/google/cloud/spanner/admin/database.rb', line 85

def self.database_admin project_id: nil,
                        credentials: 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
  endpoint      ||= emulator_host || configure.endpoint
  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.credentials = channel endpoint, credentials
    config.quota_project = configure.quota_project
    config.timeout = timeout if timeout
    config.endpoint = endpoint if 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