class Google::Cloud::Shell::V1::CloudShellService::Client
Client
for the CloudShellService
service.
API for interacting with Google
Cloud
Shell
. Each user of Cloud
Shell
has at least one environment, which has the ID “default”. Environment
consists of a Docker image defining what is installed on the environment and a home directory containing the user's data that will remain across sessions. Clients use this API to start and fetch information about their environment, which can then be used to connect to that environment via a separate SSH client.
Attributes
@private
Get the associated client for long-running operations.
@return [::Google::Cloud::Shell::V1::CloudShellService::Operations]
Public Class Methods
Configure the CloudShellService
Client
class.
See {::Google::Cloud::Shell::V1::CloudShellService::Client::Configuration} for a description of the configuration fields.
@example
# Modify the configuration for all CloudShellService clients ::Google::Cloud::Shell::V1::CloudShellService::Client.configure do |config| config.timeout = 10.0 end
@yield [config] Configure the Client
client. @yieldparam config [Client::Configuration]
@return [Client::Configuration]
# File lib/google/cloud/shell/v1/cloud_shell_service/client.rb, line 62 def self.configure @configure ||= begin namespace = ["Google", "Cloud", "Shell", "V1"] 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 = Client::Configuration.new parent_config default_config.rpcs.get_environment.timeout = 60.0 default_config.rpcs.get_environment.retry_policy = { initial_delay: 1.0, max_delay: 60.0, multiplier: 1.3, retry_codes: [14, 2] } default_config.rpcs.start_environment.timeout = 60.0 default_config.rpcs.authorize_environment.timeout = 60.0 default_config.rpcs.add_public_key.timeout = 60.0 default_config.rpcs.remove_public_key.timeout = 60.0 default_config end yield @configure if block_given? @configure end
Create a new CloudShellService
client object.
@example
# Create a client using the default configuration client = ::Google::Cloud::Shell::V1::CloudShellService::Client.new # Create a client using a custom configuration client = ::Google::Cloud::Shell::V1::CloudShellService::Client.new do |config| config.timeout = 10.0 end
@yield [config] Configure the CloudShellService
client. @yieldparam config [Client::Configuration]
# File lib/google/cloud/shell/v1/cloud_shell_service/client.rb, line 128 def initialize # These require statements are intentionally placed here to initialize # the gRPC module only when it's required. # See https://github.com/googleapis/toolkit/issues/446 require "gapic/grpc" require "google/cloud/shell/v1/cloudshell_services_pb" # Create the configuration object @config = Configuration.new Client.configure # Yield the configuration if needed yield @config if block_given? # Create credentials credentials = @config.credentials # Use self-signed JWT if the endpoint is unchanged from default, # but only if the default endpoint does not have a region prefix. enable_self_signed_jwt = @config.endpoint == Client.configure.endpoint && !@config.endpoint.split(".").first.include?("-") credentials ||= Credentials.default scope: @config.scope, enable_self_signed_jwt: enable_self_signed_jwt if credentials.is_a?(::String) || credentials.is_a?(::Hash) credentials = Credentials.new credentials, scope: @config.scope end @quota_project_id = @config.quota_project @quota_project_id ||= credentials.quota_project_id if credentials.respond_to? :quota_project_id @operations_client = Operations.new do |config| config.credentials = credentials config.endpoint = @config.endpoint end @cloud_shell_service_stub = ::Gapic::ServiceStub.new( ::Google::Cloud::Shell::V1::CloudShellService::Stub, credentials: credentials, endpoint: @config.endpoint, channel_args: @config.channel_args, interceptors: @config.interceptors ) end
Public Instance Methods
Adds a public SSH key to an environment, allowing clients with the corresponding private key to connect to that environment via SSH. If a key with the same content already exists, this will error with ALREADY_EXISTS.
@overload add_public_key
(request, options = nil)
Pass arguments to `add_public_key` via a request object, either of type {::Google::Cloud::Shell::V1::AddPublicKeyRequest} or an equivalent Hash. @param request [::Google::Cloud::Shell::V1::AddPublicKeyRequest, ::Hash] A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash. @param options [::Gapic::CallOptions, ::Hash] Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
@overload add_public_key
(environment: nil, key: nil)
Pass arguments to `add_public_key` via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above). @param environment [::String] Environment this key should be added to, e.g. `users/me/environments/default`. @param key [::String] Key that should be added to the environment. Supported formats are `ssh-dss` (see RFC4253), `ssh-rsa` (see RFC4253), `ecdsa-sha2-nistp256` (see RFC5656), `ecdsa-sha2-nistp384` (see RFC5656) and `ecdsa-sha2-nistp521` (see RFC5656). It should be structured as <format> <content>, where <content> part is encoded with Base64.
@yield [response, operation] Access the result along with the RPC operation @yieldparam response [::Gapic::Operation] @yieldparam operation [::GRPC::ActiveCall::Operation]
@return [::Gapic::Operation]
@raise [::Google::Cloud::Error] if the RPC is aborted.
# File lib/google/cloud/shell/v1/cloud_shell_service/client.rb, line 450 def add_public_key request, options = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Shell::V1::AddPublicKeyRequest # Converts hash and nil to an options object options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults metadata = @config.rpcs.add_public_key.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Shell::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = { "environment" => request.environment } request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.add_public_key.timeout, metadata: metadata, retry_policy: @config.rpcs.add_public_key.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, retry_policy: @config.retry_policy @cloud_shell_service_stub.call_rpc :add_public_key, request, options: options do |response, operation| response = ::Gapic::Operation.new response, @operations_client, options: options yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end
Configure the CloudShellService
Client
instance.
The configuration is set to the derived mode, meaning that values can be changed, but structural changes (adding new fields, etc.) are not allowed. Structural changes should be made on {Client.configure}.
See {::Google::Cloud::Shell::V1::CloudShellService::Client::Configuration} for a description of the configuration fields.
@yield [config] Configure the Client
client. @yieldparam config [Client::Configuration]
@return [Client::Configuration]
# File lib/google/cloud/shell/v1/cloud_shell_service/client.rb, line 107 def configure yield @config if block_given? @config end
Gets an environment. Returns NOT_FOUND if the environment does not exist.
@overload get_environment
(request, options = nil)
Pass arguments to `get_environment` via a request object, either of type {::Google::Cloud::Shell::V1::GetEnvironmentRequest} or an equivalent Hash. @param request [::Google::Cloud::Shell::V1::GetEnvironmentRequest, ::Hash] A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash. @param options [::Gapic::CallOptions, ::Hash] Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
@overload get_environment
(name: nil)
Pass arguments to `get_environment` via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above). @param name [::String] Required. Name of the requested resource, for example `users/me/environments/default` or `users/someone@example.com/environments/default`.
@yield [response, operation] Access the result along with the RPC operation @yieldparam response [::Google::Cloud::Shell::V1::Environment] @yieldparam operation [::GRPC::ActiveCall::Operation]
@return [::Google::Cloud::Shell::V1::Environment]
@raise [::Google::Cloud::Error] if the RPC is aborted.
# File lib/google/cloud/shell/v1/cloud_shell_service/client.rb, line 208 def get_environment request, options = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Shell::V1::GetEnvironmentRequest # Converts hash and nil to an options object options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults metadata = @config.rpcs.get_environment.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Shell::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = { "name" => request.name } request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get_environment.timeout, metadata: metadata, retry_policy: @config.rpcs.get_environment.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, retry_policy: @config.retry_policy @cloud_shell_service_stub.call_rpc :get_environment, request, options: options do |response, operation| yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end
Removes a public SSH key from an environment. Clients will no longer be able to connect to the environment using the corresponding private key. If a key with the same content is not present, this will error with NOT_FOUND.
@overload remove_public_key
(request, options = nil)
Pass arguments to `remove_public_key` via a request object, either of type {::Google::Cloud::Shell::V1::RemovePublicKeyRequest} or an equivalent Hash. @param request [::Google::Cloud::Shell::V1::RemovePublicKeyRequest, ::Hash] A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash. @param options [::Gapic::CallOptions, ::Hash] Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
@overload remove_public_key
(environment: nil, key: nil)
Pass arguments to `remove_public_key` via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above). @param environment [::String] Environment this key should be removed from, e.g. `users/me/environments/default`. @param key [::String] Key that should be removed from the environment.
@yield [response, operation] Access the result along with the RPC operation @yieldparam response [::Gapic::Operation] @yieldparam operation [::GRPC::ActiveCall::Operation]
@return [::Gapic::Operation]
@raise [::Google::Cloud::Error] if the RPC is aborted.
# File lib/google/cloud/shell/v1/cloud_shell_service/client.rb, line 525 def remove_public_key request, options = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Shell::V1::RemovePublicKeyRequest # Converts hash and nil to an options object options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults metadata = @config.rpcs.remove_public_key.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Shell::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = { "environment" => request.environment } request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.remove_public_key.timeout, metadata: metadata, retry_policy: @config.rpcs.remove_public_key.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, retry_policy: @config.retry_policy @cloud_shell_service_stub.call_rpc :remove_public_key, request, options: options do |response, operation| response = ::Gapic::Operation.new response, @operations_client, options: options yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end
Starts an existing environment, allowing clients to connect to it. The returned operation will contain an instance of StartEnvironmentMetadata
in its metadata field. Users can wait for the environment to start by polling this operation via GetOperation. Once the environment has finished starting and is ready to accept connections, the operation will contain a StartEnvironmentResponse in its response field.
@overload start_environment
(request, options = nil)
Pass arguments to `start_environment` via a request object, either of type {::Google::Cloud::Shell::V1::StartEnvironmentRequest} or an equivalent Hash. @param request [::Google::Cloud::Shell::V1::StartEnvironmentRequest, ::Hash] A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash. @param options [::Gapic::CallOptions, ::Hash] Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
@overload start_environment
(name: nil, access_token: nil, public_keys: nil)
Pass arguments to `start_environment` via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above). @param name [::String] Name of the resource that should be started, for example `users/me/environments/default` or `users/someone@example.com/environments/default`. @param access_token [::String] The initial access token passed to the environment. If this is present and valid, the environment will be pre-authenticated with gcloud so that the user can run gcloud commands in Cloud Shell without having to log in. This code can be updated later by calling AuthorizeEnvironment. @param public_keys [::Array<::String>] Public keys that should be added to the environment before it is started.
@yield [response, operation] Access the result along with the RPC operation @yieldparam response [::Gapic::Operation] @yieldparam operation [::GRPC::ActiveCall::Operation]
@return [::Gapic::Operation]
@raise [::Google::Cloud::Error] if the RPC is aborted.
# File lib/google/cloud/shell/v1/cloud_shell_service/client.rb, line 290 def start_environment request, options = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Shell::V1::StartEnvironmentRequest # Converts hash and nil to an options object options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults metadata = @config.rpcs.start_environment.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Shell::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = { "name" => request.name } request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.start_environment.timeout, metadata: metadata, retry_policy: @config.rpcs.start_environment.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, retry_policy: @config.retry_policy @cloud_shell_service_stub.call_rpc :start_environment, request, options: options do |response, operation| response = ::Gapic::Operation.new response, @operations_client, options: options yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end