diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d04863..e492309 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +### [1.3.1](https://github.com/googleapis/python-shell/compare/v1.3.0...v1.3.1) (2022-02-11) + + +### Bug Fixes + +* resolve DuplicateCredentialArgs error when using credentials_file ([b660c07](https://github.com/googleapis/python-shell/commit/b660c07d2f42673a85dd596590c82e2f972530fd)) + ## [1.3.0](https://github.com/googleapis/python-shell/compare/v1.2.2...v1.3.0) (2022-01-25) diff --git a/google/cloud/shell_v1/services/cloud_shell_service/async_client.py b/google/cloud/shell_v1/services/cloud_shell_service/async_client.py index f1b14cd..54c54e7 100644 --- a/google/cloud/shell_v1/services/cloud_shell_service/async_client.py +++ b/google/cloud/shell_v1/services/cloud_shell_service/async_client.py @@ -225,6 +225,26 @@ async def get_environment( r"""Gets an environment. Returns NOT_FOUND if the environment does not exist. + + .. code-block:: + + from google.cloud import shell_v1 + + def sample_get_environment(): + # Create a client + client = shell_v1.CloudShellServiceClient() + + # Initialize request argument(s) + request = shell_v1.GetEnvironmentRequest( + name="name_value", + ) + + # Make the request + response = client.get_environment(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.shell_v1.types.GetEnvironmentRequest, dict]): The request object. Request message for @@ -256,7 +276,7 @@ async def get_environment( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: @@ -318,6 +338,29 @@ async def start_environment( connections, the operation will contain a StartEnvironmentResponse in its response field. + + .. code-block:: + + from google.cloud import shell_v1 + + def sample_start_environment(): + # Create a client + client = shell_v1.CloudShellServiceClient() + + # Initialize request argument(s) + request = shell_v1.StartEnvironmentRequest( + ) + + # Make the request + operation = client.start_environment(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.shell_v1.types.StartEnvironmentRequest, dict]): The request object. Request message for @@ -382,6 +425,29 @@ async def authorize_environment( line tools without requiring the user to manually authenticate. + + .. code-block:: + + from google.cloud import shell_v1 + + def sample_authorize_environment(): + # Create a client + client = shell_v1.CloudShellServiceClient() + + # Initialize request argument(s) + request = shell_v1.AuthorizeEnvironmentRequest( + ) + + # Make the request + operation = client.authorize_environment(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.shell_v1.types.AuthorizeEnvironmentRequest, dict]): The request object. Request message for @@ -444,6 +510,29 @@ async def add_public_key( SSH. If a key with the same content already exists, this will error with ALREADY_EXISTS. + + .. code-block:: + + from google.cloud import shell_v1 + + def sample_add_public_key(): + # Create a client + client = shell_v1.CloudShellServiceClient() + + # Initialize request argument(s) + request = shell_v1.AddPublicKeyRequest( + ) + + # Make the request + operation = client.add_public_key(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.shell_v1.types.AddPublicKeyRequest, dict]): The request object. Request message for @@ -508,6 +597,29 @@ async def remove_public_key( corresponding private key. If a key with the same content is not present, this will error with NOT_FOUND. + + .. code-block:: + + from google.cloud import shell_v1 + + def sample_remove_public_key(): + # Create a client + client = shell_v1.CloudShellServiceClient() + + # Initialize request argument(s) + request = shell_v1.RemovePublicKeyRequest( + ) + + # Make the request + operation = client.remove_public_key(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.shell_v1.types.RemovePublicKeyRequest, dict]): The request object. Request message for diff --git a/google/cloud/shell_v1/services/cloud_shell_service/client.py b/google/cloud/shell_v1/services/cloud_shell_service/client.py index 46fb296..6fd6eaa 100644 --- a/google/cloud/shell_v1/services/cloud_shell_service/client.py +++ b/google/cloud/shell_v1/services/cloud_shell_service/client.py @@ -419,6 +419,27 @@ def get_environment( r"""Gets an environment. Returns NOT_FOUND if the environment does not exist. + + + .. code-block:: + + from google.cloud import shell_v1 + + def sample_get_environment(): + # Create a client + client = shell_v1.CloudShellServiceClient() + + # Initialize request argument(s) + request = shell_v1.GetEnvironmentRequest( + name="name_value", + ) + + # Make the request + response = client.get_environment(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.shell_v1.types.GetEnvironmentRequest, dict]): The request object. Request message for @@ -450,7 +471,7 @@ def get_environment( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: @@ -503,6 +524,30 @@ def start_environment( connections, the operation will contain a StartEnvironmentResponse in its response field. + + + .. code-block:: + + from google.cloud import shell_v1 + + def sample_start_environment(): + # Create a client + client = shell_v1.CloudShellServiceClient() + + # Initialize request argument(s) + request = shell_v1.StartEnvironmentRequest( + ) + + # Make the request + operation = client.start_environment(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.shell_v1.types.StartEnvironmentRequest, dict]): The request object. Request message for @@ -568,6 +613,30 @@ def authorize_environment( line tools without requiring the user to manually authenticate. + + + .. code-block:: + + from google.cloud import shell_v1 + + def sample_authorize_environment(): + # Create a client + client = shell_v1.CloudShellServiceClient() + + # Initialize request argument(s) + request = shell_v1.AuthorizeEnvironmentRequest( + ) + + # Make the request + operation = client.authorize_environment(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.shell_v1.types.AuthorizeEnvironmentRequest, dict]): The request object. Request message for @@ -631,6 +700,30 @@ def add_public_key( SSH. If a key with the same content already exists, this will error with ALREADY_EXISTS. + + + .. code-block:: + + from google.cloud import shell_v1 + + def sample_add_public_key(): + # Create a client + client = shell_v1.CloudShellServiceClient() + + # Initialize request argument(s) + request = shell_v1.AddPublicKeyRequest( + ) + + # Make the request + operation = client.add_public_key(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.shell_v1.types.AddPublicKeyRequest, dict]): The request object. Request message for @@ -696,6 +789,30 @@ def remove_public_key( corresponding private key. If a key with the same content is not present, this will error with NOT_FOUND. + + + .. code-block:: + + from google.cloud import shell_v1 + + def sample_remove_public_key(): + # Create a client + client = shell_v1.CloudShellServiceClient() + + # Initialize request argument(s) + request = shell_v1.RemovePublicKeyRequest( + ) + + # Make the request + operation = client.remove_public_key(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.shell_v1.types.RemovePublicKeyRequest, dict]): The request object. Request message for diff --git a/google/cloud/shell_v1/services/cloud_shell_service/transports/grpc.py b/google/cloud/shell_v1/services/cloud_shell_service/transports/grpc.py index e60ecf3..e6b7162 100644 --- a/google/cloud/shell_v1/services/cloud_shell_service/transports/grpc.py +++ b/google/cloud/shell_v1/services/cloud_shell_service/transports/grpc.py @@ -168,8 +168,11 @@ def __init__( if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -242,7 +245,7 @@ def operations_client(self) -> operations_v1.OperationsClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsClient(self.grpc_channel) diff --git a/google/cloud/shell_v1/services/cloud_shell_service/transports/grpc_asyncio.py b/google/cloud/shell_v1/services/cloud_shell_service/transports/grpc_asyncio.py index 8302cf9..91170ec 100644 --- a/google/cloud/shell_v1/services/cloud_shell_service/transports/grpc_asyncio.py +++ b/google/cloud/shell_v1/services/cloud_shell_service/transports/grpc_asyncio.py @@ -213,8 +213,11 @@ def __init__( if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -244,7 +247,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( self.grpc_channel diff --git a/samples/generated_samples/cloudshell_generated_shell_v1_cloud_shell_service_add_public_key_async.py b/samples/generated_samples/cloudshell_generated_shell_v1_cloud_shell_service_add_public_key_async.py new file mode 100644 index 0000000..d406ada --- /dev/null +++ b/samples/generated_samples/cloudshell_generated_shell_v1_cloud_shell_service_add_public_key_async.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AddPublicKey +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-shell + + +# [START cloudshell_generated_shell_v1_CloudShellService_AddPublicKey_async] +from google.cloud import shell_v1 + + +async def sample_add_public_key(): + # Create a client + client = shell_v1.CloudShellServiceAsyncClient() + + # Initialize request argument(s) + request = shell_v1.AddPublicKeyRequest( + ) + + # Make the request + operation = client.add_public_key(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END cloudshell_generated_shell_v1_CloudShellService_AddPublicKey_async] diff --git a/samples/generated_samples/cloudshell_generated_shell_v1_cloud_shell_service_add_public_key_sync.py b/samples/generated_samples/cloudshell_generated_shell_v1_cloud_shell_service_add_public_key_sync.py new file mode 100644 index 0000000..fb1f870 --- /dev/null +++ b/samples/generated_samples/cloudshell_generated_shell_v1_cloud_shell_service_add_public_key_sync.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AddPublicKey +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-shell + + +# [START cloudshell_generated_shell_v1_CloudShellService_AddPublicKey_sync] +from google.cloud import shell_v1 + + +def sample_add_public_key(): + # Create a client + client = shell_v1.CloudShellServiceClient() + + # Initialize request argument(s) + request = shell_v1.AddPublicKeyRequest( + ) + + # Make the request + operation = client.add_public_key(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END cloudshell_generated_shell_v1_CloudShellService_AddPublicKey_sync] diff --git a/samples/generated_samples/cloudshell_generated_shell_v1_cloud_shell_service_authorize_environment_async.py b/samples/generated_samples/cloudshell_generated_shell_v1_cloud_shell_service_authorize_environment_async.py new file mode 100644 index 0000000..44461ab --- /dev/null +++ b/samples/generated_samples/cloudshell_generated_shell_v1_cloud_shell_service_authorize_environment_async.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AuthorizeEnvironment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-shell + + +# [START cloudshell_generated_shell_v1_CloudShellService_AuthorizeEnvironment_async] +from google.cloud import shell_v1 + + +async def sample_authorize_environment(): + # Create a client + client = shell_v1.CloudShellServiceAsyncClient() + + # Initialize request argument(s) + request = shell_v1.AuthorizeEnvironmentRequest( + ) + + # Make the request + operation = client.authorize_environment(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END cloudshell_generated_shell_v1_CloudShellService_AuthorizeEnvironment_async] diff --git a/samples/generated_samples/cloudshell_generated_shell_v1_cloud_shell_service_authorize_environment_sync.py b/samples/generated_samples/cloudshell_generated_shell_v1_cloud_shell_service_authorize_environment_sync.py new file mode 100644 index 0000000..c19bfde --- /dev/null +++ b/samples/generated_samples/cloudshell_generated_shell_v1_cloud_shell_service_authorize_environment_sync.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AuthorizeEnvironment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-shell + + +# [START cloudshell_generated_shell_v1_CloudShellService_AuthorizeEnvironment_sync] +from google.cloud import shell_v1 + + +def sample_authorize_environment(): + # Create a client + client = shell_v1.CloudShellServiceClient() + + # Initialize request argument(s) + request = shell_v1.AuthorizeEnvironmentRequest( + ) + + # Make the request + operation = client.authorize_environment(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END cloudshell_generated_shell_v1_CloudShellService_AuthorizeEnvironment_sync] diff --git a/samples/generated_samples/cloudshell_generated_shell_v1_cloud_shell_service_get_environment_async.py b/samples/generated_samples/cloudshell_generated_shell_v1_cloud_shell_service_get_environment_async.py new file mode 100644 index 0000000..e78411d --- /dev/null +++ b/samples/generated_samples/cloudshell_generated_shell_v1_cloud_shell_service_get_environment_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetEnvironment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-shell + + +# [START cloudshell_generated_shell_v1_CloudShellService_GetEnvironment_async] +from google.cloud import shell_v1 + + +async def sample_get_environment(): + # Create a client + client = shell_v1.CloudShellServiceAsyncClient() + + # Initialize request argument(s) + request = shell_v1.GetEnvironmentRequest( + name="name_value", + ) + + # Make the request + response = await client.get_environment(request=request) + + # Handle the response + print(response) + +# [END cloudshell_generated_shell_v1_CloudShellService_GetEnvironment_async] diff --git a/samples/generated_samples/cloudshell_generated_shell_v1_cloud_shell_service_get_environment_sync.py b/samples/generated_samples/cloudshell_generated_shell_v1_cloud_shell_service_get_environment_sync.py new file mode 100644 index 0000000..3985550 --- /dev/null +++ b/samples/generated_samples/cloudshell_generated_shell_v1_cloud_shell_service_get_environment_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetEnvironment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-shell + + +# [START cloudshell_generated_shell_v1_CloudShellService_GetEnvironment_sync] +from google.cloud import shell_v1 + + +def sample_get_environment(): + # Create a client + client = shell_v1.CloudShellServiceClient() + + # Initialize request argument(s) + request = shell_v1.GetEnvironmentRequest( + name="name_value", + ) + + # Make the request + response = client.get_environment(request=request) + + # Handle the response + print(response) + +# [END cloudshell_generated_shell_v1_CloudShellService_GetEnvironment_sync] diff --git a/samples/generated_samples/cloudshell_generated_shell_v1_cloud_shell_service_remove_public_key_async.py b/samples/generated_samples/cloudshell_generated_shell_v1_cloud_shell_service_remove_public_key_async.py new file mode 100644 index 0000000..abf5979 --- /dev/null +++ b/samples/generated_samples/cloudshell_generated_shell_v1_cloud_shell_service_remove_public_key_async.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for RemovePublicKey +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-shell + + +# [START cloudshell_generated_shell_v1_CloudShellService_RemovePublicKey_async] +from google.cloud import shell_v1 + + +async def sample_remove_public_key(): + # Create a client + client = shell_v1.CloudShellServiceAsyncClient() + + # Initialize request argument(s) + request = shell_v1.RemovePublicKeyRequest( + ) + + # Make the request + operation = client.remove_public_key(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END cloudshell_generated_shell_v1_CloudShellService_RemovePublicKey_async] diff --git a/samples/generated_samples/cloudshell_generated_shell_v1_cloud_shell_service_remove_public_key_sync.py b/samples/generated_samples/cloudshell_generated_shell_v1_cloud_shell_service_remove_public_key_sync.py new file mode 100644 index 0000000..7f1541b --- /dev/null +++ b/samples/generated_samples/cloudshell_generated_shell_v1_cloud_shell_service_remove_public_key_sync.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for RemovePublicKey +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-shell + + +# [START cloudshell_generated_shell_v1_CloudShellService_RemovePublicKey_sync] +from google.cloud import shell_v1 + + +def sample_remove_public_key(): + # Create a client + client = shell_v1.CloudShellServiceClient() + + # Initialize request argument(s) + request = shell_v1.RemovePublicKeyRequest( + ) + + # Make the request + operation = client.remove_public_key(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END cloudshell_generated_shell_v1_CloudShellService_RemovePublicKey_sync] diff --git a/samples/generated_samples/cloudshell_generated_shell_v1_cloud_shell_service_start_environment_async.py b/samples/generated_samples/cloudshell_generated_shell_v1_cloud_shell_service_start_environment_async.py new file mode 100644 index 0000000..84bb50d --- /dev/null +++ b/samples/generated_samples/cloudshell_generated_shell_v1_cloud_shell_service_start_environment_async.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for StartEnvironment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-shell + + +# [START cloudshell_generated_shell_v1_CloudShellService_StartEnvironment_async] +from google.cloud import shell_v1 + + +async def sample_start_environment(): + # Create a client + client = shell_v1.CloudShellServiceAsyncClient() + + # Initialize request argument(s) + request = shell_v1.StartEnvironmentRequest( + ) + + # Make the request + operation = client.start_environment(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END cloudshell_generated_shell_v1_CloudShellService_StartEnvironment_async] diff --git a/samples/generated_samples/cloudshell_generated_shell_v1_cloud_shell_service_start_environment_sync.py b/samples/generated_samples/cloudshell_generated_shell_v1_cloud_shell_service_start_environment_sync.py new file mode 100644 index 0000000..b3a29f4 --- /dev/null +++ b/samples/generated_samples/cloudshell_generated_shell_v1_cloud_shell_service_start_environment_sync.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for StartEnvironment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-shell + + +# [START cloudshell_generated_shell_v1_CloudShellService_StartEnvironment_sync] +from google.cloud import shell_v1 + + +def sample_start_environment(): + # Create a client + client = shell_v1.CloudShellServiceClient() + + # Initialize request argument(s) + request = shell_v1.StartEnvironmentRequest( + ) + + # Make the request + operation = client.start_environment(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END cloudshell_generated_shell_v1_CloudShellService_StartEnvironment_sync] diff --git a/samples/generated_samples/snippet_metadata_shell_v1.json b/samples/generated_samples/snippet_metadata_shell_v1.json new file mode 100644 index 0000000..46a9138 --- /dev/null +++ b/samples/generated_samples/snippet_metadata_shell_v1.json @@ -0,0 +1,449 @@ +{ + "snippets": [ + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "CloudShellService" + }, + "shortName": "AddPublicKey" + } + }, + "file": "cloudshell_generated_shell_v1_cloud_shell_service_add_public_key_async.py", + "regionTag": "cloudshell_generated_shell_v1_CloudShellService_AddPublicKey_async", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "CloudShellService" + }, + "shortName": "AddPublicKey" + } + }, + "file": "cloudshell_generated_shell_v1_cloud_shell_service_add_public_key_sync.py", + "regionTag": "cloudshell_generated_shell_v1_CloudShellService_AddPublicKey_sync", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "CloudShellService" + }, + "shortName": "AuthorizeEnvironment" + } + }, + "file": "cloudshell_generated_shell_v1_cloud_shell_service_authorize_environment_async.py", + "regionTag": "cloudshell_generated_shell_v1_CloudShellService_AuthorizeEnvironment_async", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "CloudShellService" + }, + "shortName": "AuthorizeEnvironment" + } + }, + "file": "cloudshell_generated_shell_v1_cloud_shell_service_authorize_environment_sync.py", + "regionTag": "cloudshell_generated_shell_v1_CloudShellService_AuthorizeEnvironment_sync", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "CloudShellService" + }, + "shortName": "GetEnvironment" + } + }, + "file": "cloudshell_generated_shell_v1_cloud_shell_service_get_environment_async.py", + "regionTag": "cloudshell_generated_shell_v1_CloudShellService_GetEnvironment_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "CloudShellService" + }, + "shortName": "GetEnvironment" + } + }, + "file": "cloudshell_generated_shell_v1_cloud_shell_service_get_environment_sync.py", + "regionTag": "cloudshell_generated_shell_v1_CloudShellService_GetEnvironment_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "CloudShellService" + }, + "shortName": "RemovePublicKey" + } + }, + "file": "cloudshell_generated_shell_v1_cloud_shell_service_remove_public_key_async.py", + "regionTag": "cloudshell_generated_shell_v1_CloudShellService_RemovePublicKey_async", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "CloudShellService" + }, + "shortName": "RemovePublicKey" + } + }, + "file": "cloudshell_generated_shell_v1_cloud_shell_service_remove_public_key_sync.py", + "regionTag": "cloudshell_generated_shell_v1_CloudShellService_RemovePublicKey_sync", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "CloudShellService" + }, + "shortName": "StartEnvironment" + } + }, + "file": "cloudshell_generated_shell_v1_cloud_shell_service_start_environment_async.py", + "regionTag": "cloudshell_generated_shell_v1_CloudShellService_StartEnvironment_async", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "CloudShellService" + }, + "shortName": "StartEnvironment" + } + }, + "file": "cloudshell_generated_shell_v1_cloud_shell_service_start_environment_sync.py", + "regionTag": "cloudshell_generated_shell_v1_CloudShellService_StartEnvironment_sync", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + } + ] +} diff --git a/setup.py b/setup.py index 8aaec78..41e426e 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ name = "google-cloud-shell" description = "Cloud Shell API client library" -version = "1.3.0" +version = "1.3.1" release_status = "Development Status :: 5 - Production/Stable" url = "https://github.com/googleapis/python-shell" dependencies = [ diff --git a/tests/unit/gapic/shell_v1/test_cloud_shell_service.py b/tests/unit/gapic/shell_v1/test_cloud_shell_service.py index 0c38933..f857410 100644 --- a/tests/unit/gapic/shell_v1/test_cloud_shell_service.py +++ b/tests/unit/gapic/shell_v1/test_cloud_shell_service.py @@ -29,6 +29,7 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import operation from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 from google.api_core import path_template @@ -525,21 +526,28 @@ def test_cloud_shell_service_client_client_options_scopes( @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (CloudShellServiceClient, transports.CloudShellServiceGrpcTransport, "grpc"), + ( + CloudShellServiceClient, + transports.CloudShellServiceGrpcTransport, + "grpc", + grpc_helpers, + ), ( CloudShellServiceAsyncClient, transports.CloudShellServiceGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_cloud_shell_service_client_client_options_credentials_file( - client_class, transport_class, transport_name + client_class, transport_class, transport_name, grpc_helpers ): # Check the case credentials file is provided. options = client_options.ClientOptions(credentials_file="credentials.json") + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None client = client_class(client_options=options, transport=transport_name) @@ -575,6 +583,72 @@ def test_cloud_shell_service_client_client_options_from_dict(): ) +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + CloudShellServiceClient, + transports.CloudShellServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + CloudShellServiceAsyncClient, + transports.CloudShellServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_cloud_shell_service_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers +): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "cloudshell.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="cloudshell.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + @pytest.mark.parametrize("request_type", [cloudshell.GetEnvironmentRequest, dict,]) def test_get_environment(request_type, transport: str = "grpc"): client = CloudShellServiceClient(