diff --git a/CHANGELOG.md b/CHANGELOG.md index 7573edc..37e60f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +### [2.7.1](https://github.com/googleapis/python-containeranalysis/compare/v2.7.0...v2.7.1) (2022-02-11) + + +### Bug Fixes + +* resolve DuplicateCredentialArgs error when using credentials_file ([fecf484](https://github.com/googleapis/python-containeranalysis/commit/fecf4844db8e44a12f3ea42af7663196177a6b1a)) + ## [2.7.0](https://github.com/googleapis/python-containeranalysis/compare/v2.6.3...v2.7.0) (2022-01-25) diff --git a/google/cloud/devtools/containeranalysis_v1/services/container_analysis/async_client.py b/google/cloud/devtools/containeranalysis_v1/services/container_analysis/async_client.py index 3969923..5c9a872 100644 --- a/google/cloud/devtools/containeranalysis_v1/services/container_analysis/async_client.py +++ b/google/cloud/devtools/containeranalysis_v1/services/container_analysis/async_client.py @@ -248,6 +248,26 @@ async def set_iam_policy( ``projects/[PROJECT_ID]/occurrences/[OCCURRENCE_ID]`` for occurrences. + + .. code-block:: + + from google.cloud.devtools import containeranalysis_v1 + + def sample_set_iam_policy(): + # Create a client + client = containeranalysis_v1.ContainerAnalysisClient() + + # Initialize request argument(s) + request = containeranalysis_v1.SetIamPolicyRequest( + resource="resource_value", + ) + + # Make the request + response = client.set_iam_policy(request=request) + + # Handle the response + print(response) + Args: request (Union[google.iam.v1.iam_policy_pb2.SetIamPolicyRequest, dict]): The request object. Request message for `SetIamPolicy` @@ -327,7 +347,7 @@ async def set_iam_policy( """ # 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([resource]) if request is not None and has_flattened_params: @@ -382,6 +402,26 @@ async def get_iam_policy( ``projects/[PROJECT_ID]/occurrences/[OCCURRENCE_ID]`` for occurrences. + + .. code-block:: + + from google.cloud.devtools import containeranalysis_v1 + + def sample_get_iam_policy(): + # Create a client + client = containeranalysis_v1.ContainerAnalysisClient() + + # Initialize request argument(s) + request = containeranalysis_v1.GetIamPolicyRequest( + resource="resource_value", + ) + + # Make the request + response = client.get_iam_policy(request=request) + + # Handle the response + print(response) + Args: request (Union[google.iam.v1.iam_policy_pb2.GetIamPolicyRequest, dict]): The request object. Request message for `GetIamPolicy` @@ -461,7 +501,7 @@ async def get_iam_policy( """ # 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([resource]) if request is not None and has_flattened_params: @@ -516,6 +556,27 @@ async def test_iam_permissions( ``projects/[PROJECT_ID]/occurrences/[OCCURRENCE_ID]`` for occurrences. + + .. code-block:: + + from google.cloud.devtools import containeranalysis_v1 + + def sample_test_iam_permissions(): + # Create a client + client = containeranalysis_v1.ContainerAnalysisClient() + + # Initialize request argument(s) + request = containeranalysis_v1.TestIamPermissionsRequest( + resource="resource_value", + permissions=['permissions_value_1', 'permissions_value_2'], + ) + + # Make the request + response = client.test_iam_permissions(request=request) + + # Handle the response + print(response) + Args: request (Union[google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest, dict]): The request object. Request message for @@ -549,7 +610,7 @@ async def test_iam_permissions( Response message for TestIamPermissions method. """ # 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([resource, permissions]) if request is not None and has_flattened_params: @@ -602,6 +663,26 @@ async def get_vulnerability_occurrences_summary( r"""Gets a summary of the number and severity of occurrences. + + .. code-block:: + + from google.cloud.devtools import containeranalysis_v1 + + def sample_get_vulnerability_occurrences_summary(): + # Create a client + client = containeranalysis_v1.ContainerAnalysisClient() + + # Initialize request argument(s) + request = containeranalysis_v1.GetVulnerabilityOccurrencesSummaryRequest( + parent="parent_value", + ) + + # Make the request + response = client.get_vulnerability_occurrences_summary(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.devtools.containeranalysis_v1.types.GetVulnerabilityOccurrencesSummaryRequest, dict]): The request object. Request to get a vulnerability @@ -632,7 +713,7 @@ async def get_vulnerability_occurrences_summary( """ # 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([parent, filter]) if request is not None and has_flattened_params: diff --git a/google/cloud/devtools/containeranalysis_v1/services/container_analysis/client.py b/google/cloud/devtools/containeranalysis_v1/services/container_analysis/client.py index f20929a..d3f952b 100644 --- a/google/cloud/devtools/containeranalysis_v1/services/container_analysis/client.py +++ b/google/cloud/devtools/containeranalysis_v1/services/container_analysis/client.py @@ -433,6 +433,27 @@ def set_iam_policy( ``projects/[PROJECT_ID]/occurrences/[OCCURRENCE_ID]`` for occurrences. + + + .. code-block:: + + from google.cloud.devtools import containeranalysis_v1 + + def sample_set_iam_policy(): + # Create a client + client = containeranalysis_v1.ContainerAnalysisClient() + + # Initialize request argument(s) + request = containeranalysis_v1.SetIamPolicyRequest( + resource="resource_value", + ) + + # Make the request + response = client.set_iam_policy(request=request) + + # Handle the response + print(response) + Args: request (Union[google.iam.v1.iam_policy_pb2.SetIamPolicyRequest, dict]): The request object. Request message for `SetIamPolicy` @@ -512,7 +533,7 @@ def set_iam_policy( """ # 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([resource]) if request is not None and has_flattened_params: @@ -566,6 +587,27 @@ def get_iam_policy( ``projects/[PROJECT_ID]/occurrences/[OCCURRENCE_ID]`` for occurrences. + + + .. code-block:: + + from google.cloud.devtools import containeranalysis_v1 + + def sample_get_iam_policy(): + # Create a client + client = containeranalysis_v1.ContainerAnalysisClient() + + # Initialize request argument(s) + request = containeranalysis_v1.GetIamPolicyRequest( + resource="resource_value", + ) + + # Make the request + response = client.get_iam_policy(request=request) + + # Handle the response + print(response) + Args: request (Union[google.iam.v1.iam_policy_pb2.GetIamPolicyRequest, dict]): The request object. Request message for `GetIamPolicy` @@ -645,7 +687,7 @@ def get_iam_policy( """ # 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([resource]) if request is not None and has_flattened_params: @@ -699,6 +741,28 @@ def test_iam_permissions( ``projects/[PROJECT_ID]/occurrences/[OCCURRENCE_ID]`` for occurrences. + + + .. code-block:: + + from google.cloud.devtools import containeranalysis_v1 + + def sample_test_iam_permissions(): + # Create a client + client = containeranalysis_v1.ContainerAnalysisClient() + + # Initialize request argument(s) + request = containeranalysis_v1.TestIamPermissionsRequest( + resource="resource_value", + permissions=['permissions_value_1', 'permissions_value_2'], + ) + + # Make the request + response = client.test_iam_permissions(request=request) + + # Handle the response + print(response) + Args: request (Union[google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest, dict]): The request object. Request message for @@ -732,7 +796,7 @@ def test_iam_permissions( Response message for TestIamPermissions method. """ # 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([resource, permissions]) if request is not None and has_flattened_params: @@ -784,6 +848,27 @@ def get_vulnerability_occurrences_summary( r"""Gets a summary of the number and severity of occurrences. + + + .. code-block:: + + from google.cloud.devtools import containeranalysis_v1 + + def sample_get_vulnerability_occurrences_summary(): + # Create a client + client = containeranalysis_v1.ContainerAnalysisClient() + + # Initialize request argument(s) + request = containeranalysis_v1.GetVulnerabilityOccurrencesSummaryRequest( + parent="parent_value", + ) + + # Make the request + response = client.get_vulnerability_occurrences_summary(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.devtools.containeranalysis_v1.types.GetVulnerabilityOccurrencesSummaryRequest, dict]): The request object. Request to get a vulnerability @@ -814,7 +899,7 @@ def get_vulnerability_occurrences_summary( """ # 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([parent, filter]) if request is not None and has_flattened_params: diff --git a/google/cloud/devtools/containeranalysis_v1/services/container_analysis/transports/grpc.py b/google/cloud/devtools/containeranalysis_v1/services/container_analysis/transports/grpc.py index d74b00a..105d62d 100644 --- a/google/cloud/devtools/containeranalysis_v1/services/container_analysis/transports/grpc.py +++ b/google/cloud/devtools/containeranalysis_v1/services/container_analysis/transports/grpc.py @@ -174,8 +174,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, diff --git a/google/cloud/devtools/containeranalysis_v1/services/container_analysis/transports/grpc_asyncio.py b/google/cloud/devtools/containeranalysis_v1/services/container_analysis/transports/grpc_asyncio.py index d31bc85..234982c 100644 --- a/google/cloud/devtools/containeranalysis_v1/services/container_analysis/transports/grpc_asyncio.py +++ b/google/cloud/devtools/containeranalysis_v1/services/container_analysis/transports/grpc_asyncio.py @@ -219,8 +219,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, diff --git a/samples/generated_samples/containeranalysis_generated_containeranalysis_v1_container_analysis_get_iam_policy_async.py b/samples/generated_samples/containeranalysis_generated_containeranalysis_v1_container_analysis_get_iam_policy_async.py new file mode 100644 index 0000000..2b0eb56 --- /dev/null +++ b/samples/generated_samples/containeranalysis_generated_containeranalysis_v1_container_analysis_get_iam_policy_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 GetIamPolicy +# 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-devtools-containeranalysis + + +# [START containeranalysis_generated_containeranalysis_v1_ContainerAnalysis_GetIamPolicy_async] +from google.cloud.devtools import containeranalysis_v1 + + +async def sample_get_iam_policy(): + # Create a client + client = containeranalysis_v1.ContainerAnalysisAsyncClient() + + # Initialize request argument(s) + request = containeranalysis_v1.GetIamPolicyRequest( + resource="resource_value", + ) + + # Make the request + response = await client.get_iam_policy(request=request) + + # Handle the response + print(response) + +# [END containeranalysis_generated_containeranalysis_v1_ContainerAnalysis_GetIamPolicy_async] diff --git a/samples/generated_samples/containeranalysis_generated_containeranalysis_v1_container_analysis_get_iam_policy_sync.py b/samples/generated_samples/containeranalysis_generated_containeranalysis_v1_container_analysis_get_iam_policy_sync.py new file mode 100644 index 0000000..6f34fc4 --- /dev/null +++ b/samples/generated_samples/containeranalysis_generated_containeranalysis_v1_container_analysis_get_iam_policy_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 GetIamPolicy +# 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-devtools-containeranalysis + + +# [START containeranalysis_generated_containeranalysis_v1_ContainerAnalysis_GetIamPolicy_sync] +from google.cloud.devtools import containeranalysis_v1 + + +def sample_get_iam_policy(): + # Create a client + client = containeranalysis_v1.ContainerAnalysisClient() + + # Initialize request argument(s) + request = containeranalysis_v1.GetIamPolicyRequest( + resource="resource_value", + ) + + # Make the request + response = client.get_iam_policy(request=request) + + # Handle the response + print(response) + +# [END containeranalysis_generated_containeranalysis_v1_ContainerAnalysis_GetIamPolicy_sync] diff --git a/samples/generated_samples/containeranalysis_generated_containeranalysis_v1_container_analysis_get_vulnerability_occurrences_summary_async.py b/samples/generated_samples/containeranalysis_generated_containeranalysis_v1_container_analysis_get_vulnerability_occurrences_summary_async.py new file mode 100644 index 0000000..5c5a3cf --- /dev/null +++ b/samples/generated_samples/containeranalysis_generated_containeranalysis_v1_container_analysis_get_vulnerability_occurrences_summary_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 GetVulnerabilityOccurrencesSummary +# 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-devtools-containeranalysis + + +# [START containeranalysis_generated_containeranalysis_v1_ContainerAnalysis_GetVulnerabilityOccurrencesSummary_async] +from google.cloud.devtools import containeranalysis_v1 + + +async def sample_get_vulnerability_occurrences_summary(): + # Create a client + client = containeranalysis_v1.ContainerAnalysisAsyncClient() + + # Initialize request argument(s) + request = containeranalysis_v1.GetVulnerabilityOccurrencesSummaryRequest( + parent="parent_value", + ) + + # Make the request + response = await client.get_vulnerability_occurrences_summary(request=request) + + # Handle the response + print(response) + +# [END containeranalysis_generated_containeranalysis_v1_ContainerAnalysis_GetVulnerabilityOccurrencesSummary_async] diff --git a/samples/generated_samples/containeranalysis_generated_containeranalysis_v1_container_analysis_get_vulnerability_occurrences_summary_sync.py b/samples/generated_samples/containeranalysis_generated_containeranalysis_v1_container_analysis_get_vulnerability_occurrences_summary_sync.py new file mode 100644 index 0000000..61b32c5 --- /dev/null +++ b/samples/generated_samples/containeranalysis_generated_containeranalysis_v1_container_analysis_get_vulnerability_occurrences_summary_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 GetVulnerabilityOccurrencesSummary +# 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-devtools-containeranalysis + + +# [START containeranalysis_generated_containeranalysis_v1_ContainerAnalysis_GetVulnerabilityOccurrencesSummary_sync] +from google.cloud.devtools import containeranalysis_v1 + + +def sample_get_vulnerability_occurrences_summary(): + # Create a client + client = containeranalysis_v1.ContainerAnalysisClient() + + # Initialize request argument(s) + request = containeranalysis_v1.GetVulnerabilityOccurrencesSummaryRequest( + parent="parent_value", + ) + + # Make the request + response = client.get_vulnerability_occurrences_summary(request=request) + + # Handle the response + print(response) + +# [END containeranalysis_generated_containeranalysis_v1_ContainerAnalysis_GetVulnerabilityOccurrencesSummary_sync] diff --git a/samples/generated_samples/containeranalysis_generated_containeranalysis_v1_container_analysis_set_iam_policy_async.py b/samples/generated_samples/containeranalysis_generated_containeranalysis_v1_container_analysis_set_iam_policy_async.py new file mode 100644 index 0000000..a93e73b --- /dev/null +++ b/samples/generated_samples/containeranalysis_generated_containeranalysis_v1_container_analysis_set_iam_policy_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 SetIamPolicy +# 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-devtools-containeranalysis + + +# [START containeranalysis_generated_containeranalysis_v1_ContainerAnalysis_SetIamPolicy_async] +from google.cloud.devtools import containeranalysis_v1 + + +async def sample_set_iam_policy(): + # Create a client + client = containeranalysis_v1.ContainerAnalysisAsyncClient() + + # Initialize request argument(s) + request = containeranalysis_v1.SetIamPolicyRequest( + resource="resource_value", + ) + + # Make the request + response = await client.set_iam_policy(request=request) + + # Handle the response + print(response) + +# [END containeranalysis_generated_containeranalysis_v1_ContainerAnalysis_SetIamPolicy_async] diff --git a/samples/generated_samples/containeranalysis_generated_containeranalysis_v1_container_analysis_set_iam_policy_sync.py b/samples/generated_samples/containeranalysis_generated_containeranalysis_v1_container_analysis_set_iam_policy_sync.py new file mode 100644 index 0000000..9651d81 --- /dev/null +++ b/samples/generated_samples/containeranalysis_generated_containeranalysis_v1_container_analysis_set_iam_policy_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 SetIamPolicy +# 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-devtools-containeranalysis + + +# [START containeranalysis_generated_containeranalysis_v1_ContainerAnalysis_SetIamPolicy_sync] +from google.cloud.devtools import containeranalysis_v1 + + +def sample_set_iam_policy(): + # Create a client + client = containeranalysis_v1.ContainerAnalysisClient() + + # Initialize request argument(s) + request = containeranalysis_v1.SetIamPolicyRequest( + resource="resource_value", + ) + + # Make the request + response = client.set_iam_policy(request=request) + + # Handle the response + print(response) + +# [END containeranalysis_generated_containeranalysis_v1_ContainerAnalysis_SetIamPolicy_sync] diff --git a/samples/generated_samples/containeranalysis_generated_containeranalysis_v1_container_analysis_test_iam_permissions_async.py b/samples/generated_samples/containeranalysis_generated_containeranalysis_v1_container_analysis_test_iam_permissions_async.py new file mode 100644 index 0000000..614918c --- /dev/null +++ b/samples/generated_samples/containeranalysis_generated_containeranalysis_v1_container_analysis_test_iam_permissions_async.py @@ -0,0 +1,46 @@ +# -*- 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 TestIamPermissions +# 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-devtools-containeranalysis + + +# [START containeranalysis_generated_containeranalysis_v1_ContainerAnalysis_TestIamPermissions_async] +from google.cloud.devtools import containeranalysis_v1 + + +async def sample_test_iam_permissions(): + # Create a client + client = containeranalysis_v1.ContainerAnalysisAsyncClient() + + # Initialize request argument(s) + request = containeranalysis_v1.TestIamPermissionsRequest( + resource="resource_value", + permissions=['permissions_value_1', 'permissions_value_2'], + ) + + # Make the request + response = await client.test_iam_permissions(request=request) + + # Handle the response + print(response) + +# [END containeranalysis_generated_containeranalysis_v1_ContainerAnalysis_TestIamPermissions_async] diff --git a/samples/generated_samples/containeranalysis_generated_containeranalysis_v1_container_analysis_test_iam_permissions_sync.py b/samples/generated_samples/containeranalysis_generated_containeranalysis_v1_container_analysis_test_iam_permissions_sync.py new file mode 100644 index 0000000..af34e08 --- /dev/null +++ b/samples/generated_samples/containeranalysis_generated_containeranalysis_v1_container_analysis_test_iam_permissions_sync.py @@ -0,0 +1,46 @@ +# -*- 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 TestIamPermissions +# 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-devtools-containeranalysis + + +# [START containeranalysis_generated_containeranalysis_v1_ContainerAnalysis_TestIamPermissions_sync] +from google.cloud.devtools import containeranalysis_v1 + + +def sample_test_iam_permissions(): + # Create a client + client = containeranalysis_v1.ContainerAnalysisClient() + + # Initialize request argument(s) + request = containeranalysis_v1.TestIamPermissionsRequest( + resource="resource_value", + permissions=['permissions_value_1', 'permissions_value_2'], + ) + + # Make the request + response = client.test_iam_permissions(request=request) + + # Handle the response + print(response) + +# [END containeranalysis_generated_containeranalysis_v1_ContainerAnalysis_TestIamPermissions_sync] diff --git a/samples/generated_samples/snippet_metadata_containeranalysis_v1.json b/samples/generated_samples/snippet_metadata_containeranalysis_v1.json new file mode 100644 index 0000000..7e86c69 --- /dev/null +++ b/samples/generated_samples/snippet_metadata_containeranalysis_v1.json @@ -0,0 +1,360 @@ +{ + "snippets": [ + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ContainerAnalysis" + }, + "shortName": "GetIamPolicy" + } + }, + "file": "containeranalysis_generated_containeranalysis_v1_container_analysis_get_iam_policy_async.py", + "regionTag": "containeranalysis_generated_containeranalysis_v1_ContainerAnalysis_GetIamPolicy_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": "ContainerAnalysis" + }, + "shortName": "GetIamPolicy" + } + }, + "file": "containeranalysis_generated_containeranalysis_v1_container_analysis_get_iam_policy_sync.py", + "regionTag": "containeranalysis_generated_containeranalysis_v1_ContainerAnalysis_GetIamPolicy_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": "ContainerAnalysis" + }, + "shortName": "GetVulnerabilityOccurrencesSummary" + } + }, + "file": "containeranalysis_generated_containeranalysis_v1_container_analysis_get_vulnerability_occurrences_summary_async.py", + "regionTag": "containeranalysis_generated_containeranalysis_v1_ContainerAnalysis_GetVulnerabilityOccurrencesSummary_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": "ContainerAnalysis" + }, + "shortName": "GetVulnerabilityOccurrencesSummary" + } + }, + "file": "containeranalysis_generated_containeranalysis_v1_container_analysis_get_vulnerability_occurrences_summary_sync.py", + "regionTag": "containeranalysis_generated_containeranalysis_v1_ContainerAnalysis_GetVulnerabilityOccurrencesSummary_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": "ContainerAnalysis" + }, + "shortName": "SetIamPolicy" + } + }, + "file": "containeranalysis_generated_containeranalysis_v1_container_analysis_set_iam_policy_async.py", + "regionTag": "containeranalysis_generated_containeranalysis_v1_ContainerAnalysis_SetIamPolicy_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": "ContainerAnalysis" + }, + "shortName": "SetIamPolicy" + } + }, + "file": "containeranalysis_generated_containeranalysis_v1_container_analysis_set_iam_policy_sync.py", + "regionTag": "containeranalysis_generated_containeranalysis_v1_ContainerAnalysis_SetIamPolicy_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": "ContainerAnalysis" + }, + "shortName": "TestIamPermissions" + } + }, + "file": "containeranalysis_generated_containeranalysis_v1_container_analysis_test_iam_permissions_async.py", + "regionTag": "containeranalysis_generated_containeranalysis_v1_ContainerAnalysis_TestIamPermissions_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "ContainerAnalysis" + }, + "shortName": "TestIamPermissions" + } + }, + "file": "containeranalysis_generated_containeranalysis_v1_container_analysis_test_iam_permissions_sync.py", + "regionTag": "containeranalysis_generated_containeranalysis_v1_ContainerAnalysis_TestIamPermissions_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ] + } + ] +} diff --git a/samples/snippets/requirements-test.txt b/samples/snippets/requirements-test.txt index 9270945..c2845bf 100644 --- a/samples/snippets/requirements-test.txt +++ b/samples/snippets/requirements-test.txt @@ -1 +1 @@ -pytest==6.2.5 +pytest==7.0.1 diff --git a/samples/snippets/requirements.txt b/samples/snippets/requirements.txt index 67f01a1..d12d241 100644 --- a/samples/snippets/requirements.txt +++ b/samples/snippets/requirements.txt @@ -1,6 +1,6 @@ google-cloud-pubsub==2.9.0 -google-cloud-containeranalysis==2.6.3 +google-cloud-containeranalysis==2.7.0 grafeas==1.4.1 -pytest==6.2.5 +pytest==7.0.1 flaky==3.7.0 mock==4.0.3 diff --git a/setup.py b/setup.py index c08edb6..842ee5b 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ name = "google-cloud-containeranalysis" description = "Container Analysis API API client library" -version = "2.7.0" +version = "2.7.1" release_status = "Development Status :: 5 - Production/Stable" dependencies = [ # NOTE: Maintainers, please do not require google-api-core>=2.x.x diff --git a/tests/unit/gapic/containeranalysis_v1/test_container_analysis.py b/tests/unit/gapic/containeranalysis_v1/test_container_analysis.py index a8aafb0..3583384 100644 --- a/tests/unit/gapic/containeranalysis_v1/test_container_analysis.py +++ b/tests/unit/gapic/containeranalysis_v1/test_container_analysis.py @@ -528,21 +528,28 @@ def test_container_analysis_client_client_options_scopes( @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (ContainerAnalysisClient, transports.ContainerAnalysisGrpcTransport, "grpc"), + ( + ContainerAnalysisClient, + transports.ContainerAnalysisGrpcTransport, + "grpc", + grpc_helpers, + ), ( ContainerAnalysisAsyncClient, transports.ContainerAnalysisGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_container_analysis_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) @@ -578,6 +585,72 @@ def test_container_analysis_client_client_options_from_dict(): ) +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + ContainerAnalysisClient, + transports.ContainerAnalysisGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + ContainerAnalysisAsyncClient, + transports.ContainerAnalysisGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_container_analysis_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( + "containeranalysis.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="containeranalysis.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + @pytest.mark.parametrize("request_type", [iam_policy_pb2.SetIamPolicyRequest, dict,]) def test_set_iam_policy(request_type, transport: str = "grpc"): client = ContainerAnalysisClient(