diff --git a/.kokoro/test-samples.sh b/.kokoro/test-samples.sh index ec890026..b6bc8297 100755 --- a/.kokoro/test-samples.sh +++ b/.kokoro/test-samples.sh @@ -87,11 +87,11 @@ for file in samples/**/requirements.txt; do python3.6 -m nox -s "$RUN_TESTS_SESSION" EXIT=$? - # If this is a periodic build, send the test log to the FlakyBot. - # See https://github.com/googleapis/repo-automation-bots/tree/master/packages/flakybot. + # If this is a periodic build, send the test log to the Build Cop Bot. + # See https://github.com/googleapis/repo-automation-bots/tree/master/packages/buildcop. if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"periodic"* ]]; then - chmod +x $KOKORO_GFILE_DIR/linux_amd64/flakybot - $KOKORO_GFILE_DIR/linux_amd64/flakybot + chmod +x $KOKORO_GFILE_DIR/linux_amd64/buildcop + $KOKORO_GFILE_DIR/linux_amd64/buildcop fi if [[ $EXIT -ne 0 ]]; then diff --git a/.kokoro/trampoline_v2.sh b/.kokoro/trampoline_v2.sh index 4af6cdc2..719bcd5b 100755 --- a/.kokoro/trampoline_v2.sh +++ b/.kokoro/trampoline_v2.sh @@ -159,7 +159,7 @@ if [[ -n "${KOKORO_BUILD_ID:-}" ]]; then "KOKORO_GITHUB_COMMIT" "KOKORO_GITHUB_PULL_REQUEST_NUMBER" "KOKORO_GITHUB_PULL_REQUEST_COMMIT" - # For FlakyBot + # For Build Cop Bot "KOKORO_GITHUB_COMMIT_URL" "KOKORO_GITHUB_PULL_REQUEST_URL" ) diff --git a/docs/vision_v1/image_annotator.rst b/docs/vision_v1/image_annotator.rst new file mode 100644 index 00000000..83130a76 --- /dev/null +++ b/docs/vision_v1/image_annotator.rst @@ -0,0 +1,6 @@ +ImageAnnotator +-------------------------------- + +.. automodule:: google.cloud.vision_v1.services.image_annotator + :members: + :inherited-members: diff --git a/docs/vision_v1/product_search.rst b/docs/vision_v1/product_search.rst new file mode 100644 index 00000000..64e5cd02 --- /dev/null +++ b/docs/vision_v1/product_search.rst @@ -0,0 +1,11 @@ +ProductSearch +------------------------------- + +.. automodule:: google.cloud.vision_v1.services.product_search + :members: + :inherited-members: + + +.. automodule:: google.cloud.vision_v1.services.product_search.pagers + :members: + :inherited-members: diff --git a/docs/vision_v1/services.rst b/docs/vision_v1/services.rst index 0331ec53..5fe11bc5 100644 --- a/docs/vision_v1/services.rst +++ b/docs/vision_v1/services.rst @@ -1,9 +1,7 @@ Services for Google Cloud Vision v1 API ======================================= +.. toctree:: + :maxdepth: 2 -.. automodule:: google.cloud.vision_v1.services.image_annotator - :members: - :inherited-members: -.. automodule:: google.cloud.vision_v1.services.product_search - :members: - :inherited-members: + image_annotator + product_search diff --git a/docs/vision_v1/types.rst b/docs/vision_v1/types.rst index dbbb594c..52d9869b 100644 --- a/docs/vision_v1/types.rst +++ b/docs/vision_v1/types.rst @@ -3,4 +3,5 @@ Types for Google Cloud Vision v1 API .. automodule:: google.cloud.vision_v1.types :members: + :undoc-members: :show-inheritance: diff --git a/docs/vision_v1p2beta1/image_annotator.rst b/docs/vision_v1p2beta1/image_annotator.rst new file mode 100644 index 00000000..d05fd549 --- /dev/null +++ b/docs/vision_v1p2beta1/image_annotator.rst @@ -0,0 +1,6 @@ +ImageAnnotator +-------------------------------- + +.. automodule:: google.cloud.vision_v1p2beta1.services.image_annotator + :members: + :inherited-members: diff --git a/docs/vision_v1p2beta1/services.rst b/docs/vision_v1p2beta1/services.rst index 55dc030c..2272ceb5 100644 --- a/docs/vision_v1p2beta1/services.rst +++ b/docs/vision_v1p2beta1/services.rst @@ -1,6 +1,6 @@ Services for Google Cloud Vision v1p2beta1 API ============================================== +.. toctree:: + :maxdepth: 2 -.. automodule:: google.cloud.vision_v1p2beta1.services.image_annotator - :members: - :inherited-members: + image_annotator diff --git a/docs/vision_v1p2beta1/types.rst b/docs/vision_v1p2beta1/types.rst index 898a797f..33ab32e0 100644 --- a/docs/vision_v1p2beta1/types.rst +++ b/docs/vision_v1p2beta1/types.rst @@ -3,4 +3,5 @@ Types for Google Cloud Vision v1p2beta1 API .. automodule:: google.cloud.vision_v1p2beta1.types :members: + :undoc-members: :show-inheritance: diff --git a/docs/vision_v1p3beta1/image_annotator.rst b/docs/vision_v1p3beta1/image_annotator.rst new file mode 100644 index 00000000..a5ed7542 --- /dev/null +++ b/docs/vision_v1p3beta1/image_annotator.rst @@ -0,0 +1,6 @@ +ImageAnnotator +-------------------------------- + +.. automodule:: google.cloud.vision_v1p3beta1.services.image_annotator + :members: + :inherited-members: diff --git a/docs/vision_v1p3beta1/product_search.rst b/docs/vision_v1p3beta1/product_search.rst new file mode 100644 index 00000000..fd321a60 --- /dev/null +++ b/docs/vision_v1p3beta1/product_search.rst @@ -0,0 +1,11 @@ +ProductSearch +------------------------------- + +.. automodule:: google.cloud.vision_v1p3beta1.services.product_search + :members: + :inherited-members: + + +.. automodule:: google.cloud.vision_v1p3beta1.services.product_search.pagers + :members: + :inherited-members: diff --git a/docs/vision_v1p3beta1/services.rst b/docs/vision_v1p3beta1/services.rst index 591da113..06da9b3d 100644 --- a/docs/vision_v1p3beta1/services.rst +++ b/docs/vision_v1p3beta1/services.rst @@ -1,9 +1,7 @@ Services for Google Cloud Vision v1p3beta1 API ============================================== +.. toctree:: + :maxdepth: 2 -.. automodule:: google.cloud.vision_v1p3beta1.services.image_annotator - :members: - :inherited-members: -.. automodule:: google.cloud.vision_v1p3beta1.services.product_search - :members: - :inherited-members: + image_annotator + product_search diff --git a/docs/vision_v1p3beta1/types.rst b/docs/vision_v1p3beta1/types.rst index 8f60a298..5fdbaea1 100644 --- a/docs/vision_v1p3beta1/types.rst +++ b/docs/vision_v1p3beta1/types.rst @@ -3,4 +3,5 @@ Types for Google Cloud Vision v1p3beta1 API .. automodule:: google.cloud.vision_v1p3beta1.types :members: + :undoc-members: :show-inheritance: diff --git a/docs/vision_v1p4beta1/image_annotator.rst b/docs/vision_v1p4beta1/image_annotator.rst new file mode 100644 index 00000000..28717262 --- /dev/null +++ b/docs/vision_v1p4beta1/image_annotator.rst @@ -0,0 +1,6 @@ +ImageAnnotator +-------------------------------- + +.. automodule:: google.cloud.vision_v1p4beta1.services.image_annotator + :members: + :inherited-members: diff --git a/docs/vision_v1p4beta1/product_search.rst b/docs/vision_v1p4beta1/product_search.rst new file mode 100644 index 00000000..e46b54b0 --- /dev/null +++ b/docs/vision_v1p4beta1/product_search.rst @@ -0,0 +1,11 @@ +ProductSearch +------------------------------- + +.. automodule:: google.cloud.vision_v1p4beta1.services.product_search + :members: + :inherited-members: + + +.. automodule:: google.cloud.vision_v1p4beta1.services.product_search.pagers + :members: + :inherited-members: diff --git a/docs/vision_v1p4beta1/services.rst b/docs/vision_v1p4beta1/services.rst index e8da2e62..2ebd0bbc 100644 --- a/docs/vision_v1p4beta1/services.rst +++ b/docs/vision_v1p4beta1/services.rst @@ -1,9 +1,7 @@ Services for Google Cloud Vision v1p4beta1 API ============================================== +.. toctree:: + :maxdepth: 2 -.. automodule:: google.cloud.vision_v1p4beta1.services.image_annotator - :members: - :inherited-members: -.. automodule:: google.cloud.vision_v1p4beta1.services.product_search - :members: - :inherited-members: + image_annotator + product_search diff --git a/docs/vision_v1p4beta1/types.rst b/docs/vision_v1p4beta1/types.rst index 214f01b1..a90d1fa2 100644 --- a/docs/vision_v1p4beta1/types.rst +++ b/docs/vision_v1p4beta1/types.rst @@ -3,4 +3,5 @@ Types for Google Cloud Vision v1p4beta1 API .. automodule:: google.cloud.vision_v1p4beta1.types :members: + :undoc-members: :show-inheritance: diff --git a/google/cloud/vision_v1/__init__.py b/google/cloud/vision_v1/__init__.py index 8b1d075a..df7114a8 100644 --- a/google/cloud/vision_v1/__init__.py +++ b/google/cloud/vision_v1/__init__.py @@ -152,7 +152,6 @@ class ImageAnnotatorClient(VisionHelpers, IacImageAnnotatorClient): "GetReferenceImageRequest", "Image", "ImageAnnotationContext", - "ImageAnnotatorClient", "ImageContext", "ImageProperties", "ImageSource", @@ -180,6 +179,7 @@ class ImageAnnotatorClient(VisionHelpers, IacImageAnnotatorClient): "Paragraph", "Position", "Product", + "ProductSearchClient", "ProductSearchParams", "ProductSearchResults", "ProductSet", @@ -198,5 +198,5 @@ class ImageAnnotatorClient(VisionHelpers, IacImageAnnotatorClient): "WebDetection", "WebDetectionParams", "Word", - "ProductSearchClient", + "ImageAnnotatorClient", ) diff --git a/google/cloud/vision_v1/proto/geometry.proto b/google/cloud/vision_v1/proto/geometry.proto index 881c8f84..376d2da3 100644 --- a/google/cloud/vision_v1/proto/geometry.proto +++ b/google/cloud/vision_v1/proto/geometry.proto @@ -1,4 +1,4 @@ -// Copyright 2019 Google LLC. +// 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. @@ -11,7 +11,6 @@ // 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. -// syntax = "proto3"; diff --git a/google/cloud/vision_v1/proto/image_annotator.proto b/google/cloud/vision_v1/proto/image_annotator.proto index 7f13e35c..3852bed7 100644 --- a/google/cloud/vision_v1/proto/image_annotator.proto +++ b/google/cloud/vision_v1/proto/image_annotator.proto @@ -1,4 +1,4 @@ -// Copyright 2019 Google LLC. +// 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. @@ -11,7 +11,6 @@ // 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. -// syntax = "proto3"; @@ -48,7 +47,8 @@ service ImageAnnotator { "https://www.googleapis.com/auth/cloud-vision"; // Run image detection and annotation for a batch of images. - rpc BatchAnnotateImages(BatchAnnotateImagesRequest) returns (BatchAnnotateImagesResponse) { + rpc BatchAnnotateImages(BatchAnnotateImagesRequest) + returns (BatchAnnotateImagesResponse) { option (google.api.http) = { post: "/v1/images:annotate" body: "*" @@ -71,7 +71,8 @@ service ImageAnnotator { // AnnotateFileRequest.pages) frames (gif) or pages (pdf or tiff) from each // file provided and perform detection and annotation for each image // extracted. - rpc BatchAnnotateFiles(BatchAnnotateFilesRequest) returns (BatchAnnotateFilesResponse) { + rpc BatchAnnotateFiles(BatchAnnotateFilesRequest) + returns (BatchAnnotateFilesResponse) { option (google.api.http) = { post: "/v1/files:annotate" body: "*" @@ -96,7 +97,8 @@ service ImageAnnotator { // // This service will write image annotation outputs to json files in customer // GCS bucket, each json file containing BatchAnnotateImagesResponse proto. - rpc AsyncBatchAnnotateImages(AsyncBatchAnnotateImagesRequest) returns (google.longrunning.Operation) { + rpc AsyncBatchAnnotateImages(AsyncBatchAnnotateImagesRequest) + returns (google.longrunning.Operation) { option (google.api.http) = { post: "/v1/images:asyncBatchAnnotate" body: "*" @@ -122,7 +124,8 @@ service ImageAnnotator { // `google.longrunning.Operations` interface. // `Operation.metadata` contains `OperationMetadata` (metadata). // `Operation.response` contains `AsyncBatchAnnotateFilesResponse` (results). - rpc AsyncBatchAnnotateFiles(AsyncBatchAnnotateFilesRequest) returns (google.longrunning.Operation) { + rpc AsyncBatchAnnotateFiles(AsyncBatchAnnotateFilesRequest) + returns (google.longrunning.Operation) { option (google.api.http) = { post: "/v1/files:asyncBatchAnnotate" body: "*" @@ -242,6 +245,9 @@ message Image { // Image content, represented as a stream of bytes. // Note: As with all `bytes` fields, protobuffers use a pure binary // representation, whereas JSON representations use base64. + // + // Currently, this field only works for BatchAnnotateImages requests. It does + // not work for AsyncBatchAnnotateImages requests. bytes content = 1; // Google Cloud Storage image location, or publicly-accessible image @@ -385,6 +391,12 @@ message FaceAnnotation { // Chin right gonion. CHIN_RIGHT_GONION = 34; + + // Left cheek center. + LEFT_CHEEK_CENTER = 35; + + // Right cheek center. + RIGHT_CHEEK_CENTER = 36; } // Face landmark type. @@ -569,27 +581,27 @@ message SafeSearchAnnotation { // Confidence of adult_score. Range [0, 1]. 0 means not confident, 1 means // very confident. - float adult_confidence = 16; + float adult_confidence = 16 [deprecated = true]; // Confidence of spoof_score. Range [0, 1]. 0 means not confident, 1 means // very confident. - float spoof_confidence = 18; + float spoof_confidence = 18 [deprecated = true]; // Confidence of medical_score. Range [0, 1]. 0 means not confident, 1 means // very confident. - float medical_confidence = 20; + float medical_confidence = 20 [deprecated = true]; // Confidence of violence_score. Range [0, 1]. 0 means not confident, 1 means // very confident. - float violence_confidence = 22; + float violence_confidence = 22 [deprecated = true]; // Confidence of racy_score. Range [0, 1]. 0 means not confident, 1 means very // confident. - float racy_confidence = 24; + float racy_confidence = 24 [deprecated = true]; // Confidence of nsfw_score. Range [0, 1]. 0 means not confident, 1 means very // confident. - float nsfw_confidence = 26; + float nsfw_confidence = 26 [deprecated = true]; } // Rectangle determined by min and max `LatLng` pairs. @@ -667,7 +679,6 @@ message WebDetectionParams { // Parameters for text detections. This is used to control TEXT_DETECTION and // DOCUMENT_TEXT_DETECTION features. message TextDetectionParams { - // By default, Cloud Vision API only includes confidence score for // DOCUMENT_TEXT_DETECTION result. Set the flag to true to include confidence // score for TEXT_DETECTION as well. @@ -781,7 +792,8 @@ message AnnotateImageResponse { // Multiple image annotation requests are batched into a single service call. message BatchAnnotateImagesRequest { // Required. Individual image annotation requests for this batch. - repeated AnnotateImageRequest requests = 1 [(google.api.field_behavior) = REQUIRED]; + repeated AnnotateImageRequest requests = 1 + [(google.api.field_behavior) = REQUIRED]; // Optional. Target project and location to make a call. // @@ -852,9 +864,10 @@ message AnnotateFileResponse { // A list of requests to annotate files using the BatchAnnotateFiles API. message BatchAnnotateFilesRequest { - // Required. The list of file annotation requests. Right now we support only one - // AnnotateFileRequest in BatchAnnotateFilesRequest. - repeated AnnotateFileRequest requests = 1 [(google.api.field_behavior) = REQUIRED]; + // Required. The list of file annotation requests. Right now we support only + // one AnnotateFileRequest in BatchAnnotateFilesRequest. + repeated AnnotateFileRequest requests = 1 + [(google.api.field_behavior) = REQUIRED]; // Optional. Target project and location to make a call. // @@ -902,7 +915,8 @@ message AsyncAnnotateFileResponse { // Request for async image annotation for a list of images. message AsyncBatchAnnotateImagesRequest { // Required. Individual image annotation requests for this batch. - repeated AnnotateImageRequest requests = 1 [(google.api.field_behavior) = REQUIRED]; + repeated AnnotateImageRequest requests = 1 + [(google.api.field_behavior) = REQUIRED]; // Required. The desired output location and metadata (e.g. format). OutputConfig output_config = 2 [(google.api.field_behavior) = REQUIRED]; @@ -932,7 +946,8 @@ message AsyncBatchAnnotateImagesResponse { // call. message AsyncBatchAnnotateFilesRequest { // Required. Individual async file annotation requests for this batch. - repeated AsyncAnnotateFileRequest requests = 1 [(google.api.field_behavior) = REQUIRED]; + repeated AsyncAnnotateFileRequest requests = 1 + [(google.api.field_behavior) = REQUIRED]; // Optional. Target project and location to make a call. // diff --git a/google/cloud/vision_v1/proto/product_search.proto b/google/cloud/vision_v1/proto/product_search.proto index 6df694b8..564925fe 100644 --- a/google/cloud/vision_v1/proto/product_search.proto +++ b/google/cloud/vision_v1/proto/product_search.proto @@ -1,4 +1,4 @@ -// Copyright 2019 Google LLC. +// 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. @@ -11,17 +11,16 @@ // 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. -// syntax = "proto3"; package google.cloud.vision.v1; +import "google/api/resource.proto"; import "google/cloud/vision/v1/geometry.proto"; import "google/cloud/vision/v1/product_search_service.proto"; import "google/protobuf/timestamp.proto"; import "google/api/annotations.proto"; -import "google/api/resource.proto"; option cc_enable_arenas = true; option go_package = "google.golang.org/genproto/googleapis/cloud/vision/v1;vision"; @@ -33,7 +32,7 @@ option objc_class_prefix = "GCVN"; // Parameters for a product search request. message ProductSearchParams { // The bounding polygon around the area of interest in the image. - // Optional. If it is not specified, system discretion will be applied. + // If it is not specified, system discretion will be applied. BoundingPoly bounding_poly = 9; // The resource name of a [ProductSet][google.cloud.vision.v1.ProductSet] to be searched for similar images. @@ -41,8 +40,8 @@ message ProductSearchParams { // Format is: // `projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`. string product_set = 6 [(google.api.resource_reference) = { - type: "vision.googleapis.com/ProductSet" - }]; + type: "vision.googleapis.com/ProductSet" + }]; // The list of product categories to search in. Currently, we only consider // the first category, and either "homegoods-v2", "apparel-v2", "toys-v2", diff --git a/google/cloud/vision_v1/proto/product_search_service.proto b/google/cloud/vision_v1/proto/product_search_service.proto index ecfcdf6c..5a61f542 100644 --- a/google/cloud/vision_v1/proto/product_search_service.proto +++ b/google/cloud/vision_v1/proto/product_search_service.proto @@ -1,4 +1,4 @@ -// Copyright 2019 Google LLC. +// 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. @@ -11,7 +11,6 @@ // 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. -// syntax = "proto3"; @@ -397,9 +396,9 @@ message Product { string description = 3; // Immutable. The category for the product identified by the reference image. This should - // be either "homegoods-v2", "apparel-v2", or "toys-v2". The legacy categories - // "homegoods", "apparel", and "toys" are still supported, but these should - // not be used for new products. + // be one of "homegoods-v2", "apparel-v2", "toys-v2", "packagedgoods-v1" or + // "general-v1". The legacy categories "homegoods", "apparel", and "toys" are + // still supported, but these should not be used for new products. string product_category = 4 [(google.api.field_behavior) = IMMUTABLE]; // Key-value pairs that can be attached to a product. At query time, @@ -465,7 +464,6 @@ message ReferenceImage { // The resource name of the reference image. // // Format is: - // // `projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID`. // // This field is ignored when creating a reference image. @@ -638,7 +636,7 @@ message GetProductSetRequest { // Required. Resource name of the ProductSet to get. // // Format is: - // `projects/PROJECT_ID/locations/LOG_ID/productSets/PRODUCT_SET_ID` + // `projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID` string name = 1 [ (google.api.field_behavior) = REQUIRED, (google.api.resource_reference) = { @@ -737,7 +735,6 @@ message GetReferenceImageRequest { // Required. The resource name of the ReferenceImage to get. // // Format is: - // // `projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID`. string name = 1 [ (google.api.field_behavior) = REQUIRED, @@ -752,7 +749,6 @@ message DeleteReferenceImageRequest { // Required. The resource name of the reference image to delete. // // Format is: - // // `projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID` string name = 1 [ (google.api.field_behavior) = REQUIRED, diff --git a/google/cloud/vision_v1/proto/text_annotation.proto b/google/cloud/vision_v1/proto/text_annotation.proto index 97f9c8fa..db3bbdc5 100644 --- a/google/cloud/vision_v1/proto/text_annotation.proto +++ b/google/cloud/vision_v1/proto/text_annotation.proto @@ -1,4 +1,4 @@ -// Copyright 2019 Google LLC. +// 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. @@ -11,7 +11,6 @@ // 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. -// syntax = "proto3"; diff --git a/google/cloud/vision_v1/proto/web_detection.proto b/google/cloud/vision_v1/proto/web_detection.proto index 5ba86403..5d239b89 100644 --- a/google/cloud/vision_v1/proto/web_detection.proto +++ b/google/cloud/vision_v1/proto/web_detection.proto @@ -1,4 +1,4 @@ -// Copyright 2019 Google LLC. +// 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. @@ -11,7 +11,6 @@ // 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. -// syntax = "proto3"; diff --git a/google/cloud/vision_v1/services/image_annotator/async_client.py b/google/cloud/vision_v1/services/image_annotator/async_client.py index f441e263..8dc41443 100644 --- a/google/cloud/vision_v1/services/image_annotator/async_client.py +++ b/google/cloud/vision_v1/services/image_annotator/async_client.py @@ -83,6 +83,7 @@ class ImageAnnotatorAsyncClient: ImageAnnotatorClient.parse_common_location_path ) + from_service_account_info = ImageAnnotatorClient.from_service_account_info from_service_account_file = ImageAnnotatorClient.from_service_account_file from_service_account_json = from_service_account_file @@ -160,12 +161,13 @@ async def batch_annotate_images( images. Args: - request (:class:`~.image_annotator.BatchAnnotateImagesRequest`): + request (:class:`google.cloud.vision_v1.types.BatchAnnotateImagesRequest`): The request object. Multiple image annotation requests are batched into a single service call. - requests (:class:`Sequence[~.image_annotator.AnnotateImageRequest]`): + requests (:class:`Sequence[google.cloud.vision_v1.types.AnnotateImageRequest]`): Required. Individual image annotation requests for this batch. + This corresponds to the ``requests`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -177,7 +179,7 @@ async def batch_annotate_images( sent along with the request as metadata. Returns: - ~.image_annotator.BatchAnnotateImagesResponse: + google.cloud.vision_v1.types.BatchAnnotateImagesResponse: Response to a batch image annotation request. @@ -241,14 +243,15 @@ async def batch_annotate_files( extracted. Args: - request (:class:`~.image_annotator.BatchAnnotateFilesRequest`): + request (:class:`google.cloud.vision_v1.types.BatchAnnotateFilesRequest`): The request object. A list of requests to annotate files using the BatchAnnotateFiles API. - requests (:class:`Sequence[~.image_annotator.AnnotateFileRequest]`): + requests (:class:`Sequence[google.cloud.vision_v1.types.AnnotateFileRequest]`): Required. The list of file annotation requests. Right now we support only one AnnotateFileRequest in BatchAnnotateFilesRequest. + This corresponds to the ``requests`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -260,7 +263,7 @@ async def batch_annotate_files( sent along with the request as metadata. Returns: - ~.image_annotator.BatchAnnotateFilesResponse: + google.cloud.vision_v1.types.BatchAnnotateFilesResponse: A list of file annotation responses. """ # Create or coerce a protobuf request object. @@ -327,18 +330,20 @@ async def async_batch_annotate_images( BatchAnnotateImagesResponse proto. Args: - request (:class:`~.image_annotator.AsyncBatchAnnotateImagesRequest`): + request (:class:`google.cloud.vision_v1.types.AsyncBatchAnnotateImagesRequest`): The request object. Request for async image annotation for a list of images. - requests (:class:`Sequence[~.image_annotator.AnnotateImageRequest]`): + requests (:class:`Sequence[google.cloud.vision_v1.types.AnnotateImageRequest]`): Required. Individual image annotation requests for this batch. + This corresponds to the ``requests`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - output_config (:class:`~.image_annotator.OutputConfig`): + output_config (:class:`google.cloud.vision_v1.types.OutputConfig`): Required. The desired output location and metadata (e.g. format). + This corresponds to the ``output_config`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -350,11 +355,11 @@ async def async_batch_annotate_images( sent along with the request as metadata. Returns: - ~.operation_async.AsyncOperation: + google.api_core.operation_async.AsyncOperation: An object representing a long-running operation. The result type for the operation will be - :class:``~.image_annotator.AsyncBatchAnnotateImagesResponse``: + :class:`google.cloud.vision_v1.types.AsyncBatchAnnotateImagesResponse` Response to an async batch image annotation request. """ @@ -427,12 +432,13 @@ async def async_batch_annotate_files( ``AsyncBatchAnnotateFilesResponse`` (results). Args: - request (:class:`~.image_annotator.AsyncBatchAnnotateFilesRequest`): + request (:class:`google.cloud.vision_v1.types.AsyncBatchAnnotateFilesRequest`): The request object. Multiple async file annotation requests are batched into a single service call. - requests (:class:`Sequence[~.image_annotator.AsyncAnnotateFileRequest]`): + requests (:class:`Sequence[google.cloud.vision_v1.types.AsyncAnnotateFileRequest]`): Required. Individual async file annotation requests for this batch. + This corresponds to the ``requests`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -444,11 +450,11 @@ async def async_batch_annotate_files( sent along with the request as metadata. Returns: - ~.operation_async.AsyncOperation: + google.api_core.operation_async.AsyncOperation: An object representing a long-running operation. The result type for the operation will be - :class:``~.image_annotator.AsyncBatchAnnotateFilesResponse``: + :class:`google.cloud.vision_v1.types.AsyncBatchAnnotateFilesResponse` Response to an async batch file annotation request. """ diff --git a/google/cloud/vision_v1/services/image_annotator/client.py b/google/cloud/vision_v1/services/image_annotator/client.py index cd963a34..9bf982c9 100644 --- a/google/cloud/vision_v1/services/image_annotator/client.py +++ b/google/cloud/vision_v1/services/image_annotator/client.py @@ -115,6 +115,22 @@ def _get_default_mtls_endpoint(api_endpoint): DEFAULT_ENDPOINT ) + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + ImageAnnotatorClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_info(info) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials @@ -127,7 +143,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): kwargs: Additional arguments to pass to the constructor. Returns: - {@api.name}: The constructed client. + ImageAnnotatorClient: The constructed client. """ credentials = service_account.Credentials.from_service_account_file(filename) kwargs["credentials"] = credentials @@ -251,10 +267,10 @@ def __init__( credentials identify the application to the service; if none are specified, the client will attempt to ascertain the credentials from the environment. - transport (Union[str, ~.ImageAnnotatorTransport]): The + transport (Union[str, ImageAnnotatorTransport]): The transport to use. If set to None, a transport is chosen automatically. - client_options (client_options_lib.ClientOptions): Custom options for the + client_options (google.api_core.client_options.ClientOptions): Custom options for the client. It won't take effect if a ``transport`` instance is provided. (1) The ``api_endpoint`` property can be used to override the default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT @@ -290,21 +306,17 @@ def __init__( util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")) ) - ssl_credentials = None + client_cert_source_func = None is_mtls = False if use_client_cert: if client_options.client_cert_source: - import grpc # type: ignore - - cert, key = client_options.client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) is_mtls = True + client_cert_source_func = client_options.client_cert_source else: - creds = SslCredentials() - is_mtls = creds.is_mtls - ssl_credentials = creds.ssl_credentials if is_mtls else None + is_mtls = mtls.has_default_client_cert_source() + client_cert_source_func = ( + mtls.default_client_cert_source() if is_mtls else None + ) # Figure out which api endpoint to use. if client_options.api_endpoint is not None: @@ -347,7 +359,7 @@ def __init__( credentials_file=client_options.credentials_file, host=api_endpoint, scopes=client_options.scopes, - ssl_channel_credentials=ssl_credentials, + client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, ) @@ -365,12 +377,13 @@ def batch_annotate_images( images. Args: - request (:class:`~.image_annotator.BatchAnnotateImagesRequest`): + request (google.cloud.vision_v1.types.BatchAnnotateImagesRequest): The request object. Multiple image annotation requests are batched into a single service call. - requests (:class:`Sequence[~.image_annotator.AnnotateImageRequest]`): + requests (Sequence[google.cloud.vision_v1.types.AnnotateImageRequest]): Required. Individual image annotation requests for this batch. + This corresponds to the ``requests`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -382,7 +395,7 @@ def batch_annotate_images( sent along with the request as metadata. Returns: - ~.image_annotator.BatchAnnotateImagesResponse: + google.cloud.vision_v1.types.BatchAnnotateImagesResponse: Response to a batch image annotation request. @@ -410,8 +423,8 @@ def batch_annotate_images( # If we have keyword arguments corresponding to fields on the # request, apply these. - if requests: - request.requests.extend(requests) + if requests is not None: + request.requests = requests # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -442,14 +455,15 @@ def batch_annotate_files( extracted. Args: - request (:class:`~.image_annotator.BatchAnnotateFilesRequest`): + request (google.cloud.vision_v1.types.BatchAnnotateFilesRequest): The request object. A list of requests to annotate files using the BatchAnnotateFiles API. - requests (:class:`Sequence[~.image_annotator.AnnotateFileRequest]`): + requests (Sequence[google.cloud.vision_v1.types.AnnotateFileRequest]): Required. The list of file annotation requests. Right now we support only one AnnotateFileRequest in BatchAnnotateFilesRequest. + This corresponds to the ``requests`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -461,7 +475,7 @@ def batch_annotate_files( sent along with the request as metadata. Returns: - ~.image_annotator.BatchAnnotateFilesResponse: + google.cloud.vision_v1.types.BatchAnnotateFilesResponse: A list of file annotation responses. """ # Create or coerce a protobuf request object. @@ -487,8 +501,8 @@ def batch_annotate_files( # If we have keyword arguments corresponding to fields on the # request, apply these. - if requests: - request.requests.extend(requests) + if requests is not None: + request.requests = requests # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -524,18 +538,20 @@ def async_batch_annotate_images( BatchAnnotateImagesResponse proto. Args: - request (:class:`~.image_annotator.AsyncBatchAnnotateImagesRequest`): + request (google.cloud.vision_v1.types.AsyncBatchAnnotateImagesRequest): The request object. Request for async image annotation for a list of images. - requests (:class:`Sequence[~.image_annotator.AnnotateImageRequest]`): + requests (Sequence[google.cloud.vision_v1.types.AnnotateImageRequest]): Required. Individual image annotation requests for this batch. + This corresponds to the ``requests`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - output_config (:class:`~.image_annotator.OutputConfig`): + output_config (google.cloud.vision_v1.types.OutputConfig): Required. The desired output location and metadata (e.g. format). + This corresponds to the ``output_config`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -547,11 +563,11 @@ def async_batch_annotate_images( sent along with the request as metadata. Returns: - ~.operation.Operation: + google.api_core.operation.Operation: An object representing a long-running operation. The result type for the operation will be - :class:``~.image_annotator.AsyncBatchAnnotateImagesResponse``: + :class:`google.cloud.vision_v1.types.AsyncBatchAnnotateImagesResponse` Response to an async batch image annotation request. """ @@ -578,12 +594,11 @@ def async_batch_annotate_images( # If we have keyword arguments corresponding to fields on the # request, apply these. + if requests is not None: + request.requests = requests if output_config is not None: request.output_config = output_config - if requests: - request.requests.extend(requests) - # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = self._transport._wrapped_methods[ @@ -622,12 +637,13 @@ def async_batch_annotate_files( ``AsyncBatchAnnotateFilesResponse`` (results). Args: - request (:class:`~.image_annotator.AsyncBatchAnnotateFilesRequest`): + request (google.cloud.vision_v1.types.AsyncBatchAnnotateFilesRequest): The request object. Multiple async file annotation requests are batched into a single service call. - requests (:class:`Sequence[~.image_annotator.AsyncAnnotateFileRequest]`): + requests (Sequence[google.cloud.vision_v1.types.AsyncAnnotateFileRequest]): Required. Individual async file annotation requests for this batch. + This corresponds to the ``requests`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -639,11 +655,11 @@ def async_batch_annotate_files( sent along with the request as metadata. Returns: - ~.operation.Operation: + google.api_core.operation.Operation: An object representing a long-running operation. The result type for the operation will be - :class:``~.image_annotator.AsyncBatchAnnotateFilesResponse``: + :class:`google.cloud.vision_v1.types.AsyncBatchAnnotateFilesResponse` Response to an async batch file annotation request. """ @@ -670,8 +686,8 @@ def async_batch_annotate_files( # If we have keyword arguments corresponding to fields on the # request, apply these. - if requests: - request.requests.extend(requests) + if requests is not None: + request.requests = requests # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. diff --git a/google/cloud/vision_v1/services/image_annotator/transports/grpc.py b/google/cloud/vision_v1/services/image_annotator/transports/grpc.py index 36536880..2f4c0437 100644 --- a/google/cloud/vision_v1/services/image_annotator/transports/grpc.py +++ b/google/cloud/vision_v1/services/image_annotator/transports/grpc.py @@ -62,6 +62,7 @@ def __init__( api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -92,6 +93,10 @@ def __init__( ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -108,6 +113,11 @@ def __init__( """ self._ssl_channel_credentials = ssl_channel_credentials + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -117,11 +127,6 @@ def __init__( self._grpc_channel = channel self._ssl_channel_credentials = None elif api_mtls_endpoint: - warnings.warn( - "api_mtls_endpoint and client_cert_source are deprecated", - DeprecationWarning, - ) - host = ( api_mtls_endpoint if ":" in api_mtls_endpoint @@ -165,12 +170,18 @@ def __init__( scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id ) + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + # create a new channel. The provided one is ignored. self._grpc_channel = type(self).create_channel( host, credentials=credentials, credentials_file=credentials_file, - ssl_credentials=ssl_channel_credentials, + ssl_credentials=self._ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ diff --git a/google/cloud/vision_v1/services/image_annotator/transports/grpc_asyncio.py b/google/cloud/vision_v1/services/image_annotator/transports/grpc_asyncio.py index d95951d9..f1c4dd2a 100644 --- a/google/cloud/vision_v1/services/image_annotator/transports/grpc_asyncio.py +++ b/google/cloud/vision_v1/services/image_annotator/transports/grpc_asyncio.py @@ -106,6 +106,7 @@ def __init__( api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -137,6 +138,10 @@ def __init__( ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -153,6 +158,11 @@ def __init__( """ self._ssl_channel_credentials = ssl_channel_credentials + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -162,11 +172,6 @@ def __init__( self._grpc_channel = channel self._ssl_channel_credentials = None elif api_mtls_endpoint: - warnings.warn( - "api_mtls_endpoint and client_cert_source are deprecated", - DeprecationWarning, - ) - host = ( api_mtls_endpoint if ":" in api_mtls_endpoint @@ -210,12 +215,18 @@ def __init__( scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id ) + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + # create a new channel. The provided one is ignored. self._grpc_channel = type(self).create_channel( host, credentials=credentials, credentials_file=credentials_file, - ssl_credentials=ssl_channel_credentials, + ssl_credentials=self._ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ diff --git a/google/cloud/vision_v1/services/product_search/async_client.py b/google/cloud/vision_v1/services/product_search/async_client.py index 11b5e016..2bb84807 100644 --- a/google/cloud/vision_v1/services/product_search/async_client.py +++ b/google/cloud/vision_v1/services/product_search/async_client.py @@ -107,6 +107,7 @@ class ProductSearchAsyncClient: ProductSearchClient.parse_common_location_path ) + from_service_account_info = ProductSearchClient.from_service_account_info from_service_account_file = ProductSearchClient.from_service_account_file from_service_account_json = from_service_account_file @@ -190,7 +191,7 @@ async def create_product_set( longer than 4096 characters. Args: - request (:class:`~.product_search_service.CreateProductSetRequest`): + request (:class:`google.cloud.vision_v1.types.CreateProductSetRequest`): The request object. Request message for the `CreateProductSet` method. parent (:class:`str`): @@ -198,10 +199,11 @@ async def create_product_set( created. Format is ``projects/PROJECT_ID/locations/LOC_ID``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - product_set (:class:`~.product_search_service.ProductSet`): + product_set (:class:`google.cloud.vision_v1.types.ProductSet`): Required. The ProductSet to create. This corresponds to the ``product_set`` field on the ``request`` instance; if ``request`` is provided, this @@ -212,6 +214,7 @@ async def create_product_set( resource id. If it is already in use, an error is returned with code ALREADY_EXISTS. Must be at most 128 characters long. It cannot contain the character ``/``. + This corresponds to the ``product_set_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -223,7 +226,7 @@ async def create_product_set( sent along with the request as metadata. Returns: - ~.product_search_service.ProductSet: + google.cloud.vision_v1.types.ProductSet: A ProductSet contains Products. A ProductSet can contain a maximum of 1 million reference images. If the limit @@ -296,7 +299,7 @@ async def list_product_sets( less than 1. Args: - request (:class:`~.product_search_service.ListProductSetsRequest`): + request (:class:`google.cloud.vision_v1.types.ListProductSetsRequest`): The request object. Request message for the `ListProductSets` method. parent (:class:`str`): @@ -304,6 +307,7 @@ async def list_product_sets( listed. Format is ``projects/PROJECT_ID/locations/LOC_ID``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -315,8 +319,8 @@ async def list_product_sets( sent along with the request as metadata. Returns: - ~.pagers.ListProductSetsAsyncPager: - Response message for the ``ListProductSets`` method. + google.cloud.vision_v1.services.product_search.pagers.ListProductSetsAsyncPager: + Response message for the ListProductSets method. Iterating over this object will yield results and resolve additional pages automatically. @@ -390,14 +394,15 @@ async def get_product_set( - Returns NOT_FOUND if the ProductSet does not exist. Args: - request (:class:`~.product_search_service.GetProductSetRequest`): + request (:class:`google.cloud.vision_v1.types.GetProductSetRequest`): The request object. Request message for the `GetProductSet` method. name (:class:`str`): Required. Resource name of the ProductSet to get. Format is: - ``projects/PROJECT_ID/locations/LOG_ID/productSets/PRODUCT_SET_ID`` + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -409,7 +414,7 @@ async def get_product_set( sent along with the request as metadata. Returns: - ~.product_search_service.ProductSet: + google.cloud.vision_v1.types.ProductSet: A ProductSet contains Products. A ProductSet can contain a maximum of 1 million reference images. If the limit @@ -484,20 +489,22 @@ async def update_product_set( characters. Args: - request (:class:`~.product_search_service.UpdateProductSetRequest`): + request (:class:`google.cloud.vision_v1.types.UpdateProductSetRequest`): The request object. Request message for the `UpdateProductSet` method. - product_set (:class:`~.product_search_service.ProductSet`): + product_set (:class:`google.cloud.vision_v1.types.ProductSet`): Required. The ProductSet resource which replaces the one on the server. + This corresponds to the ``product_set`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - update_mask (:class:`~.field_mask.FieldMask`): + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): The [FieldMask][google.protobuf.FieldMask] that specifies which fields to update. If update_mask isn't specified, all mutable fields are to be updated. Valid mask path is ``display_name``. + This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -509,7 +516,7 @@ async def update_product_set( sent along with the request as metadata. Returns: - ~.product_search_service.ProductSet: + google.cloud.vision_v1.types.ProductSet: A ProductSet contains Products. A ProductSet can contain a maximum of 1 million reference images. If the limit @@ -582,7 +589,7 @@ async def delete_product_set( Storage. Args: - request (:class:`~.product_search_service.DeleteProductSetRequest`): + request (:class:`google.cloud.vision_v1.types.DeleteProductSetRequest`): The request object. Request message for the `DeleteProductSet` method. name (:class:`str`): @@ -590,6 +597,7 @@ async def delete_product_set( Format is: ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -668,7 +676,7 @@ async def create_product( invalid. Args: - request (:class:`~.product_search_service.CreateProductRequest`): + request (:class:`google.cloud.vision_v1.types.CreateProductRequest`): The request object. Request message for the `CreateProduct` method. parent (:class:`str`): @@ -676,10 +684,11 @@ async def create_product( created. Format is ``projects/PROJECT_ID/locations/LOC_ID``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - product (:class:`~.product_search_service.Product`): + product (:class:`google.cloud.vision_v1.types.Product`): Required. The product to create. This corresponds to the ``product`` field on the ``request`` instance; if ``request`` is provided, this @@ -690,6 +699,7 @@ async def create_product( resource id. If it is already in use, an error is returned with code ALREADY_EXISTS. Must be at most 128 characters long. It cannot contain the character ``/``. + This corresponds to the ``product_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -701,7 +711,7 @@ async def create_product( sent along with the request as metadata. Returns: - ~.product_search_service.Product: + google.cloud.vision_v1.types.Product: A Product contains ReferenceImages. """ # Create or coerce a protobuf request object. @@ -769,7 +779,7 @@ async def list_products( less than 1. Args: - request (:class:`~.product_search_service.ListProductsRequest`): + request (:class:`google.cloud.vision_v1.types.ListProductsRequest`): The request object. Request message for the `ListProducts` method. parent (:class:`str`): @@ -777,6 +787,7 @@ async def list_products( should be listed. Format: ``projects/PROJECT_ID/locations/LOC_ID`` + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -788,8 +799,8 @@ async def list_products( sent along with the request as metadata. Returns: - ~.pagers.ListProductsAsyncPager: - Response message for the ``ListProducts`` method. + google.cloud.vision_v1.services.product_search.pagers.ListProductsAsyncPager: + Response message for the ListProducts method. Iterating over this object will yield results and resolve additional pages automatically. @@ -863,7 +874,7 @@ async def get_product( - Returns NOT_FOUND if the Product does not exist. Args: - request (:class:`~.product_search_service.GetProductRequest`): + request (:class:`google.cloud.vision_v1.types.GetProductRequest`): The request object. Request message for the `GetProduct` method. name (:class:`str`): @@ -871,6 +882,7 @@ async def get_product( Format is: ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -882,7 +894,7 @@ async def get_product( sent along with the request as metadata. Returns: - ~.product_search_service.Product: + google.cloud.vision_v1.types.Product: A Product contains ReferenceImages. """ # Create or coerce a protobuf request object. @@ -959,22 +971,24 @@ async def update_product( update_mask. Args: - request (:class:`~.product_search_service.UpdateProductRequest`): + request (:class:`google.cloud.vision_v1.types.UpdateProductRequest`): The request object. Request message for the `UpdateProduct` method. - product (:class:`~.product_search_service.Product`): + product (:class:`google.cloud.vision_v1.types.Product`): Required. The Product resource which replaces the one on the server. product.name is immutable. + This corresponds to the ``product`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - update_mask (:class:`~.field_mask.FieldMask`): + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): The [FieldMask][google.protobuf.FieldMask] that specifies which fields to update. If update_mask isn't specified, all mutable fields are to be updated. Valid mask paths include ``product_labels``, ``display_name``, and ``description``. + This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -986,7 +1000,7 @@ async def update_product( sent along with the request as metadata. Returns: - ~.product_search_service.Product: + google.cloud.vision_v1.types.Product: A Product contains ReferenceImages. """ # Create or coerce a protobuf request object. @@ -1056,7 +1070,7 @@ async def delete_product( all related caches are refreshed. Args: - request (:class:`~.product_search_service.DeleteProductRequest`): + request (:class:`google.cloud.vision_v1.types.DeleteProductRequest`): The request object. Request message for the `DeleteProduct` method. name (:class:`str`): @@ -1064,6 +1078,7 @@ async def delete_product( Format is: ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1154,7 +1169,7 @@ async def create_reference_image( 10 polygons. Args: - request (:class:`~.product_search_service.CreateReferenceImageRequest`): + request (:class:`google.cloud.vision_v1.types.CreateReferenceImageRequest`): The request object. Request message for the `CreateReferenceImage` method. parent (:class:`str`): @@ -1163,13 +1178,15 @@ async def create_reference_image( Format is ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - reference_image (:class:`~.product_search_service.ReferenceImage`): + reference_image (:class:`google.cloud.vision_v1.types.ReferenceImage`): Required. The reference image to create. If an image ID is specified, it is ignored. + This corresponds to the ``reference_image`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1179,6 +1196,7 @@ async def create_reference_image( as the resource id. If it is already in use, an error is returned with code ALREADY_EXISTS. Must be at most 128 characters long. It cannot contain the character ``/``. + This corresponds to the ``reference_image_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1190,9 +1208,9 @@ async def create_reference_image( sent along with the request as metadata. Returns: - ~.product_search_service.ReferenceImage: - A ``ReferenceImage`` represents a product image and its - associated metadata, such as bounding boxes. + google.cloud.vision_v1.types.ReferenceImage: + A ReferenceImage represents a product image and its associated metadata, + such as bounding boxes. """ # Create or coerce a protobuf request object. @@ -1261,7 +1279,7 @@ async def delete_reference_image( Storage. Args: - request (:class:`~.product_search_service.DeleteReferenceImageRequest`): + request (:class:`google.cloud.vision_v1.types.DeleteReferenceImageRequest`): The request object. Request message for the `DeleteReferenceImage` method. name (:class:`str`): @@ -1269,8 +1287,8 @@ async def delete_reference_image( delete. Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1344,7 +1362,7 @@ async def list_reference_images( 100, or less than 1. Args: - request (:class:`~.product_search_service.ListReferenceImagesRequest`): + request (:class:`google.cloud.vision_v1.types.ListReferenceImagesRequest`): The request object. Request message for the `ListReferenceImages` method. parent (:class:`str`): @@ -1353,6 +1371,7 @@ async def list_reference_images( Format is ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1364,8 +1383,8 @@ async def list_reference_images( sent along with the request as metadata. Returns: - ~.pagers.ListReferenceImagesAsyncPager: - Response message for the ``ListReferenceImages`` method. + google.cloud.vision_v1.services.product_search.pagers.ListReferenceImagesAsyncPager: + Response message for the ListReferenceImages method. Iterating over this object will yield results and resolve additional pages automatically. @@ -1439,7 +1458,7 @@ async def get_reference_image( - Returns NOT_FOUND if the specified image does not exist. Args: - request (:class:`~.product_search_service.GetReferenceImageRequest`): + request (:class:`google.cloud.vision_v1.types.GetReferenceImageRequest`): The request object. Request message for the `GetReferenceImage` method. name (:class:`str`): @@ -1447,8 +1466,8 @@ async def get_reference_image( get. Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1460,9 +1479,9 @@ async def get_reference_image( sent along with the request as metadata. Returns: - ~.product_search_service.ReferenceImage: - A ``ReferenceImage`` represents a product image and its - associated metadata, such as bounding boxes. + google.cloud.vision_v1.types.ReferenceImage: + A ReferenceImage represents a product image and its associated metadata, + such as bounding boxes. """ # Create or coerce a protobuf request object. @@ -1532,7 +1551,7 @@ async def add_product_to_product_set( exist. Args: - request (:class:`~.product_search_service.AddProductToProductSetRequest`): + request (:class:`google.cloud.vision_v1.types.AddProductToProductSetRequest`): The request object. Request message for the `AddProductToProductSet` method. name (:class:`str`): @@ -1541,6 +1560,7 @@ async def add_product_to_product_set( Format is: ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1550,6 +1570,7 @@ async def add_product_to_product_set( Format is: ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + This corresponds to the ``product`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1620,7 +1641,7 @@ async def remove_product_from_product_set( r"""Removes a Product from the specified ProductSet. Args: - request (:class:`~.product_search_service.RemoveProductFromProductSetRequest`): + request (:class:`google.cloud.vision_v1.types.RemoveProductFromProductSetRequest`): The request object. Request message for the `RemoveProductFromProductSet` method. name (:class:`str`): @@ -1629,6 +1650,7 @@ async def remove_product_from_product_set( Format is: ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1638,6 +1660,7 @@ async def remove_product_from_product_set( Format is: ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + This corresponds to the ``product`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1714,7 +1737,7 @@ async def list_products_in_product_set( less than 1. Args: - request (:class:`~.product_search_service.ListProductsInProductSetRequest`): + request (:class:`google.cloud.vision_v1.types.ListProductsInProductSetRequest`): The request object. Request message for the `ListProductsInProductSet` method. name (:class:`str`): @@ -1723,6 +1746,7 @@ async def list_products_in_product_set( Format is: ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1734,8 +1758,8 @@ async def list_products_in_product_set( sent along with the request as metadata. Returns: - ~.pagers.ListProductsInProductSetAsyncPager: - Response message for the ``ListProductsInProductSet`` + google.cloud.vision_v1.services.product_search.pagers.ListProductsInProductSetAsyncPager: + Response message for the ListProductsInProductSet method. Iterating over this object will yield results and @@ -1818,7 +1842,7 @@ async def import_product_sets( [ImportProductSetsGcsSource.csv_file_uri][google.cloud.vision.v1.ImportProductSetsGcsSource.csv_file_uri]. Args: - request (:class:`~.product_search_service.ImportProductSetsRequest`): + request (:class:`google.cloud.vision_v1.types.ImportProductSetsRequest`): The request object. Request message for the `ImportProductSets` method. parent (:class:`str`): @@ -1826,12 +1850,14 @@ async def import_product_sets( imported. Format is ``projects/PROJECT_ID/locations/LOC_ID``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - input_config (:class:`~.product_search_service.ImportProductSetsInputConfig`): + input_config (:class:`google.cloud.vision_v1.types.ImportProductSetsInputConfig`): Required. The input content for the list of requests. + This corresponds to the ``input_config`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1843,18 +1869,18 @@ async def import_product_sets( sent along with the request as metadata. Returns: - ~.operation_async.AsyncOperation: + google.api_core.operation_async.AsyncOperation: An object representing a long-running operation. The result type for the operation will be - :class:``~.product_search_service.ImportProductSetsResponse``: - Response message for the ``ImportProductSets`` method. + :class:`google.cloud.vision_v1.types.ImportProductSetsResponse` + Response message for the ImportProductSets method. - This message is returned by the - [google.longrunning.Operations.GetOperation][google.longrunning.Operations.GetOperation] - method in the returned - [google.longrunning.Operation.response][google.longrunning.Operation.response] - field. + This message is returned by the + [google.longrunning.Operations.GetOperation][google.longrunning.Operations.GetOperation] + method in the returned + [google.longrunning.Operation.response][google.longrunning.Operation.response] + field. """ # Create or coerce a protobuf request object. @@ -1949,7 +1975,7 @@ async def purge_products( ``BatchOperationMetadata``. (progress) Args: - request (:class:`~.product_search_service.PurgeProductsRequest`): + request (:class:`google.cloud.vision_v1.types.PurgeProductsRequest`): The request object. Request message for the `PurgeProducts` method. parent (:class:`str`): @@ -1957,6 +1983,7 @@ async def purge_products( should be deleted. Format is ``projects/PROJECT_ID/locations/LOC_ID``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1968,24 +1995,22 @@ async def purge_products( sent along with the request as metadata. Returns: - ~.operation_async.AsyncOperation: + google.api_core.operation_async.AsyncOperation: An object representing a long-running operation. - The result type for the operation will be - :class:``~.empty.Empty``: A generic empty message that - you can re-use to avoid defining duplicated empty - messages in your APIs. A typical example is to use it as - the request or the response type of an API method. For - instance: + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: - :: + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); - service Foo { - rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); - } + } - The JSON representation for ``Empty`` is empty JSON - object ``{}``. + The JSON representation for Empty is empty JSON + object {}. """ # Create or coerce a protobuf request object. diff --git a/google/cloud/vision_v1/services/product_search/client.py b/google/cloud/vision_v1/services/product_search/client.py index b79cb3da..86b6a2a6 100644 --- a/google/cloud/vision_v1/services/product_search/client.py +++ b/google/cloud/vision_v1/services/product_search/client.py @@ -133,6 +133,22 @@ def _get_default_mtls_endpoint(api_endpoint): DEFAULT_ENDPOINT ) + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + ProductSearchClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_info(info) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials @@ -145,7 +161,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): kwargs: Additional arguments to pass to the constructor. Returns: - {@api.name}: The constructed client. + ProductSearchClient: The constructed client. """ credentials = service_account.Credentials.from_service_account_file(filename) kwargs["credentials"] = credentials @@ -290,10 +306,10 @@ def __init__( credentials identify the application to the service; if none are specified, the client will attempt to ascertain the credentials from the environment. - transport (Union[str, ~.ProductSearchTransport]): The + transport (Union[str, ProductSearchTransport]): The transport to use. If set to None, a transport is chosen automatically. - client_options (client_options_lib.ClientOptions): Custom options for the + client_options (google.api_core.client_options.ClientOptions): Custom options for the client. It won't take effect if a ``transport`` instance is provided. (1) The ``api_endpoint`` property can be used to override the default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT @@ -329,21 +345,17 @@ def __init__( util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")) ) - ssl_credentials = None + client_cert_source_func = None is_mtls = False if use_client_cert: if client_options.client_cert_source: - import grpc # type: ignore - - cert, key = client_options.client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) is_mtls = True + client_cert_source_func = client_options.client_cert_source else: - creds = SslCredentials() - is_mtls = creds.is_mtls - ssl_credentials = creds.ssl_credentials if is_mtls else None + is_mtls = mtls.has_default_client_cert_source() + client_cert_source_func = ( + mtls.default_client_cert_source() if is_mtls else None + ) # Figure out which api endpoint to use. if client_options.api_endpoint is not None: @@ -386,7 +398,7 @@ def __init__( credentials_file=client_options.credentials_file, host=api_endpoint, scopes=client_options.scopes, - ssl_channel_credentials=ssl_credentials, + client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, ) @@ -410,28 +422,30 @@ def create_product_set( longer than 4096 characters. Args: - request (:class:`~.product_search_service.CreateProductSetRequest`): + request (google.cloud.vision_v1.types.CreateProductSetRequest): The request object. Request message for the `CreateProductSet` method. - parent (:class:`str`): + parent (str): Required. The project in which the ProductSet should be created. Format is ``projects/PROJECT_ID/locations/LOC_ID``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - product_set (:class:`~.product_search_service.ProductSet`): + product_set (google.cloud.vision_v1.types.ProductSet): Required. The ProductSet to create. This corresponds to the ``product_set`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - product_set_id (:class:`str`): + product_set_id (str): A user-supplied resource id for this ProductSet. If set, the server will attempt to use this value as the resource id. If it is already in use, an error is returned with code ALREADY_EXISTS. Must be at most 128 characters long. It cannot contain the character ``/``. + This corresponds to the ``product_set_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -443,7 +457,7 @@ def create_product_set( sent along with the request as metadata. Returns: - ~.product_search_service.ProductSet: + google.cloud.vision_v1.types.ProductSet: A ProductSet contains Products. A ProductSet can contain a maximum of 1 million reference images. If the limit @@ -511,14 +525,15 @@ def list_product_sets( less than 1. Args: - request (:class:`~.product_search_service.ListProductSetsRequest`): + request (google.cloud.vision_v1.types.ListProductSetsRequest): The request object. Request message for the `ListProductSets` method. - parent (:class:`str`): + parent (str): Required. The project from which ProductSets should be listed. Format is ``projects/PROJECT_ID/locations/LOC_ID``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -530,8 +545,8 @@ def list_product_sets( sent along with the request as metadata. Returns: - ~.pagers.ListProductSetsPager: - Response message for the ``ListProductSets`` method. + google.cloud.vision_v1.services.product_search.pagers.ListProductSetsPager: + Response message for the ListProductSets method. Iterating over this object will yield results and resolve additional pages automatically. @@ -598,14 +613,15 @@ def get_product_set( - Returns NOT_FOUND if the ProductSet does not exist. Args: - request (:class:`~.product_search_service.GetProductSetRequest`): + request (google.cloud.vision_v1.types.GetProductSetRequest): The request object. Request message for the `GetProductSet` method. - name (:class:`str`): + name (str): Required. Resource name of the ProductSet to get. Format is: - ``projects/PROJECT_ID/locations/LOG_ID/productSets/PRODUCT_SET_ID`` + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -617,7 +633,7 @@ def get_product_set( sent along with the request as metadata. Returns: - ~.product_search_service.ProductSet: + google.cloud.vision_v1.types.ProductSet: A ProductSet contains Products. A ProductSet can contain a maximum of 1 million reference images. If the limit @@ -685,20 +701,22 @@ def update_product_set( characters. Args: - request (:class:`~.product_search_service.UpdateProductSetRequest`): + request (google.cloud.vision_v1.types.UpdateProductSetRequest): The request object. Request message for the `UpdateProductSet` method. - product_set (:class:`~.product_search_service.ProductSet`): + product_set (google.cloud.vision_v1.types.ProductSet): Required. The ProductSet resource which replaces the one on the server. + This corresponds to the ``product_set`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - update_mask (:class:`~.field_mask.FieldMask`): + update_mask (google.protobuf.field_mask_pb2.FieldMask): The [FieldMask][google.protobuf.FieldMask] that specifies which fields to update. If update_mask isn't specified, all mutable fields are to be updated. Valid mask path is ``display_name``. + This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -710,7 +728,7 @@ def update_product_set( sent along with the request as metadata. Returns: - ~.product_search_service.ProductSet: + google.cloud.vision_v1.types.ProductSet: A ProductSet contains Products. A ProductSet can contain a maximum of 1 million reference images. If the limit @@ -776,14 +794,15 @@ def delete_product_set( Storage. Args: - request (:class:`~.product_search_service.DeleteProductSetRequest`): + request (google.cloud.vision_v1.types.DeleteProductSetRequest): The request object. Request message for the `DeleteProductSet` method. - name (:class:`str`): + name (str): Required. Resource name of the ProductSet to delete. Format is: ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -855,28 +874,30 @@ def create_product( invalid. Args: - request (:class:`~.product_search_service.CreateProductRequest`): + request (google.cloud.vision_v1.types.CreateProductRequest): The request object. Request message for the `CreateProduct` method. - parent (:class:`str`): + parent (str): Required. The project in which the Product should be created. Format is ``projects/PROJECT_ID/locations/LOC_ID``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - product (:class:`~.product_search_service.Product`): + product (google.cloud.vision_v1.types.Product): Required. The product to create. This corresponds to the ``product`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - product_id (:class:`str`): + product_id (str): A user-supplied resource id for this Product. If set, the server will attempt to use this value as the resource id. If it is already in use, an error is returned with code ALREADY_EXISTS. Must be at most 128 characters long. It cannot contain the character ``/``. + This corresponds to the ``product_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -888,7 +909,7 @@ def create_product( sent along with the request as metadata. Returns: - ~.product_search_service.Product: + google.cloud.vision_v1.types.Product: A Product contains ReferenceImages. """ # Create or coerce a protobuf request object. @@ -951,14 +972,15 @@ def list_products( less than 1. Args: - request (:class:`~.product_search_service.ListProductsRequest`): + request (google.cloud.vision_v1.types.ListProductsRequest): The request object. Request message for the `ListProducts` method. - parent (:class:`str`): + parent (str): Required. The project OR ProductSet from which Products should be listed. Format: ``projects/PROJECT_ID/locations/LOC_ID`` + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -970,8 +992,8 @@ def list_products( sent along with the request as metadata. Returns: - ~.pagers.ListProductsPager: - Response message for the ``ListProducts`` method. + google.cloud.vision_v1.services.product_search.pagers.ListProductsPager: + Response message for the ListProducts method. Iterating over this object will yield results and resolve additional pages automatically. @@ -1038,14 +1060,15 @@ def get_product( - Returns NOT_FOUND if the Product does not exist. Args: - request (:class:`~.product_search_service.GetProductRequest`): + request (google.cloud.vision_v1.types.GetProductRequest): The request object. Request message for the `GetProduct` method. - name (:class:`str`): + name (str): Required. Resource name of the Product to get. Format is: ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1057,7 +1080,7 @@ def get_product( sent along with the request as metadata. Returns: - ~.product_search_service.Product: + google.cloud.vision_v1.types.Product: A Product contains ReferenceImages. """ # Create or coerce a protobuf request object. @@ -1127,22 +1150,24 @@ def update_product( update_mask. Args: - request (:class:`~.product_search_service.UpdateProductRequest`): + request (google.cloud.vision_v1.types.UpdateProductRequest): The request object. Request message for the `UpdateProduct` method. - product (:class:`~.product_search_service.Product`): + product (google.cloud.vision_v1.types.Product): Required. The Product resource which replaces the one on the server. product.name is immutable. + This corresponds to the ``product`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - update_mask (:class:`~.field_mask.FieldMask`): + update_mask (google.protobuf.field_mask_pb2.FieldMask): The [FieldMask][google.protobuf.FieldMask] that specifies which fields to update. If update_mask isn't specified, all mutable fields are to be updated. Valid mask paths include ``product_labels``, ``display_name``, and ``description``. + This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1154,7 +1179,7 @@ def update_product( sent along with the request as metadata. Returns: - ~.product_search_service.Product: + google.cloud.vision_v1.types.Product: A Product contains ReferenceImages. """ # Create or coerce a protobuf request object. @@ -1217,14 +1242,15 @@ def delete_product( all related caches are refreshed. Args: - request (:class:`~.product_search_service.DeleteProductRequest`): + request (google.cloud.vision_v1.types.DeleteProductRequest): The request object. Request message for the `DeleteProduct` method. - name (:class:`str`): + name (str): Required. Resource name of product to delete. Format is: ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1308,31 +1334,34 @@ def create_reference_image( 10 polygons. Args: - request (:class:`~.product_search_service.CreateReferenceImageRequest`): + request (google.cloud.vision_v1.types.CreateReferenceImageRequest): The request object. Request message for the `CreateReferenceImage` method. - parent (:class:`str`): + parent (str): Required. Resource name of the product in which to create the reference image. Format is ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - reference_image (:class:`~.product_search_service.ReferenceImage`): + reference_image (google.cloud.vision_v1.types.ReferenceImage): Required. The reference image to create. If an image ID is specified, it is ignored. + This corresponds to the ``reference_image`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - reference_image_id (:class:`str`): + reference_image_id (str): A user-supplied resource id for the ReferenceImage to be added. If set, the server will attempt to use this value as the resource id. If it is already in use, an error is returned with code ALREADY_EXISTS. Must be at most 128 characters long. It cannot contain the character ``/``. + This corresponds to the ``reference_image_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1344,9 +1373,9 @@ def create_reference_image( sent along with the request as metadata. Returns: - ~.product_search_service.ReferenceImage: - A ``ReferenceImage`` represents a product image and its - associated metadata, such as bounding boxes. + google.cloud.vision_v1.types.ReferenceImage: + A ReferenceImage represents a product image and its associated metadata, + such as bounding boxes. """ # Create or coerce a protobuf request object. @@ -1410,16 +1439,16 @@ def delete_reference_image( Storage. Args: - request (:class:`~.product_search_service.DeleteReferenceImageRequest`): + request (google.cloud.vision_v1.types.DeleteReferenceImageRequest): The request object. Request message for the `DeleteReferenceImage` method. - name (:class:`str`): + name (str): Required. The resource name of the reference image to delete. Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1486,15 +1515,16 @@ def list_reference_images( 100, or less than 1. Args: - request (:class:`~.product_search_service.ListReferenceImagesRequest`): + request (google.cloud.vision_v1.types.ListReferenceImagesRequest): The request object. Request message for the `ListReferenceImages` method. - parent (:class:`str`): + parent (str): Required. Resource name of the product containing the reference images. Format is ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1506,8 +1536,8 @@ def list_reference_images( sent along with the request as metadata. Returns: - ~.pagers.ListReferenceImagesPager: - Response message for the ``ListReferenceImages`` method. + google.cloud.vision_v1.services.product_search.pagers.ListReferenceImagesPager: + Response message for the ListReferenceImages method. Iterating over this object will yield results and resolve additional pages automatically. @@ -1574,16 +1604,16 @@ def get_reference_image( - Returns NOT_FOUND if the specified image does not exist. Args: - request (:class:`~.product_search_service.GetReferenceImageRequest`): + request (google.cloud.vision_v1.types.GetReferenceImageRequest): The request object. Request message for the `GetReferenceImage` method. - name (:class:`str`): + name (str): Required. The resource name of the ReferenceImage to get. Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1595,9 +1625,9 @@ def get_reference_image( sent along with the request as metadata. Returns: - ~.product_search_service.ReferenceImage: - A ``ReferenceImage`` represents a product image and its - associated metadata, such as bounding boxes. + google.cloud.vision_v1.types.ReferenceImage: + A ReferenceImage represents a product image and its associated metadata, + such as bounding boxes. """ # Create or coerce a protobuf request object. @@ -1660,24 +1690,26 @@ def add_product_to_product_set( exist. Args: - request (:class:`~.product_search_service.AddProductToProductSetRequest`): + request (google.cloud.vision_v1.types.AddProductToProductSetRequest): The request object. Request message for the `AddProductToProductSet` method. - name (:class:`str`): + name (str): Required. The resource name for the ProductSet to modify. Format is: ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - product (:class:`str`): + product (str): Required. The resource name for the Product to be added to this ProductSet. Format is: ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + This corresponds to the ``product`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1745,24 +1777,26 @@ def remove_product_from_product_set( r"""Removes a Product from the specified ProductSet. Args: - request (:class:`~.product_search_service.RemoveProductFromProductSetRequest`): + request (google.cloud.vision_v1.types.RemoveProductFromProductSetRequest): The request object. Request message for the `RemoveProductFromProductSet` method. - name (:class:`str`): + name (str): Required. The resource name for the ProductSet to modify. Format is: ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - product (:class:`str`): + product (str): Required. The resource name for the Product to be removed from this ProductSet. Format is: ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + This corresponds to the ``product`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1836,15 +1870,16 @@ def list_products_in_product_set( less than 1. Args: - request (:class:`~.product_search_service.ListProductsInProductSetRequest`): + request (google.cloud.vision_v1.types.ListProductsInProductSetRequest): The request object. Request message for the `ListProductsInProductSet` method. - name (:class:`str`): + name (str): Required. The ProductSet resource for which to retrieve Products. Format is: ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1856,8 +1891,8 @@ def list_products_in_product_set( sent along with the request as metadata. Returns: - ~.pagers.ListProductsInProductSetPager: - Response message for the ``ListProductsInProductSet`` + google.cloud.vision_v1.services.product_search.pagers.ListProductsInProductSetPager: + Response message for the ListProductsInProductSet method. Iterating over this object will yield results and @@ -1937,20 +1972,22 @@ def import_product_sets( [ImportProductSetsGcsSource.csv_file_uri][google.cloud.vision.v1.ImportProductSetsGcsSource.csv_file_uri]. Args: - request (:class:`~.product_search_service.ImportProductSetsRequest`): + request (google.cloud.vision_v1.types.ImportProductSetsRequest): The request object. Request message for the `ImportProductSets` method. - parent (:class:`str`): + parent (str): Required. The project in which the ProductSets should be imported. Format is ``projects/PROJECT_ID/locations/LOC_ID``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - input_config (:class:`~.product_search_service.ImportProductSetsInputConfig`): + input_config (google.cloud.vision_v1.types.ImportProductSetsInputConfig): Required. The input content for the list of requests. + This corresponds to the ``input_config`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1962,18 +1999,18 @@ def import_product_sets( sent along with the request as metadata. Returns: - ~.operation.Operation: + google.api_core.operation.Operation: An object representing a long-running operation. The result type for the operation will be - :class:``~.product_search_service.ImportProductSetsResponse``: - Response message for the ``ImportProductSets`` method. + :class:`google.cloud.vision_v1.types.ImportProductSetsResponse` + Response message for the ImportProductSets method. - This message is returned by the - [google.longrunning.Operations.GetOperation][google.longrunning.Operations.GetOperation] - method in the returned - [google.longrunning.Operation.response][google.longrunning.Operation.response] - field. + This message is returned by the + [google.longrunning.Operations.GetOperation][google.longrunning.Operations.GetOperation] + method in the returned + [google.longrunning.Operation.response][google.longrunning.Operation.response] + field. """ # Create or coerce a protobuf request object. @@ -2063,14 +2100,15 @@ def purge_products( ``BatchOperationMetadata``. (progress) Args: - request (:class:`~.product_search_service.PurgeProductsRequest`): + request (google.cloud.vision_v1.types.PurgeProductsRequest): The request object. Request message for the `PurgeProducts` method. - parent (:class:`str`): + parent (str): Required. The project and location in which the Products should be deleted. Format is ``projects/PROJECT_ID/locations/LOC_ID``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -2082,24 +2120,22 @@ def purge_products( sent along with the request as metadata. Returns: - ~.operation.Operation: + google.api_core.operation.Operation: An object representing a long-running operation. - The result type for the operation will be - :class:``~.empty.Empty``: A generic empty message that - you can re-use to avoid defining duplicated empty - messages in your APIs. A typical example is to use it as - the request or the response type of an API method. For - instance: + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: - :: + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); - service Foo { - rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); - } + } - The JSON representation for ``Empty`` is empty JSON - object ``{}``. + The JSON representation for Empty is empty JSON + object {}. """ # Create or coerce a protobuf request object. diff --git a/google/cloud/vision_v1/services/product_search/pagers.py b/google/cloud/vision_v1/services/product_search/pagers.py index 69bc017f..8d317b18 100644 --- a/google/cloud/vision_v1/services/product_search/pagers.py +++ b/google/cloud/vision_v1/services/product_search/pagers.py @@ -15,7 +15,16 @@ # limitations under the License. # -from typing import Any, AsyncIterable, Awaitable, Callable, Iterable, Sequence, Tuple +from typing import ( + Any, + AsyncIterable, + Awaitable, + Callable, + Iterable, + Sequence, + Tuple, + Optional, +) from google.cloud.vision_v1.types import product_search_service @@ -24,7 +33,7 @@ class ListProductSetsPager: """A pager for iterating through ``list_product_sets`` requests. This class thinly wraps an initial - :class:`~.product_search_service.ListProductSetsResponse` object, and + :class:`google.cloud.vision_v1.types.ListProductSetsResponse` object, and provides an ``__iter__`` method to iterate through its ``product_sets`` field. @@ -33,7 +42,7 @@ class ListProductSetsPager: through the ``product_sets`` field on the corresponding responses. - All the usual :class:`~.product_search_service.ListProductSetsResponse` + All the usual :class:`google.cloud.vision_v1.types.ListProductSetsResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -51,9 +60,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.product_search_service.ListProductSetsRequest`): + request (google.cloud.vision_v1.types.ListProductSetsRequest): The initial request object. - response (:class:`~.product_search_service.ListProductSetsResponse`): + response (google.cloud.vision_v1.types.ListProductSetsResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -86,7 +95,7 @@ class ListProductSetsAsyncPager: """A pager for iterating through ``list_product_sets`` requests. This class thinly wraps an initial - :class:`~.product_search_service.ListProductSetsResponse` object, and + :class:`google.cloud.vision_v1.types.ListProductSetsResponse` object, and provides an ``__aiter__`` method to iterate through its ``product_sets`` field. @@ -95,7 +104,7 @@ class ListProductSetsAsyncPager: through the ``product_sets`` field on the corresponding responses. - All the usual :class:`~.product_search_service.ListProductSetsResponse` + All the usual :class:`google.cloud.vision_v1.types.ListProductSetsResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -115,9 +124,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.product_search_service.ListProductSetsRequest`): + request (google.cloud.vision_v1.types.ListProductSetsRequest): The initial request object. - response (:class:`~.product_search_service.ListProductSetsResponse`): + response (google.cloud.vision_v1.types.ListProductSetsResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -156,7 +165,7 @@ class ListProductsPager: """A pager for iterating through ``list_products`` requests. This class thinly wraps an initial - :class:`~.product_search_service.ListProductsResponse` object, and + :class:`google.cloud.vision_v1.types.ListProductsResponse` object, and provides an ``__iter__`` method to iterate through its ``products`` field. @@ -165,7 +174,7 @@ class ListProductsPager: through the ``products`` field on the corresponding responses. - All the usual :class:`~.product_search_service.ListProductsResponse` + All the usual :class:`google.cloud.vision_v1.types.ListProductsResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -183,9 +192,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.product_search_service.ListProductsRequest`): + request (google.cloud.vision_v1.types.ListProductsRequest): The initial request object. - response (:class:`~.product_search_service.ListProductsResponse`): + response (google.cloud.vision_v1.types.ListProductsResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -218,7 +227,7 @@ class ListProductsAsyncPager: """A pager for iterating through ``list_products`` requests. This class thinly wraps an initial - :class:`~.product_search_service.ListProductsResponse` object, and + :class:`google.cloud.vision_v1.types.ListProductsResponse` object, and provides an ``__aiter__`` method to iterate through its ``products`` field. @@ -227,7 +236,7 @@ class ListProductsAsyncPager: through the ``products`` field on the corresponding responses. - All the usual :class:`~.product_search_service.ListProductsResponse` + All the usual :class:`google.cloud.vision_v1.types.ListProductsResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -245,9 +254,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.product_search_service.ListProductsRequest`): + request (google.cloud.vision_v1.types.ListProductsRequest): The initial request object. - response (:class:`~.product_search_service.ListProductsResponse`): + response (google.cloud.vision_v1.types.ListProductsResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -284,7 +293,7 @@ class ListReferenceImagesPager: """A pager for iterating through ``list_reference_images`` requests. This class thinly wraps an initial - :class:`~.product_search_service.ListReferenceImagesResponse` object, and + :class:`google.cloud.vision_v1.types.ListReferenceImagesResponse` object, and provides an ``__iter__`` method to iterate through its ``reference_images`` field. @@ -293,7 +302,7 @@ class ListReferenceImagesPager: through the ``reference_images`` field on the corresponding responses. - All the usual :class:`~.product_search_service.ListReferenceImagesResponse` + All the usual :class:`google.cloud.vision_v1.types.ListReferenceImagesResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -311,9 +320,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.product_search_service.ListReferenceImagesRequest`): + request (google.cloud.vision_v1.types.ListReferenceImagesRequest): The initial request object. - response (:class:`~.product_search_service.ListReferenceImagesResponse`): + response (google.cloud.vision_v1.types.ListReferenceImagesResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -346,7 +355,7 @@ class ListReferenceImagesAsyncPager: """A pager for iterating through ``list_reference_images`` requests. This class thinly wraps an initial - :class:`~.product_search_service.ListReferenceImagesResponse` object, and + :class:`google.cloud.vision_v1.types.ListReferenceImagesResponse` object, and provides an ``__aiter__`` method to iterate through its ``reference_images`` field. @@ -355,7 +364,7 @@ class ListReferenceImagesAsyncPager: through the ``reference_images`` field on the corresponding responses. - All the usual :class:`~.product_search_service.ListReferenceImagesResponse` + All the usual :class:`google.cloud.vision_v1.types.ListReferenceImagesResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -375,9 +384,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.product_search_service.ListReferenceImagesRequest`): + request (google.cloud.vision_v1.types.ListReferenceImagesRequest): The initial request object. - response (:class:`~.product_search_service.ListReferenceImagesResponse`): + response (google.cloud.vision_v1.types.ListReferenceImagesResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -416,7 +425,7 @@ class ListProductsInProductSetPager: """A pager for iterating through ``list_products_in_product_set`` requests. This class thinly wraps an initial - :class:`~.product_search_service.ListProductsInProductSetResponse` object, and + :class:`google.cloud.vision_v1.types.ListProductsInProductSetResponse` object, and provides an ``__iter__`` method to iterate through its ``products`` field. @@ -425,7 +434,7 @@ class ListProductsInProductSetPager: through the ``products`` field on the corresponding responses. - All the usual :class:`~.product_search_service.ListProductsInProductSetResponse` + All the usual :class:`google.cloud.vision_v1.types.ListProductsInProductSetResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -443,9 +452,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.product_search_service.ListProductsInProductSetRequest`): + request (google.cloud.vision_v1.types.ListProductsInProductSetRequest): The initial request object. - response (:class:`~.product_search_service.ListProductsInProductSetResponse`): + response (google.cloud.vision_v1.types.ListProductsInProductSetResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -480,7 +489,7 @@ class ListProductsInProductSetAsyncPager: """A pager for iterating through ``list_products_in_product_set`` requests. This class thinly wraps an initial - :class:`~.product_search_service.ListProductsInProductSetResponse` object, and + :class:`google.cloud.vision_v1.types.ListProductsInProductSetResponse` object, and provides an ``__aiter__`` method to iterate through its ``products`` field. @@ -489,7 +498,7 @@ class ListProductsInProductSetAsyncPager: through the ``products`` field on the corresponding responses. - All the usual :class:`~.product_search_service.ListProductsInProductSetResponse` + All the usual :class:`google.cloud.vision_v1.types.ListProductsInProductSetResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -509,9 +518,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.product_search_service.ListProductsInProductSetRequest`): + request (google.cloud.vision_v1.types.ListProductsInProductSetRequest): The initial request object. - response (:class:`~.product_search_service.ListProductsInProductSetResponse`): + response (google.cloud.vision_v1.types.ListProductsInProductSetResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. diff --git a/google/cloud/vision_v1/services/product_search/transports/grpc.py b/google/cloud/vision_v1/services/product_search/transports/grpc.py index 76d646b7..fead6543 100644 --- a/google/cloud/vision_v1/services/product_search/transports/grpc.py +++ b/google/cloud/vision_v1/services/product_search/transports/grpc.py @@ -77,6 +77,7 @@ def __init__( api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -107,6 +108,10 @@ def __init__( ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -123,6 +128,11 @@ def __init__( """ self._ssl_channel_credentials = ssl_channel_credentials + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -132,11 +142,6 @@ def __init__( self._grpc_channel = channel self._ssl_channel_credentials = None elif api_mtls_endpoint: - warnings.warn( - "api_mtls_endpoint and client_cert_source are deprecated", - DeprecationWarning, - ) - host = ( api_mtls_endpoint if ":" in api_mtls_endpoint @@ -180,12 +185,18 @@ def __init__( scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id ) + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + # create a new channel. The provided one is ignored. self._grpc_channel = type(self).create_channel( host, credentials=credentials, credentials_file=credentials_file, - ssl_credentials=ssl_channel_credentials, + ssl_credentials=self._ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ diff --git a/google/cloud/vision_v1/services/product_search/transports/grpc_asyncio.py b/google/cloud/vision_v1/services/product_search/transports/grpc_asyncio.py index 76a9a2cf..9387ce67 100644 --- a/google/cloud/vision_v1/services/product_search/transports/grpc_asyncio.py +++ b/google/cloud/vision_v1/services/product_search/transports/grpc_asyncio.py @@ -121,6 +121,7 @@ def __init__( api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -152,6 +153,10 @@ def __init__( ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -168,6 +173,11 @@ def __init__( """ self._ssl_channel_credentials = ssl_channel_credentials + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -177,11 +187,6 @@ def __init__( self._grpc_channel = channel self._ssl_channel_credentials = None elif api_mtls_endpoint: - warnings.warn( - "api_mtls_endpoint and client_cert_source are deprecated", - DeprecationWarning, - ) - host = ( api_mtls_endpoint if ":" in api_mtls_endpoint @@ -225,12 +230,18 @@ def __init__( scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id ) + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + # create a new channel. The provided one is ignored. self._grpc_channel = type(self).create_channel( host, credentials=credentials, credentials_file=credentials_file, - ssl_credentials=ssl_channel_credentials, + ssl_credentials=self._ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ diff --git a/google/cloud/vision_v1/types/geometry.py b/google/cloud/vision_v1/types/geometry.py index be6f5602..05db4f69 100644 --- a/google/cloud/vision_v1/types/geometry.py +++ b/google/cloud/vision_v1/types/geometry.py @@ -62,9 +62,9 @@ class BoundingPoly(proto.Message): r"""A bounding polygon for the detected image annotation. Attributes: - vertices (Sequence[~.geometry.Vertex]): + vertices (Sequence[google.cloud.vision_v1.types.Vertex]): The bounding polygon vertices. - normalized_vertices (Sequence[~.geometry.NormalizedVertex]): + normalized_vertices (Sequence[google.cloud.vision_v1.types.NormalizedVertex]): The bounding polygon normalized vertices. """ diff --git a/google/cloud/vision_v1/types/image_annotator.py b/google/cloud/vision_v1/types/image_annotator.py index 462baf72..2a69494e 100644 --- a/google/cloud/vision_v1/types/image_annotator.py +++ b/google/cloud/vision_v1/types/image_annotator.py @@ -93,7 +93,7 @@ class Feature(proto.Message): ``Feature`` objects can be specified in the ``features`` list. Attributes: - type_ (~.image_annotator.Feature.Type): + type_ (google.cloud.vision_v1.types.Feature.Type): The feature type. max_results (int): Maximum number of results of this type. Does not apply to @@ -176,7 +176,11 @@ class Image(proto.Message): Image content, represented as a stream of bytes. Note: As with all ``bytes`` fields, protobuffers use a pure binary representation, whereas JSON representations use base64. - source (~.image_annotator.ImageSource): + + Currently, this field only works for BatchAnnotateImages + requests. It does not work for AsyncBatchAnnotateImages + requests. + source (google.cloud.vision_v1.types.ImageSource): Google Cloud Storage image location, or publicly-accessible image URL. If both ``content`` and ``source`` are provided for an image, ``content`` takes precedence and is used to @@ -193,7 +197,7 @@ class FaceAnnotation(proto.Message): detection. Attributes: - bounding_poly (~.geometry.BoundingPoly): + bounding_poly (google.cloud.vision_v1.types.BoundingPoly): The bounding polygon around the face. The coordinates of the bounding box are in the original image's scale. The bounding box is computed to "frame" the face in accordance with human @@ -201,7 +205,7 @@ class FaceAnnotation(proto.Message): that one or more x and/or y coordinates may not be generated in the ``BoundingPoly`` (the polygon will be unbounded) if only a partial face appears in the image to be annotated. - fd_bounding_poly (~.geometry.BoundingPoly): + fd_bounding_poly (google.cloud.vision_v1.types.BoundingPoly): The ``fd_bounding_poly`` bounding polygon is tighter than the ``boundingPoly``, and encloses only the skin part of the face. Typically, it is used to eliminate the face from any @@ -209,7 +213,7 @@ class FaceAnnotation(proto.Message): an image. It is not based on the landmarker results, only on the initial face detection, hence the fd (face detection) prefix. - landmarks (Sequence[~.image_annotator.FaceAnnotation.Landmark]): + landmarks (Sequence[google.cloud.vision_v1.types.FaceAnnotation.Landmark]): Detected face landmarks. roll_angle (float): Roll angle, which indicates the amount of @@ -228,19 +232,19 @@ class FaceAnnotation(proto.Message): Detection confidence. Range [0, 1]. landmarking_confidence (float): Face landmarking confidence. Range [0, 1]. - joy_likelihood (~.image_annotator.Likelihood): + joy_likelihood (google.cloud.vision_v1.types.Likelihood): Joy likelihood. - sorrow_likelihood (~.image_annotator.Likelihood): + sorrow_likelihood (google.cloud.vision_v1.types.Likelihood): Sorrow likelihood. - anger_likelihood (~.image_annotator.Likelihood): + anger_likelihood (google.cloud.vision_v1.types.Likelihood): Anger likelihood. - surprise_likelihood (~.image_annotator.Likelihood): + surprise_likelihood (google.cloud.vision_v1.types.Likelihood): Surprise likelihood. - under_exposed_likelihood (~.image_annotator.Likelihood): + under_exposed_likelihood (google.cloud.vision_v1.types.Likelihood): Under-exposed likelihood. - blurred_likelihood (~.image_annotator.Likelihood): + blurred_likelihood (google.cloud.vision_v1.types.Likelihood): Blurred likelihood. - headwear_likelihood (~.image_annotator.Likelihood): + headwear_likelihood (google.cloud.vision_v1.types.Likelihood): Headwear likelihood. """ @@ -248,9 +252,9 @@ class Landmark(proto.Message): r"""A face-specific landmark (for example, a face feature). Attributes: - type_ (~.image_annotator.FaceAnnotation.Landmark.Type): + type_ (google.cloud.vision_v1.types.FaceAnnotation.Landmark.Type): Face landmark type. - position (~.geometry.Position): + position (google.cloud.vision_v1.types.Position): Face landmark position. """ @@ -295,6 +299,8 @@ class Type(proto.Enum): CHIN_GNATHION = 32 CHIN_LEFT_GONION = 33 CHIN_RIGHT_GONION = 34 + LEFT_CHEEK_CENTER = 35 + RIGHT_CHEEK_CENTER = 36 type_ = proto.Field(proto.ENUM, number=3, enum="FaceAnnotation.Landmark.Type",) @@ -337,7 +343,7 @@ class LocationInfo(proto.Message): r"""Detected entity location information. Attributes: - lat_lng (~.latlng.LatLng): + lat_lng (google.type.latlng_pb2.LatLng): lat/long location coordinates. """ @@ -392,17 +398,17 @@ class EntityAnnotation(proto.Message): than to an image containing a detected distant towering building, even though the confidence that there is a tower in each image may be the same. Range [0, 1]. - bounding_poly (~.geometry.BoundingPoly): + bounding_poly (google.cloud.vision_v1.types.BoundingPoly): Image region to which this entity belongs. Not produced for ``LABEL_DETECTION`` features. - locations (Sequence[~.image_annotator.LocationInfo]): + locations (Sequence[google.cloud.vision_v1.types.LocationInfo]): The location information for the detected entity. Multiple ``LocationInfo`` elements can be present because one location may indicate the location of the scene in the image, and another location may indicate the location of the place where the image was taken. Location information is usually present for landmarks. - properties (Sequence[~.image_annotator.Property]): + properties (Sequence[google.cloud.vision_v1.types.Property]): Some entities may have optional user-supplied ``Property`` (name/value) fields, such a score or string that qualifies the entity. @@ -442,7 +448,7 @@ class LocalizedObjectAnnotation(proto.Message): Object name, expressed in its ``language_code`` language. score (float): Score of the result. Range [0, 1]. - bounding_poly (~.geometry.BoundingPoly): + bounding_poly (google.cloud.vision_v1.types.BoundingPoly): Image region to which this object belongs. This must be populated. """ @@ -464,21 +470,21 @@ class SafeSearchAnnotation(proto.Message): spoof, medical, violence). Attributes: - adult (~.image_annotator.Likelihood): + adult (google.cloud.vision_v1.types.Likelihood): Represents the adult content likelihood for the image. Adult content may contain elements such as nudity, pornographic images or cartoons, or sexual activities. - spoof (~.image_annotator.Likelihood): + spoof (google.cloud.vision_v1.types.Likelihood): Spoof likelihood. The likelihood that an modification was made to the image's canonical version to make it appear funny or offensive. - medical (~.image_annotator.Likelihood): + medical (google.cloud.vision_v1.types.Likelihood): Likelihood that this is a medical image. - violence (~.image_annotator.Likelihood): + violence (google.cloud.vision_v1.types.Likelihood): Likelihood that this image contains violent content. - racy (~.image_annotator.Likelihood): + racy (google.cloud.vision_v1.types.Likelihood): Likelihood that the request image contains racy content. Racy content may include (but is not limited to) skimpy or sheer clothing, @@ -532,9 +538,9 @@ class LatLongRect(proto.Message): r"""Rectangle determined by min and max ``LatLng`` pairs. Attributes: - min_lat_lng (~.latlng.LatLng): + min_lat_lng (google.type.latlng_pb2.LatLng): Min lat/long pair. - max_lat_lng (~.latlng.LatLng): + max_lat_lng (google.type.latlng_pb2.LatLng): Max lat/long pair. """ @@ -548,7 +554,7 @@ class ColorInfo(proto.Message): fraction of the image that the color occupies in the image. Attributes: - color (~.gt_color.Color): + color (google.type.color_pb2.Color): RGB components of the color. score (float): Image-specific score for this color. Value in range [0, 1]. @@ -568,7 +574,7 @@ class DominantColorsAnnotation(proto.Message): r"""Set of dominant colors and their corresponding scores. Attributes: - colors (Sequence[~.image_annotator.ColorInfo]): + colors (Sequence[google.cloud.vision_v1.types.ColorInfo]): RGB color values with their score and pixel fraction. """ @@ -580,7 +586,7 @@ class ImageProperties(proto.Message): r"""Stores image properties, such as dominant colors. Attributes: - dominant_colors (~.image_annotator.DominantColorsAnnotation): + dominant_colors (google.cloud.vision_v1.types.DominantColorsAnnotation): If present, dominant colors completed successfully. """ @@ -595,7 +601,7 @@ class CropHint(proto.Message): serving an image. Attributes: - bounding_poly (~.geometry.BoundingPoly): + bounding_poly (google.cloud.vision_v1.types.BoundingPoly): The bounding polygon for the crop region. The coordinates of the bounding box are in the original image's scale. @@ -618,7 +624,7 @@ class CropHintsAnnotation(proto.Message): serving images. Attributes: - crop_hints (Sequence[~.image_annotator.CropHint]): + crop_hints (Sequence[google.cloud.vision_v1.types.CropHint]): Crop hint results. """ @@ -673,7 +679,7 @@ class ImageContext(proto.Message): r"""Image context and/or feature-specific parameters. Attributes: - lat_long_rect (~.image_annotator.LatLongRect): + lat_long_rect (google.cloud.vision_v1.types.LatLongRect): Not used. language_hints (Sequence[str]): List of languages to use for TEXT_DETECTION. In most cases, @@ -686,13 +692,13 @@ class ImageContext(proto.Message): Text detection returns an error if one or more of the specified languages is not one of the `supported languages `__. - crop_hints_params (~.image_annotator.CropHintsParams): + crop_hints_params (google.cloud.vision_v1.types.CropHintsParams): Parameters for crop hints annotation request. - product_search_params (~.product_search.ProductSearchParams): + product_search_params (google.cloud.vision_v1.types.ProductSearchParams): Parameters for product search. - web_detection_params (~.image_annotator.WebDetectionParams): + web_detection_params (google.cloud.vision_v1.types.WebDetectionParams): Parameters for web detection. - text_detection_params (~.image_annotator.TextDetectionParams): + text_detection_params (google.cloud.vision_v1.types.TextDetectionParams): Parameters for text detection and document text detection. """ @@ -722,11 +728,11 @@ class AnnotateImageRequest(proto.Message): context information. Attributes: - image (~.image_annotator.Image): + image (google.cloud.vision_v1.types.Image): The image to be processed. - features (Sequence[~.image_annotator.Feature]): + features (Sequence[google.cloud.vision_v1.types.Feature]): Requested features. - image_context (~.image_annotator.ImageContext): + image_context (google.cloud.vision_v1.types.ImageContext): Additional context that may accompany the image. """ @@ -761,50 +767,50 @@ class AnnotateImageResponse(proto.Message): r"""Response to an image annotation request. Attributes: - face_annotations (Sequence[~.image_annotator.FaceAnnotation]): + face_annotations (Sequence[google.cloud.vision_v1.types.FaceAnnotation]): If present, face detection has completed successfully. - landmark_annotations (Sequence[~.image_annotator.EntityAnnotation]): + landmark_annotations (Sequence[google.cloud.vision_v1.types.EntityAnnotation]): If present, landmark detection has completed successfully. - logo_annotations (Sequence[~.image_annotator.EntityAnnotation]): + logo_annotations (Sequence[google.cloud.vision_v1.types.EntityAnnotation]): If present, logo detection has completed successfully. - label_annotations (Sequence[~.image_annotator.EntityAnnotation]): + label_annotations (Sequence[google.cloud.vision_v1.types.EntityAnnotation]): If present, label detection has completed successfully. - localized_object_annotations (Sequence[~.image_annotator.LocalizedObjectAnnotation]): + localized_object_annotations (Sequence[google.cloud.vision_v1.types.LocalizedObjectAnnotation]): If present, localized object detection has completed successfully. This will be sorted descending by confidence score. - text_annotations (Sequence[~.image_annotator.EntityAnnotation]): + text_annotations (Sequence[google.cloud.vision_v1.types.EntityAnnotation]): If present, text (OCR) detection has completed successfully. - full_text_annotation (~.text_annotation.TextAnnotation): + full_text_annotation (google.cloud.vision_v1.types.TextAnnotation): If present, text (OCR) detection or document (OCR) text detection has completed successfully. This annotation provides the structural hierarchy for the OCR detected text. - safe_search_annotation (~.image_annotator.SafeSearchAnnotation): + safe_search_annotation (google.cloud.vision_v1.types.SafeSearchAnnotation): If present, safe-search annotation has completed successfully. - image_properties_annotation (~.image_annotator.ImageProperties): + image_properties_annotation (google.cloud.vision_v1.types.ImageProperties): If present, image properties were extracted successfully. - crop_hints_annotation (~.image_annotator.CropHintsAnnotation): + crop_hints_annotation (google.cloud.vision_v1.types.CropHintsAnnotation): If present, crop hints have completed successfully. - web_detection (~.gcv_web_detection.WebDetection): + web_detection (google.cloud.vision_v1.types.WebDetection): If present, web detection has completed successfully. - product_search_results (~.product_search.ProductSearchResults): + product_search_results (google.cloud.vision_v1.types.ProductSearchResults): If present, product search has completed successfully. - error (~.status.Status): + error (google.rpc.status_pb2.Status): If set, represents the error message for the operation. Note that filled-in image annotations are guaranteed to be correct, even when ``error`` is set. - context (~.image_annotator.ImageAnnotationContext): + context (google.cloud.vision_v1.types.ImageAnnotationContext): If present, contextual information is needed to understand where this image comes from. """ @@ -867,7 +873,7 @@ class BatchAnnotateImagesRequest(proto.Message): service call. Attributes: - requests (Sequence[~.image_annotator.AnnotateImageRequest]): + requests (Sequence[google.cloud.vision_v1.types.AnnotateImageRequest]): Required. Individual image annotation requests for this batch. parent (str): @@ -896,7 +902,7 @@ class BatchAnnotateImagesResponse(proto.Message): r"""Response to a batch image annotation request. Attributes: - responses (Sequence[~.image_annotator.AnnotateImageResponse]): + responses (Sequence[google.cloud.vision_v1.types.AnnotateImageResponse]): Individual responses to image annotation requests within the batch. """ @@ -911,11 +917,11 @@ class AnnotateFileRequest(proto.Message): GIF file. Attributes: - input_config (~.image_annotator.InputConfig): + input_config (google.cloud.vision_v1.types.InputConfig): Required. Information about the input file. - features (Sequence[~.image_annotator.Feature]): + features (Sequence[google.cloud.vision_v1.types.Feature]): Required. Requested features. - image_context (~.image_annotator.ImageContext): + image_context (google.cloud.vision_v1.types.ImageContext): Additional context that may accompany the image(s) in the file. pages (Sequence[int]): @@ -951,16 +957,16 @@ class AnnotateFileResponse(proto.Message): responses. Attributes: - input_config (~.image_annotator.InputConfig): + input_config (google.cloud.vision_v1.types.InputConfig): Information about the file for which this response is generated. - responses (Sequence[~.image_annotator.AnnotateImageResponse]): + responses (Sequence[google.cloud.vision_v1.types.AnnotateImageResponse]): Individual responses to images found within the file. This field will be empty if the ``error`` field is set. total_pages (int): This field gives the total number of pages in the file. - error (~.status.Status): + error (google.rpc.status_pb2.Status): If set, represents the error message for the failed request. The ``responses`` field will not be set in this case. """ @@ -981,7 +987,7 @@ class BatchAnnotateFilesRequest(proto.Message): BatchAnnotateFiles API. Attributes: - requests (Sequence[~.image_annotator.AnnotateFileRequest]): + requests (Sequence[google.cloud.vision_v1.types.AnnotateFileRequest]): Required. The list of file annotation requests. Right now we support only one AnnotateFileRequest in @@ -1012,7 +1018,7 @@ class BatchAnnotateFilesResponse(proto.Message): r"""A list of file annotation responses. Attributes: - responses (Sequence[~.image_annotator.AnnotateFileResponse]): + responses (Sequence[google.cloud.vision_v1.types.AnnotateFileResponse]): The list of file annotation responses, each response corresponding to each AnnotateFileRequest in @@ -1028,14 +1034,14 @@ class AsyncAnnotateFileRequest(proto.Message): r"""An offline file annotation request. Attributes: - input_config (~.image_annotator.InputConfig): + input_config (google.cloud.vision_v1.types.InputConfig): Required. Information about the input file. - features (Sequence[~.image_annotator.Feature]): + features (Sequence[google.cloud.vision_v1.types.Feature]): Required. Requested features. - image_context (~.image_annotator.ImageContext): + image_context (google.cloud.vision_v1.types.ImageContext): Additional context that may accompany the image(s) in the file. - output_config (~.image_annotator.OutputConfig): + output_config (google.cloud.vision_v1.types.OutputConfig): Required. The desired output location and metadata (e.g. format). """ @@ -1053,7 +1059,7 @@ class AsyncAnnotateFileResponse(proto.Message): r"""The response for a single offline file annotation request. Attributes: - output_config (~.image_annotator.OutputConfig): + output_config (google.cloud.vision_v1.types.OutputConfig): The output location and metadata from AsyncAnnotateFileRequest. """ @@ -1065,10 +1071,10 @@ class AsyncBatchAnnotateImagesRequest(proto.Message): r"""Request for async image annotation for a list of images. Attributes: - requests (Sequence[~.image_annotator.AnnotateImageRequest]): + requests (Sequence[google.cloud.vision_v1.types.AnnotateImageRequest]): Required. Individual image annotation requests for this batch. - output_config (~.image_annotator.OutputConfig): + output_config (google.cloud.vision_v1.types.OutputConfig): Required. The desired output location and metadata (e.g. format). parent (str): @@ -1099,7 +1105,7 @@ class AsyncBatchAnnotateImagesResponse(proto.Message): r"""Response to an async batch image annotation request. Attributes: - output_config (~.image_annotator.OutputConfig): + output_config (google.cloud.vision_v1.types.OutputConfig): The output location and metadata from AsyncBatchAnnotateImagesRequest. """ @@ -1112,7 +1118,7 @@ class AsyncBatchAnnotateFilesRequest(proto.Message): single service call. Attributes: - requests (Sequence[~.image_annotator.AsyncAnnotateFileRequest]): + requests (Sequence[google.cloud.vision_v1.types.AsyncAnnotateFileRequest]): Required. Individual async file annotation requests for this batch. parent (str): @@ -1141,7 +1147,7 @@ class AsyncBatchAnnotateFilesResponse(proto.Message): r"""Response to an async batch file annotation request. Attributes: - responses (Sequence[~.image_annotator.AsyncAnnotateFileResponse]): + responses (Sequence[google.cloud.vision_v1.types.AsyncAnnotateFileResponse]): The list of file annotation responses, one for each request in AsyncBatchAnnotateFilesRequest. @@ -1156,7 +1162,7 @@ class InputConfig(proto.Message): r"""The desired input location and metadata. Attributes: - gcs_source (~.image_annotator.GcsSource): + gcs_source (google.cloud.vision_v1.types.GcsSource): The Google Cloud Storage location to read the input from. content (bytes): @@ -1184,7 +1190,7 @@ class OutputConfig(proto.Message): r"""The desired output location and metadata. Attributes: - gcs_destination (~.image_annotator.GcsDestination): + gcs_destination (google.cloud.vision_v1.types.GcsDestination): The Google Cloud Storage location to write the output(s) to. batch_size (int): @@ -1261,11 +1267,11 @@ class OperationMetadata(proto.Message): r"""Contains metadata for the BatchAnnotateImages operation. Attributes: - state (~.image_annotator.OperationMetadata.State): + state (google.cloud.vision_v1.types.OperationMetadata.State): Current state of the batch operation. - create_time (~.timestamp.Timestamp): + create_time (google.protobuf.timestamp_pb2.Timestamp): The time when the batch request was received. - update_time (~.timestamp.Timestamp): + update_time (google.protobuf.timestamp_pb2.Timestamp): The time when the operation result was last updated. """ diff --git a/google/cloud/vision_v1/types/product_search.py b/google/cloud/vision_v1/types/product_search.py index 6ae8f236..d28d3390 100644 --- a/google/cloud/vision_v1/types/product_search.py +++ b/google/cloud/vision_v1/types/product_search.py @@ -33,10 +33,10 @@ class ProductSearchParams(proto.Message): r"""Parameters for a product search request. Attributes: - bounding_poly (~.geometry.BoundingPoly): + bounding_poly (google.cloud.vision_v1.types.BoundingPoly): The bounding polygon around the area of - interest in the image. Optional. If it is not - specified, system discretion will be applied. + interest in the image. If it is not specified, + system discretion will be applied. product_set (str): The resource name of a [ProductSet][google.cloud.vision.v1.ProductSet] to be @@ -83,14 +83,14 @@ class ProductSearchResults(proto.Message): r"""Results for a product search request. Attributes: - index_time (~.timestamp.Timestamp): + index_time (google.protobuf.timestamp_pb2.Timestamp): Timestamp of the index which provided these results. Products added to the product set and products removed from the product set after this time are not reflected in the current results. - results (Sequence[~.product_search.ProductSearchResults.Result]): + results (Sequence[google.cloud.vision_v1.types.ProductSearchResults.Result]): List of results, one for each product match. - product_grouped_results (Sequence[~.product_search.ProductSearchResults.GroupedResult]): + product_grouped_results (Sequence[google.cloud.vision_v1.types.ProductSearchResults.GroupedResult]): List of results grouped by products detected in the query image. Each entry corresponds to one bounding polygon in the query image, and @@ -103,7 +103,7 @@ class Result(proto.Message): r"""Information about a product. Attributes: - product (~.product_search_service.Product): + product (google.cloud.vision_v1.types.Product): The Product. score (float): A confidence level on the match, ranging from @@ -151,12 +151,12 @@ class GroupedResult(proto.Message): a query image. Attributes: - bounding_poly (~.geometry.BoundingPoly): + bounding_poly (google.cloud.vision_v1.types.BoundingPoly): The bounding polygon around the product detected in the query image. - results (Sequence[~.product_search.ProductSearchResults.Result]): + results (Sequence[google.cloud.vision_v1.types.ProductSearchResults.Result]): List of results, one for each product match. - object_annotations (Sequence[~.product_search.ProductSearchResults.ObjectAnnotation]): + object_annotations (Sequence[google.cloud.vision_v1.types.ProductSearchResults.ObjectAnnotation]): List of generic predictions for the object in the bounding box. """ diff --git a/google/cloud/vision_v1/types/product_search_service.py b/google/cloud/vision_v1/types/product_search_service.py index f06e2eee..65cb5d7f 100644 --- a/google/cloud/vision_v1/types/product_search_service.py +++ b/google/cloud/vision_v1/types/product_search_service.py @@ -83,11 +83,12 @@ class Product(proto.Message): product_category (str): Immutable. The category for the product identified by the reference image. This should - be either "homegoods-v2", "apparel-v2", or - "toys-v2". The legacy categories "homegoods", - "apparel", and "toys" are still supported, but - these should not be used for new products. - product_labels (Sequence[~.product_search_service.Product.KeyValue]): + be one of "homegoods-v2", "apparel-v2", + "toys-v2", "packagedgoods-v1" or "general-v1". + The legacy categories "homegoods", "apparel", + and "toys" are still supported, but these should + not be used for new products. + product_labels (Sequence[google.cloud.vision_v1.types.Product.KeyValue]): Key-value pairs that can be attached to a product. At query time, constraints can be specified based on the product_labels. @@ -150,7 +151,7 @@ class ProductSet(proto.Message): The user-provided name for this ProductSet. Must not be empty. Must be at most 4096 characters long. - index_time (~.timestamp.Timestamp): + index_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The time at which this ProductSet was last indexed. Query results will reflect all updates before this time. If this @@ -160,7 +161,7 @@ class ProductSet(proto.Message): This field is ignored when creating a ProductSet. - index_error (~.status.Status): + index_error (google.rpc.status_pb2.Status): Output only. If there was an error with indexing the product set, the field is populated. @@ -186,7 +187,6 @@ class ReferenceImage(proto.Message): The resource name of the reference image. Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID``. This field is ignored when creating a reference image. @@ -195,7 +195,7 @@ class ReferenceImage(proto.Message): image. The URI must start with ``gs://``. - bounding_polys (Sequence[~.geometry.BoundingPoly]): + bounding_polys (Sequence[google.cloud.vision_v1.types.BoundingPoly]): Optional. Bounding polygons around the areas of interest in the reference image. If this field is empty, the system will try to detect @@ -226,7 +226,7 @@ class CreateProductRequest(proto.Message): created. Format is ``projects/PROJECT_ID/locations/LOC_ID``. - product (~.product_search_service.Product): + product (google.cloud.vision_v1.types.Product): Required. The product to create. product_id (str): A user-supplied resource id for this Product. If set, the @@ -271,7 +271,7 @@ class ListProductsResponse(proto.Message): r"""Response message for the ``ListProducts`` method. Attributes: - products (Sequence[~.product_search_service.Product]): + products (Sequence[google.cloud.vision_v1.types.Product]): List of products. next_page_token (str): Token to retrieve the next page of results, @@ -306,11 +306,11 @@ class UpdateProductRequest(proto.Message): r"""Request message for the ``UpdateProduct`` method. Attributes: - product (~.product_search_service.Product): + product (google.cloud.vision_v1.types.Product): Required. The Product resource which replaces the one on the server. product.name is immutable. - update_mask (~.field_mask.FieldMask): + update_mask (google.protobuf.field_mask_pb2.FieldMask): The [FieldMask][google.protobuf.FieldMask] that specifies which fields to update. If update_mask isn't specified, all mutable fields are to be updated. Valid mask paths include @@ -345,7 +345,7 @@ class CreateProductSetRequest(proto.Message): created. Format is ``projects/PROJECT_ID/locations/LOC_ID``. - product_set (~.product_search_service.ProductSet): + product_set (google.cloud.vision_v1.types.ProductSet): Required. The ProductSet to create. product_set_id (str): A user-supplied resource id for this ProductSet. If set, the @@ -390,7 +390,7 @@ class ListProductSetsResponse(proto.Message): r"""Response message for the ``ListProductSets`` method. Attributes: - product_sets (Sequence[~.product_search_service.ProductSet]): + product_sets (Sequence[google.cloud.vision_v1.types.ProductSet]): List of ProductSets. next_page_token (str): Token to retrieve the next page of results, @@ -415,7 +415,7 @@ class GetProductSetRequest(proto.Message): Required. Resource name of the ProductSet to get. Format is: - ``projects/PROJECT_ID/locations/LOG_ID/productSets/PRODUCT_SET_ID`` + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` """ name = proto.Field(proto.STRING, number=1) @@ -425,10 +425,10 @@ class UpdateProductSetRequest(proto.Message): r"""Request message for the ``UpdateProductSet`` method. Attributes: - product_set (~.product_search_service.ProductSet): + product_set (google.cloud.vision_v1.types.ProductSet): Required. The ProductSet resource which replaces the one on the server. - update_mask (~.field_mask.FieldMask): + update_mask (google.protobuf.field_mask_pb2.FieldMask): The [FieldMask][google.protobuf.FieldMask] that specifies which fields to update. If update_mask isn't specified, all mutable fields are to be updated. Valid mask path is @@ -464,7 +464,7 @@ class CreateReferenceImageRequest(proto.Message): Format is ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. - reference_image (~.product_search_service.ReferenceImage): + reference_image (google.cloud.vision_v1.types.ReferenceImage): Required. The reference image to create. If an image ID is specified, it is ignored. reference_image_id (str): @@ -514,7 +514,7 @@ class ListReferenceImagesResponse(proto.Message): r"""Response message for the ``ListReferenceImages`` method. Attributes: - reference_images (Sequence[~.product_search_service.ReferenceImage]): + reference_images (Sequence[google.cloud.vision_v1.types.ReferenceImage]): The list of reference images. page_size (int): The maximum number of items to return. @@ -545,7 +545,6 @@ class GetReferenceImageRequest(proto.Message): Required. The resource name of the ReferenceImage to get. Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID``. """ @@ -561,7 +560,6 @@ class DeleteReferenceImageRequest(proto.Message): delete. Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID`` """ @@ -641,7 +639,7 @@ class ListProductsInProductSetResponse(proto.Message): r"""Response message for the ``ListProductsInProductSet`` method. Attributes: - products (Sequence[~.product_search_service.Product]): + products (Sequence[google.cloud.vision_v1.types.Product]): The list of Products. next_page_token (str): Token to retrieve the next page of results, @@ -746,7 +744,7 @@ class ImportProductSetsInputConfig(proto.Message): r"""The input content for the ``ImportProductSets`` method. Attributes: - gcs_source (~.product_search_service.ImportProductSetsGcsSource): + gcs_source (google.cloud.vision_v1.types.ImportProductSetsGcsSource): The Google Cloud Storage location for a csv file which preserves a list of ImportProductSetRequests in each line. @@ -766,7 +764,7 @@ class ImportProductSetsRequest(proto.Message): imported. Format is ``projects/PROJECT_ID/locations/LOC_ID``. - input_config (~.product_search_service.ImportProductSetsInputConfig): + input_config (google.cloud.vision_v1.types.ImportProductSetsInputConfig): Required. The input content for the list of requests. """ @@ -788,9 +786,9 @@ class ImportProductSetsResponse(proto.Message): field. Attributes: - reference_images (Sequence[~.product_search_service.ReferenceImage]): + reference_images (Sequence[google.cloud.vision_v1.types.ReferenceImage]): The list of reference_images that are imported successfully. - statuses (Sequence[~.status.Status]): + statuses (Sequence[google.rpc.status_pb2.Status]): The rpc status for each ImportProductSet request, including both successes and errors. @@ -815,12 +813,12 @@ class BatchOperationMetadata(proto.Message): ``google::longrunning::Operations`` service. Attributes: - state (~.product_search_service.BatchOperationMetadata.State): + state (google.cloud.vision_v1.types.BatchOperationMetadata.State): The current state of the batch operation. - submit_time (~.timestamp.Timestamp): + submit_time (google.protobuf.timestamp_pb2.Timestamp): The time when the batch request was submitted to the server. - end_time (~.timestamp.Timestamp): + end_time (google.protobuf.timestamp_pb2.Timestamp): The time when the batch request is finished and [google.longrunning.Operation.done][google.longrunning.Operation.done] is set to true. @@ -861,7 +859,7 @@ class PurgeProductsRequest(proto.Message): r"""Request message for the ``PurgeProducts`` method. Attributes: - product_set_purge_config (~.product_search_service.ProductSetPurgeConfig): + product_set_purge_config (google.cloud.vision_v1.types.ProductSetPurgeConfig): Specify which ProductSet contains the Products to be deleted. delete_orphan_products (bool): diff --git a/google/cloud/vision_v1/types/text_annotation.py b/google/cloud/vision_v1/types/text_annotation.py index fa3b88ae..3f8e73a8 100644 --- a/google/cloud/vision_v1/types/text_annotation.py +++ b/google/cloud/vision_v1/types/text_annotation.py @@ -38,7 +38,7 @@ class TextAnnotation(proto.Message): message definition below for more detail. Attributes: - pages (Sequence[~.text_annotation.Page]): + pages (Sequence[google.cloud.vision_v1.types.Page]): List of pages detected by OCR. text (str): UTF-8 text detected on the pages. @@ -64,7 +64,7 @@ class DetectedBreak(proto.Message): r"""Detected start or end of a structural component. Attributes: - type_ (~.text_annotation.TextAnnotation.DetectedBreak.BreakType): + type_ (google.cloud.vision_v1.types.TextAnnotation.DetectedBreak.BreakType): Detected break type. is_prefix (bool): True if break prepends the element. @@ -89,10 +89,10 @@ class TextProperty(proto.Message): r"""Additional information detected on the structural component. Attributes: - detected_languages (Sequence[~.text_annotation.TextAnnotation.DetectedLanguage]): + detected_languages (Sequence[google.cloud.vision_v1.types.TextAnnotation.DetectedLanguage]): A list of detected languages together with confidence. - detected_break (~.text_annotation.TextAnnotation.DetectedBreak): + detected_break (google.cloud.vision_v1.types.TextAnnotation.DetectedBreak): Detected start or end of a text segment. """ @@ -113,7 +113,7 @@ class Page(proto.Message): r"""Detected page from OCR. Attributes: - property (~.text_annotation.TextAnnotation.TextProperty): + property (google.cloud.vision_v1.types.TextAnnotation.TextProperty): Additional information detected on the page. width (int): Page width. For PDFs the unit is points. For @@ -121,7 +121,7 @@ class Page(proto.Message): height (int): Page height. For PDFs the unit is points. For images (including TIFFs) the unit is pixels. - blocks (Sequence[~.text_annotation.Block]): + blocks (Sequence[google.cloud.vision_v1.types.Block]): List of blocks of text, images etc on this page. confidence (float): @@ -145,10 +145,10 @@ class Block(proto.Message): r"""Logical element on the page. Attributes: - property (~.text_annotation.TextAnnotation.TextProperty): + property (google.cloud.vision_v1.types.TextAnnotation.TextProperty): Additional information detected for the block. - bounding_box (~.geometry.BoundingPoly): + bounding_box (google.cloud.vision_v1.types.BoundingPoly): The bounding box for the block. The vertices are in the order of top-left, top-right, bottom-right, bottom-left. When a rotation of the bounding box is detected the rotation @@ -173,10 +173,10 @@ class Block(proto.Message): 1----0 and the vertex order will still be (0, 1, 2, 3). - paragraphs (Sequence[~.text_annotation.Paragraph]): + paragraphs (Sequence[google.cloud.vision_v1.types.Paragraph]): List of paragraphs in this block (if this blocks is of type text). - block_type (~.text_annotation.Block.BlockType): + block_type (google.cloud.vision_v1.types.Block.BlockType): Detected block type (text, image etc) for this block. confidence (float): @@ -210,10 +210,10 @@ class Paragraph(proto.Message): certain order. Attributes: - property (~.text_annotation.TextAnnotation.TextProperty): + property (google.cloud.vision_v1.types.TextAnnotation.TextProperty): Additional information detected for the paragraph. - bounding_box (~.geometry.BoundingPoly): + bounding_box (google.cloud.vision_v1.types.BoundingPoly): The bounding box for the paragraph. The vertices are in the order of top-left, top-right, bottom-right, bottom-left. When a rotation of the bounding box is detected the rotation @@ -225,7 +225,7 @@ class Paragraph(proto.Message): - when it's rotated 180 degrees around the top-left corner it becomes: 2----3 \| \| 1----0 and the vertex order will still be (0, 1, 2, 3). - words (Sequence[~.text_annotation.Word]): + words (Sequence[google.cloud.vision_v1.types.Word]): List of all words in this paragraph. confidence (float): Confidence of the OCR results for the paragraph. Range [0, @@ -247,9 +247,9 @@ class Word(proto.Message): r"""A word representation. Attributes: - property (~.text_annotation.TextAnnotation.TextProperty): + property (google.cloud.vision_v1.types.TextAnnotation.TextProperty): Additional information detected for the word. - bounding_box (~.geometry.BoundingPoly): + bounding_box (google.cloud.vision_v1.types.BoundingPoly): The bounding box for the word. The vertices are in the order of top-left, top-right, bottom-right, bottom-left. When a rotation of the bounding box is detected the rotation is @@ -261,7 +261,7 @@ class Word(proto.Message): - when it's rotated 180 degrees around the top-left corner it becomes: 2----3 \| \| 1----0 and the vertex order will still be (0, 1, 2, 3). - symbols (Sequence[~.text_annotation.Symbol]): + symbols (Sequence[google.cloud.vision_v1.types.Symbol]): List of symbols in the word. The order of the symbols follows the natural reading order. @@ -284,10 +284,10 @@ class Symbol(proto.Message): r"""A single symbol representation. Attributes: - property (~.text_annotation.TextAnnotation.TextProperty): + property (google.cloud.vision_v1.types.TextAnnotation.TextProperty): Additional information detected for the symbol. - bounding_box (~.geometry.BoundingPoly): + bounding_box (google.cloud.vision_v1.types.BoundingPoly): The bounding box for the symbol. The vertices are in the order of top-left, top-right, bottom-right, bottom-left. When a rotation of the bounding box is detected the rotation diff --git a/google/cloud/vision_v1/types/web_detection.py b/google/cloud/vision_v1/types/web_detection.py index 9395af29..7aa82a25 100644 --- a/google/cloud/vision_v1/types/web_detection.py +++ b/google/cloud/vision_v1/types/web_detection.py @@ -27,24 +27,24 @@ class WebDetection(proto.Message): r"""Relevant information for the image from the Internet. Attributes: - web_entities (Sequence[~.web_detection.WebDetection.WebEntity]): + web_entities (Sequence[google.cloud.vision_v1.types.WebDetection.WebEntity]): Deduced entities from similar images on the Internet. - full_matching_images (Sequence[~.web_detection.WebDetection.WebImage]): + full_matching_images (Sequence[google.cloud.vision_v1.types.WebDetection.WebImage]): Fully matching images from the Internet. Can include resized copies of the query image. - partial_matching_images (Sequence[~.web_detection.WebDetection.WebImage]): + partial_matching_images (Sequence[google.cloud.vision_v1.types.WebDetection.WebImage]): Partial matching images from the Internet. Those images are similar enough to share some key-point features. For example an original image will likely have partial matching for its crops. - pages_with_matching_images (Sequence[~.web_detection.WebDetection.WebPage]): + pages_with_matching_images (Sequence[google.cloud.vision_v1.types.WebDetection.WebPage]): Web pages containing the matching images from the Internet. - visually_similar_images (Sequence[~.web_detection.WebDetection.WebImage]): + visually_similar_images (Sequence[google.cloud.vision_v1.types.WebDetection.WebImage]): The visually similar image results. - best_guess_labels (Sequence[~.web_detection.WebDetection.WebLabel]): + best_guess_labels (Sequence[google.cloud.vision_v1.types.WebDetection.WebLabel]): The service's best guess as to the topic of the request image. Inferred from similar images on the open web. @@ -98,10 +98,10 @@ class WebPage(proto.Message): page_title (str): Title for the web page, may contain HTML markups. - full_matching_images (Sequence[~.web_detection.WebDetection.WebImage]): + full_matching_images (Sequence[google.cloud.vision_v1.types.WebDetection.WebImage]): Fully matching images on the page. Can include resized copies of the query image. - partial_matching_images (Sequence[~.web_detection.WebDetection.WebImage]): + partial_matching_images (Sequence[google.cloud.vision_v1.types.WebDetection.WebImage]): Partial matching images on the page. Those images are similar enough to share some key-point features. For example an original diff --git a/google/cloud/vision_v1p1beta1/services/image_annotator/async_client.py b/google/cloud/vision_v1p1beta1/services/image_annotator/async_client.py index 9099dd92..a5154e9d 100644 --- a/google/cloud/vision_v1p1beta1/services/image_annotator/async_client.py +++ b/google/cloud/vision_v1p1beta1/services/image_annotator/async_client.py @@ -76,6 +76,7 @@ class ImageAnnotatorAsyncClient: ImageAnnotatorClient.parse_common_location_path ) + from_service_account_info = ImageAnnotatorClient.from_service_account_info from_service_account_file = ImageAnnotatorClient.from_service_account_file from_service_account_json = from_service_account_file @@ -153,12 +154,13 @@ async def batch_annotate_images( images. Args: - request (:class:`~.image_annotator.BatchAnnotateImagesRequest`): + request (:class:`google.cloud.vision_v1p1beta1.types.BatchAnnotateImagesRequest`): The request object. Multiple image annotation requests are batched into a single service call. - requests (:class:`Sequence[~.image_annotator.AnnotateImageRequest]`): + requests (:class:`Sequence[google.cloud.vision_v1p1beta1.types.AnnotateImageRequest]`): Required. Individual image annotation requests for this batch. + This corresponds to the ``requests`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -170,7 +172,7 @@ async def batch_annotate_images( sent along with the request as metadata. Returns: - ~.image_annotator.BatchAnnotateImagesResponse: + google.cloud.vision_v1p1beta1.types.BatchAnnotateImagesResponse: Response to a batch image annotation request. diff --git a/google/cloud/vision_v1p1beta1/services/image_annotator/client.py b/google/cloud/vision_v1p1beta1/services/image_annotator/client.py index 9b133ea1..23d0dddd 100644 --- a/google/cloud/vision_v1p1beta1/services/image_annotator/client.py +++ b/google/cloud/vision_v1p1beta1/services/image_annotator/client.py @@ -113,6 +113,22 @@ def _get_default_mtls_endpoint(api_endpoint): DEFAULT_ENDPOINT ) + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + ImageAnnotatorClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_info(info) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials @@ -125,7 +141,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): kwargs: Additional arguments to pass to the constructor. Returns: - {@api.name}: The constructed client. + ImageAnnotatorClient: The constructed client. """ credentials = service_account.Credentials.from_service_account_file(filename) kwargs["credentials"] = credentials @@ -217,10 +233,10 @@ def __init__( credentials identify the application to the service; if none are specified, the client will attempt to ascertain the credentials from the environment. - transport (Union[str, ~.ImageAnnotatorTransport]): The + transport (Union[str, ImageAnnotatorTransport]): The transport to use. If set to None, a transport is chosen automatically. - client_options (client_options_lib.ClientOptions): Custom options for the + client_options (google.api_core.client_options.ClientOptions): Custom options for the client. It won't take effect if a ``transport`` instance is provided. (1) The ``api_endpoint`` property can be used to override the default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT @@ -256,21 +272,17 @@ def __init__( util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")) ) - ssl_credentials = None + client_cert_source_func = None is_mtls = False if use_client_cert: if client_options.client_cert_source: - import grpc # type: ignore - - cert, key = client_options.client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) is_mtls = True + client_cert_source_func = client_options.client_cert_source else: - creds = SslCredentials() - is_mtls = creds.is_mtls - ssl_credentials = creds.ssl_credentials if is_mtls else None + is_mtls = mtls.has_default_client_cert_source() + client_cert_source_func = ( + mtls.default_client_cert_source() if is_mtls else None + ) # Figure out which api endpoint to use. if client_options.api_endpoint is not None: @@ -313,7 +325,7 @@ def __init__( credentials_file=client_options.credentials_file, host=api_endpoint, scopes=client_options.scopes, - ssl_channel_credentials=ssl_credentials, + client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, ) @@ -331,12 +343,13 @@ def batch_annotate_images( images. Args: - request (:class:`~.image_annotator.BatchAnnotateImagesRequest`): + request (google.cloud.vision_v1p1beta1.types.BatchAnnotateImagesRequest): The request object. Multiple image annotation requests are batched into a single service call. - requests (:class:`Sequence[~.image_annotator.AnnotateImageRequest]`): + requests (Sequence[google.cloud.vision_v1p1beta1.types.AnnotateImageRequest]): Required. Individual image annotation requests for this batch. + This corresponds to the ``requests`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -348,7 +361,7 @@ def batch_annotate_images( sent along with the request as metadata. Returns: - ~.image_annotator.BatchAnnotateImagesResponse: + google.cloud.vision_v1p1beta1.types.BatchAnnotateImagesResponse: Response to a batch image annotation request. @@ -376,8 +389,8 @@ def batch_annotate_images( # If we have keyword arguments corresponding to fields on the # request, apply these. - if requests: - request.requests.extend(requests) + if requests is not None: + request.requests = requests # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. diff --git a/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc.py b/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc.py index 8dce4d82..3ed52718 100644 --- a/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc.py +++ b/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc.py @@ -60,6 +60,7 @@ def __init__( api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -90,6 +91,10 @@ def __init__( ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -106,6 +111,11 @@ def __init__( """ self._ssl_channel_credentials = ssl_channel_credentials + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -115,11 +125,6 @@ def __init__( self._grpc_channel = channel self._ssl_channel_credentials = None elif api_mtls_endpoint: - warnings.warn( - "api_mtls_endpoint and client_cert_source are deprecated", - DeprecationWarning, - ) - host = ( api_mtls_endpoint if ":" in api_mtls_endpoint @@ -163,12 +168,18 @@ def __init__( scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id ) + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + # create a new channel. The provided one is ignored. self._grpc_channel = type(self).create_channel( host, credentials=credentials, credentials_file=credentials_file, - ssl_credentials=ssl_channel_credentials, + ssl_credentials=self._ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ diff --git a/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc_asyncio.py b/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc_asyncio.py index 385f11ed..66f68f26 100644 --- a/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc_asyncio.py +++ b/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc_asyncio.py @@ -104,6 +104,7 @@ def __init__( api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -135,6 +136,10 @@ def __init__( ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -151,6 +156,11 @@ def __init__( """ self._ssl_channel_credentials = ssl_channel_credentials + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -160,11 +170,6 @@ def __init__( self._grpc_channel = channel self._ssl_channel_credentials = None elif api_mtls_endpoint: - warnings.warn( - "api_mtls_endpoint and client_cert_source are deprecated", - DeprecationWarning, - ) - host = ( api_mtls_endpoint if ":" in api_mtls_endpoint @@ -208,12 +213,18 @@ def __init__( scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id ) + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + # create a new channel. The provided one is ignored. self._grpc_channel = type(self).create_channel( host, credentials=credentials, credentials_file=credentials_file, - ssl_credentials=ssl_channel_credentials, + ssl_credentials=self._ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ diff --git a/google/cloud/vision_v1p1beta1/types/geometry.py b/google/cloud/vision_v1p1beta1/types/geometry.py index de248804..f581bee0 100644 --- a/google/cloud/vision_v1p1beta1/types/geometry.py +++ b/google/cloud/vision_v1p1beta1/types/geometry.py @@ -45,7 +45,7 @@ class BoundingPoly(proto.Message): r"""A bounding polygon for the detected image annotation. Attributes: - vertices (Sequence[~.geometry.Vertex]): + vertices (Sequence[google.cloud.vision_v1p1beta1.types.Vertex]): The bounding polygon vertices. """ diff --git a/google/cloud/vision_v1p1beta1/types/image_annotator.py b/google/cloud/vision_v1p1beta1/types/image_annotator.py index be04b15f..93f03cb8 100644 --- a/google/cloud/vision_v1p1beta1/types/image_annotator.py +++ b/google/cloud/vision_v1p1beta1/types/image_annotator.py @@ -76,7 +76,7 @@ class Feature(proto.Message): return. Attributes: - type_ (~.image_annotator.Feature.Type): + type_ (google.cloud.vision_v1p1beta1.types.Feature.Type): The feature type. max_results (int): Maximum number of results of this type. @@ -145,7 +145,7 @@ class Image(proto.Message): Image content, represented as a stream of bytes. Note: as with all ``bytes`` fields, protobuffers use a pure binary representation, whereas JSON representations use base64. - source (~.image_annotator.ImageSource): + source (google.cloud.vision_v1p1beta1.types.ImageSource): Google Cloud Storage image location. If both ``content`` and ``source`` are provided for an image, ``content`` takes precedence and is used to perform the image annotation @@ -162,7 +162,7 @@ class FaceAnnotation(proto.Message): detection. Attributes: - bounding_poly (~.geometry.BoundingPoly): + bounding_poly (google.cloud.vision_v1p1beta1.types.BoundingPoly): The bounding polygon around the face. The coordinates of the bounding box are in the original image's scale, as returned in ``ImageParams``. The bounding box is computed to "frame" @@ -171,7 +171,7 @@ class FaceAnnotation(proto.Message): coordinates may not be generated in the ``BoundingPoly`` (the polygon will be unbounded) if only a partial face appears in the image to be annotated. - fd_bounding_poly (~.geometry.BoundingPoly): + fd_bounding_poly (google.cloud.vision_v1p1beta1.types.BoundingPoly): The ``fd_bounding_poly`` bounding polygon is tighter than the ``boundingPoly``, and encloses only the skin part of the face. Typically, it is used to eliminate the face from any @@ -179,7 +179,7 @@ class FaceAnnotation(proto.Message): an image. It is not based on the landmarker results, only on the initial face detection, hence the fd (face detection) prefix. - landmarks (Sequence[~.image_annotator.FaceAnnotation.Landmark]): + landmarks (Sequence[google.cloud.vision_v1p1beta1.types.FaceAnnotation.Landmark]): Detected face landmarks. roll_angle (float): Roll angle, which indicates the amount of @@ -198,19 +198,19 @@ class FaceAnnotation(proto.Message): Detection confidence. Range [0, 1]. landmarking_confidence (float): Face landmarking confidence. Range [0, 1]. - joy_likelihood (~.image_annotator.Likelihood): + joy_likelihood (google.cloud.vision_v1p1beta1.types.Likelihood): Joy likelihood. - sorrow_likelihood (~.image_annotator.Likelihood): + sorrow_likelihood (google.cloud.vision_v1p1beta1.types.Likelihood): Sorrow likelihood. - anger_likelihood (~.image_annotator.Likelihood): + anger_likelihood (google.cloud.vision_v1p1beta1.types.Likelihood): Anger likelihood. - surprise_likelihood (~.image_annotator.Likelihood): + surprise_likelihood (google.cloud.vision_v1p1beta1.types.Likelihood): Surprise likelihood. - under_exposed_likelihood (~.image_annotator.Likelihood): + under_exposed_likelihood (google.cloud.vision_v1p1beta1.types.Likelihood): Under-exposed likelihood. - blurred_likelihood (~.image_annotator.Likelihood): + blurred_likelihood (google.cloud.vision_v1p1beta1.types.Likelihood): Blurred likelihood. - headwear_likelihood (~.image_annotator.Likelihood): + headwear_likelihood (google.cloud.vision_v1p1beta1.types.Likelihood): Headwear likelihood. """ @@ -218,9 +218,9 @@ class Landmark(proto.Message): r"""A face-specific landmark (for example, a face feature). Attributes: - type_ (~.image_annotator.FaceAnnotation.Landmark.Type): + type_ (google.cloud.vision_v1p1beta1.types.FaceAnnotation.Landmark.Type): Face landmark type. - position (~.geometry.Position): + position (google.cloud.vision_v1p1beta1.types.Position): Face landmark position. """ @@ -307,7 +307,7 @@ class LocationInfo(proto.Message): r"""Detected entity location information. Attributes: - lat_lng (~.latlng.LatLng): + lat_lng (google.type.latlng_pb2.LatLng): lat/long location coordinates. """ @@ -361,17 +361,17 @@ class EntityAnnotation(proto.Message): than to an image containing a detected distant towering building, even though the confidence that there is a tower in each image may be the same. Range [0, 1]. - bounding_poly (~.geometry.BoundingPoly): + bounding_poly (google.cloud.vision_v1p1beta1.types.BoundingPoly): Image region to which this entity belongs. Not produced for ``LABEL_DETECTION`` features. - locations (Sequence[~.image_annotator.LocationInfo]): + locations (Sequence[google.cloud.vision_v1p1beta1.types.LocationInfo]): The location information for the detected entity. Multiple ``LocationInfo`` elements can be present because one location may indicate the location of the scene in the image, and another location may indicate the location of the place where the image was taken. Location information is usually present for landmarks. - properties (Sequence[~.image_annotator.Property]): + properties (Sequence[google.cloud.vision_v1p1beta1.types.Property]): Some entities may have optional user-supplied ``Property`` (name/value) fields, such a score or string that qualifies the entity. @@ -402,21 +402,21 @@ class SafeSearchAnnotation(proto.Message): spoof, medical, violence). Attributes: - adult (~.image_annotator.Likelihood): + adult (google.cloud.vision_v1p1beta1.types.Likelihood): Represents the adult content likelihood for the image. Adult content may contain elements such as nudity, pornographic images or cartoons, or sexual activities. - spoof (~.image_annotator.Likelihood): + spoof (google.cloud.vision_v1p1beta1.types.Likelihood): Spoof likelihood. The likelihood that an modification was made to the image's canonical version to make it appear funny or offensive. - medical (~.image_annotator.Likelihood): + medical (google.cloud.vision_v1p1beta1.types.Likelihood): Likelihood that this is a medical image. - violence (~.image_annotator.Likelihood): + violence (google.cloud.vision_v1p1beta1.types.Likelihood): Likelihood that this image contains violent content. - racy (~.image_annotator.Likelihood): + racy (google.cloud.vision_v1p1beta1.types.Likelihood): Likelihood that the request image contains racy content. Racy content may include (but is not limited to) skimpy or sheer clothing, @@ -440,9 +440,9 @@ class LatLongRect(proto.Message): r"""Rectangle determined by min and max ``LatLng`` pairs. Attributes: - min_lat_lng (~.latlng.LatLng): + min_lat_lng (google.type.latlng_pb2.LatLng): Min lat/long pair. - max_lat_lng (~.latlng.LatLng): + max_lat_lng (google.type.latlng_pb2.LatLng): Max lat/long pair. """ @@ -456,7 +456,7 @@ class ColorInfo(proto.Message): fraction of the image that the color occupies in the image. Attributes: - color (~.gt_color.Color): + color (google.type.color_pb2.Color): RGB components of the color. score (float): Image-specific score for this color. Value in range [0, 1]. @@ -476,7 +476,7 @@ class DominantColorsAnnotation(proto.Message): r"""Set of dominant colors and their corresponding scores. Attributes: - colors (Sequence[~.image_annotator.ColorInfo]): + colors (Sequence[google.cloud.vision_v1p1beta1.types.ColorInfo]): RGB color values with their score and pixel fraction. """ @@ -488,7 +488,7 @@ class ImageProperties(proto.Message): r"""Stores image properties, such as dominant colors. Attributes: - dominant_colors (~.image_annotator.DominantColorsAnnotation): + dominant_colors (google.cloud.vision_v1p1beta1.types.DominantColorsAnnotation): If present, dominant colors completed successfully. """ @@ -503,7 +503,7 @@ class CropHint(proto.Message): serving an image. Attributes: - bounding_poly (~.geometry.BoundingPoly): + bounding_poly (google.cloud.vision_v1p1beta1.types.BoundingPoly): The bounding polygon for the crop region. The coordinates of the bounding box are in the original image's scale, as returned in ``ImageParams``. @@ -526,7 +526,7 @@ class CropHintsAnnotation(proto.Message): serving images. Attributes: - crop_hints (Sequence[~.image_annotator.CropHint]): + crop_hints (Sequence[google.cloud.vision_v1p1beta1.types.CropHint]): Crop hint results. """ @@ -581,7 +581,7 @@ class ImageContext(proto.Message): r"""Image context and/or feature-specific parameters. Attributes: - lat_long_rect (~.image_annotator.LatLongRect): + lat_long_rect (google.cloud.vision_v1p1beta1.types.LatLongRect): lat/long rectangle that specifies the location of the image. language_hints (Sequence[str]): @@ -595,11 +595,11 @@ class ImageContext(proto.Message): Text detection returns an error if one or more of the specified languages is not one of the `supported languages `__. - crop_hints_params (~.image_annotator.CropHintsParams): + crop_hints_params (google.cloud.vision_v1p1beta1.types.CropHintsParams): Parameters for crop hints annotation request. - web_detection_params (~.image_annotator.WebDetectionParams): + web_detection_params (google.cloud.vision_v1p1beta1.types.WebDetectionParams): Parameters for web detection. - text_detection_params (~.image_annotator.TextDetectionParams): + text_detection_params (google.cloud.vision_v1p1beta1.types.TextDetectionParams): Parameters for text detection and document text detection. """ @@ -624,11 +624,11 @@ class AnnotateImageRequest(proto.Message): user-provided image, with user-requested features. Attributes: - image (~.image_annotator.Image): + image (google.cloud.vision_v1p1beta1.types.Image): The image to be processed. - features (Sequence[~.image_annotator.Feature]): + features (Sequence[google.cloud.vision_v1p1beta1.types.Feature]): Requested features. - image_context (~.image_annotator.ImageContext): + image_context (google.cloud.vision_v1p1beta1.types.ImageContext): Additional context that may accompany the image. """ @@ -644,39 +644,39 @@ class AnnotateImageResponse(proto.Message): r"""Response to an image annotation request. Attributes: - face_annotations (Sequence[~.image_annotator.FaceAnnotation]): + face_annotations (Sequence[google.cloud.vision_v1p1beta1.types.FaceAnnotation]): If present, face detection has completed successfully. - landmark_annotations (Sequence[~.image_annotator.EntityAnnotation]): + landmark_annotations (Sequence[google.cloud.vision_v1p1beta1.types.EntityAnnotation]): If present, landmark detection has completed successfully. - logo_annotations (Sequence[~.image_annotator.EntityAnnotation]): + logo_annotations (Sequence[google.cloud.vision_v1p1beta1.types.EntityAnnotation]): If present, logo detection has completed successfully. - label_annotations (Sequence[~.image_annotator.EntityAnnotation]): + label_annotations (Sequence[google.cloud.vision_v1p1beta1.types.EntityAnnotation]): If present, label detection has completed successfully. - text_annotations (Sequence[~.image_annotator.EntityAnnotation]): + text_annotations (Sequence[google.cloud.vision_v1p1beta1.types.EntityAnnotation]): If present, text (OCR) detection has completed successfully. - full_text_annotation (~.text_annotation.TextAnnotation): + full_text_annotation (google.cloud.vision_v1p1beta1.types.TextAnnotation): If present, text (OCR) detection or document (OCR) text detection has completed successfully. This annotation provides the structural hierarchy for the OCR detected text. - safe_search_annotation (~.image_annotator.SafeSearchAnnotation): + safe_search_annotation (google.cloud.vision_v1p1beta1.types.SafeSearchAnnotation): If present, safe-search annotation has completed successfully. - image_properties_annotation (~.image_annotator.ImageProperties): + image_properties_annotation (google.cloud.vision_v1p1beta1.types.ImageProperties): If present, image properties were extracted successfully. - crop_hints_annotation (~.image_annotator.CropHintsAnnotation): + crop_hints_annotation (google.cloud.vision_v1p1beta1.types.CropHintsAnnotation): If present, crop hints have completed successfully. - web_detection (~.gcv_web_detection.WebDetection): + web_detection (google.cloud.vision_v1p1beta1.types.WebDetection): If present, web detection has completed successfully. - error (~.status.Status): + error (google.rpc.status_pb2.Status): If set, represents the error message for the operation. Note that filled-in image annotations are guaranteed to be correct, even when ``error`` is set. @@ -730,7 +730,7 @@ class BatchAnnotateImagesRequest(proto.Message): service call. Attributes: - requests (Sequence[~.image_annotator.AnnotateImageRequest]): + requests (Sequence[google.cloud.vision_v1p1beta1.types.AnnotateImageRequest]): Required. Individual image annotation requests for this batch. """ @@ -744,7 +744,7 @@ class BatchAnnotateImagesResponse(proto.Message): r"""Response to a batch image annotation request. Attributes: - responses (Sequence[~.image_annotator.AnnotateImageResponse]): + responses (Sequence[google.cloud.vision_v1p1beta1.types.AnnotateImageResponse]): Individual responses to image annotation requests within the batch. """ diff --git a/google/cloud/vision_v1p1beta1/types/text_annotation.py b/google/cloud/vision_v1p1beta1/types/text_annotation.py index 8e231b4b..23b249fe 100644 --- a/google/cloud/vision_v1p1beta1/types/text_annotation.py +++ b/google/cloud/vision_v1p1beta1/types/text_annotation.py @@ -38,7 +38,7 @@ class TextAnnotation(proto.Message): message definition below for more detail. Attributes: - pages (Sequence[~.text_annotation.Page]): + pages (Sequence[google.cloud.vision_v1p1beta1.types.Page]): List of pages detected by OCR. text (str): UTF-8 text detected on the pages. @@ -64,7 +64,7 @@ class DetectedBreak(proto.Message): r"""Detected start or end of a structural component. Attributes: - type_ (~.text_annotation.TextAnnotation.DetectedBreak.BreakType): + type_ (google.cloud.vision_v1p1beta1.types.TextAnnotation.DetectedBreak.BreakType): Detected break type. is_prefix (bool): True if break prepends the element. @@ -89,10 +89,10 @@ class TextProperty(proto.Message): r"""Additional information detected on the structural component. Attributes: - detected_languages (Sequence[~.text_annotation.TextAnnotation.DetectedLanguage]): + detected_languages (Sequence[google.cloud.vision_v1p1beta1.types.TextAnnotation.DetectedLanguage]): A list of detected languages together with confidence. - detected_break (~.text_annotation.TextAnnotation.DetectedBreak): + detected_break (google.cloud.vision_v1p1beta1.types.TextAnnotation.DetectedBreak): Detected start or end of a text segment. """ @@ -113,13 +113,13 @@ class Page(proto.Message): r"""Detected page from OCR. Attributes: - property (~.text_annotation.TextAnnotation.TextProperty): + property (google.cloud.vision_v1p1beta1.types.TextAnnotation.TextProperty): Additional information detected on the page. width (int): Page width in pixels. height (int): Page height in pixels. - blocks (Sequence[~.text_annotation.Block]): + blocks (Sequence[google.cloud.vision_v1p1beta1.types.Block]): List of blocks of text, images etc on this page. confidence (float): @@ -143,10 +143,10 @@ class Block(proto.Message): r"""Logical element on the page. Attributes: - property (~.text_annotation.TextAnnotation.TextProperty): + property (google.cloud.vision_v1p1beta1.types.TextAnnotation.TextProperty): Additional information detected for the block. - bounding_box (~.geometry.BoundingPoly): + bounding_box (google.cloud.vision_v1p1beta1.types.BoundingPoly): The bounding box for the block. The vertices are in the order of top-left, top-right, bottom-right, bottom-left. When a rotation of the bounding box is detected the rotation @@ -158,10 +158,10 @@ class Block(proto.Message): - when it's rotated 180 degrees around the top-left corner it becomes: 2----3 \| \| 1----0 and the vertice order will still be (0, 1, 2, 3). - paragraphs (Sequence[~.text_annotation.Paragraph]): + paragraphs (Sequence[google.cloud.vision_v1p1beta1.types.Paragraph]): List of paragraphs in this block (if this blocks is of type text). - block_type (~.text_annotation.Block.BlockType): + block_type (google.cloud.vision_v1p1beta1.types.Block.BlockType): Detected block type (text, image etc) for this block. confidence (float): @@ -195,10 +195,10 @@ class Paragraph(proto.Message): certain order. Attributes: - property (~.text_annotation.TextAnnotation.TextProperty): + property (google.cloud.vision_v1p1beta1.types.TextAnnotation.TextProperty): Additional information detected for the paragraph. - bounding_box (~.geometry.BoundingPoly): + bounding_box (google.cloud.vision_v1p1beta1.types.BoundingPoly): The bounding box for the paragraph. The vertices are in the order of top-left, top-right, bottom-right, bottom-left. When a rotation of the bounding box is detected the rotation @@ -210,7 +210,7 @@ class Paragraph(proto.Message): - when it's rotated 180 degrees around the top-left corner it becomes: 2----3 \| \| 1----0 and the vertice order will still be (0, 1, 2, 3). - words (Sequence[~.text_annotation.Word]): + words (Sequence[google.cloud.vision_v1p1beta1.types.Word]): List of words in this paragraph. confidence (float): Confidence of the OCR results for the paragraph. Range [0, @@ -232,9 +232,9 @@ class Word(proto.Message): r"""A word representation. Attributes: - property (~.text_annotation.TextAnnotation.TextProperty): + property (google.cloud.vision_v1p1beta1.types.TextAnnotation.TextProperty): Additional information detected for the word. - bounding_box (~.geometry.BoundingPoly): + bounding_box (google.cloud.vision_v1p1beta1.types.BoundingPoly): The bounding box for the word. The vertices are in the order of top-left, top-right, bottom-right, bottom-left. When a rotation of the bounding box is detected the rotation is @@ -246,7 +246,7 @@ class Word(proto.Message): - when it's rotated 180 degrees around the top-left corner it becomes: 2----3 \| \| 1----0 and the vertice order will still be (0, 1, 2, 3). - symbols (Sequence[~.text_annotation.Symbol]): + symbols (Sequence[google.cloud.vision_v1p1beta1.types.Symbol]): List of symbols in the word. The order of the symbols follows the natural reading order. @@ -269,10 +269,10 @@ class Symbol(proto.Message): r"""A single symbol representation. Attributes: - property (~.text_annotation.TextAnnotation.TextProperty): + property (google.cloud.vision_v1p1beta1.types.TextAnnotation.TextProperty): Additional information detected for the symbol. - bounding_box (~.geometry.BoundingPoly): + bounding_box (google.cloud.vision_v1p1beta1.types.BoundingPoly): The bounding box for the symbol. The vertices are in the order of top-left, top-right, bottom-right, bottom-left. When a rotation of the bounding box is detected the rotation diff --git a/google/cloud/vision_v1p1beta1/types/web_detection.py b/google/cloud/vision_v1p1beta1/types/web_detection.py index 6bd91777..1e9586d6 100644 --- a/google/cloud/vision_v1p1beta1/types/web_detection.py +++ b/google/cloud/vision_v1p1beta1/types/web_detection.py @@ -27,24 +27,24 @@ class WebDetection(proto.Message): r"""Relevant information for the image from the Internet. Attributes: - web_entities (Sequence[~.web_detection.WebDetection.WebEntity]): + web_entities (Sequence[google.cloud.vision_v1p1beta1.types.WebDetection.WebEntity]): Deduced entities from similar images on the Internet. - full_matching_images (Sequence[~.web_detection.WebDetection.WebImage]): + full_matching_images (Sequence[google.cloud.vision_v1p1beta1.types.WebDetection.WebImage]): Fully matching images from the Internet. Can include resized copies of the query image. - partial_matching_images (Sequence[~.web_detection.WebDetection.WebImage]): + partial_matching_images (Sequence[google.cloud.vision_v1p1beta1.types.WebDetection.WebImage]): Partial matching images from the Internet. Those images are similar enough to share some key-point features. For example an original image will likely have partial matching for its crops. - pages_with_matching_images (Sequence[~.web_detection.WebDetection.WebPage]): + pages_with_matching_images (Sequence[google.cloud.vision_v1p1beta1.types.WebDetection.WebPage]): Web pages containing the matching images from the Internet. - visually_similar_images (Sequence[~.web_detection.WebDetection.WebImage]): + visually_similar_images (Sequence[google.cloud.vision_v1p1beta1.types.WebDetection.WebImage]): The visually similar image results. - best_guess_labels (Sequence[~.web_detection.WebDetection.WebLabel]): + best_guess_labels (Sequence[google.cloud.vision_v1p1beta1.types.WebDetection.WebLabel]): Best guess text labels for the request image. """ @@ -96,10 +96,10 @@ class WebPage(proto.Message): page_title (str): Title for the web page, may contain HTML markups. - full_matching_images (Sequence[~.web_detection.WebDetection.WebImage]): + full_matching_images (Sequence[google.cloud.vision_v1p1beta1.types.WebDetection.WebImage]): Fully matching images on the page. Can include resized copies of the query image. - partial_matching_images (Sequence[~.web_detection.WebDetection.WebImage]): + partial_matching_images (Sequence[google.cloud.vision_v1p1beta1.types.WebDetection.WebImage]): Partial matching images on the page. Those images are similar enough to share some key-point features. For example an original diff --git a/google/cloud/vision_v1p2beta1/services/image_annotator/async_client.py b/google/cloud/vision_v1p2beta1/services/image_annotator/async_client.py index e28c5f19..c2efa184 100644 --- a/google/cloud/vision_v1p2beta1/services/image_annotator/async_client.py +++ b/google/cloud/vision_v1p2beta1/services/image_annotator/async_client.py @@ -78,6 +78,7 @@ class ImageAnnotatorAsyncClient: ImageAnnotatorClient.parse_common_location_path ) + from_service_account_info = ImageAnnotatorClient.from_service_account_info from_service_account_file = ImageAnnotatorClient.from_service_account_file from_service_account_json = from_service_account_file @@ -155,12 +156,13 @@ async def batch_annotate_images( images. Args: - request (:class:`~.image_annotator.BatchAnnotateImagesRequest`): + request (:class:`google.cloud.vision_v1p2beta1.types.BatchAnnotateImagesRequest`): The request object. Multiple image annotation requests are batched into a single service call. - requests (:class:`Sequence[~.image_annotator.AnnotateImageRequest]`): + requests (:class:`Sequence[google.cloud.vision_v1p2beta1.types.AnnotateImageRequest]`): Required. Individual image annotation requests for this batch. + This corresponds to the ``requests`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -172,7 +174,7 @@ async def batch_annotate_images( sent along with the request as metadata. Returns: - ~.image_annotator.BatchAnnotateImagesResponse: + google.cloud.vision_v1p2beta1.types.BatchAnnotateImagesResponse: Response to a batch image annotation request. @@ -235,12 +237,13 @@ async def async_batch_annotate_files( ``AsyncBatchAnnotateFilesResponse`` (results). Args: - request (:class:`~.image_annotator.AsyncBatchAnnotateFilesRequest`): + request (:class:`google.cloud.vision_v1p2beta1.types.AsyncBatchAnnotateFilesRequest`): The request object. Multiple async file annotation requests are batched into a single service call. - requests (:class:`Sequence[~.image_annotator.AsyncAnnotateFileRequest]`): + requests (:class:`Sequence[google.cloud.vision_v1p2beta1.types.AsyncAnnotateFileRequest]`): Required. Individual async file annotation requests for this batch. + This corresponds to the ``requests`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -252,11 +255,11 @@ async def async_batch_annotate_files( sent along with the request as metadata. Returns: - ~.operation_async.AsyncOperation: + google.api_core.operation_async.AsyncOperation: An object representing a long-running operation. The result type for the operation will be - :class:``~.image_annotator.AsyncBatchAnnotateFilesResponse``: + :class:`google.cloud.vision_v1p2beta1.types.AsyncBatchAnnotateFilesResponse` Response to an async batch file annotation request. """ diff --git a/google/cloud/vision_v1p2beta1/services/image_annotator/client.py b/google/cloud/vision_v1p2beta1/services/image_annotator/client.py index c86c318b..25d7616a 100644 --- a/google/cloud/vision_v1p2beta1/services/image_annotator/client.py +++ b/google/cloud/vision_v1p2beta1/services/image_annotator/client.py @@ -115,6 +115,22 @@ def _get_default_mtls_endpoint(api_endpoint): DEFAULT_ENDPOINT ) + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + ImageAnnotatorClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_info(info) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials @@ -127,7 +143,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): kwargs: Additional arguments to pass to the constructor. Returns: - {@api.name}: The constructed client. + ImageAnnotatorClient: The constructed client. """ credentials = service_account.Credentials.from_service_account_file(filename) kwargs["credentials"] = credentials @@ -219,10 +235,10 @@ def __init__( credentials identify the application to the service; if none are specified, the client will attempt to ascertain the credentials from the environment. - transport (Union[str, ~.ImageAnnotatorTransport]): The + transport (Union[str, ImageAnnotatorTransport]): The transport to use. If set to None, a transport is chosen automatically. - client_options (client_options_lib.ClientOptions): Custom options for the + client_options (google.api_core.client_options.ClientOptions): Custom options for the client. It won't take effect if a ``transport`` instance is provided. (1) The ``api_endpoint`` property can be used to override the default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT @@ -258,21 +274,17 @@ def __init__( util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")) ) - ssl_credentials = None + client_cert_source_func = None is_mtls = False if use_client_cert: if client_options.client_cert_source: - import grpc # type: ignore - - cert, key = client_options.client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) is_mtls = True + client_cert_source_func = client_options.client_cert_source else: - creds = SslCredentials() - is_mtls = creds.is_mtls - ssl_credentials = creds.ssl_credentials if is_mtls else None + is_mtls = mtls.has_default_client_cert_source() + client_cert_source_func = ( + mtls.default_client_cert_source() if is_mtls else None + ) # Figure out which api endpoint to use. if client_options.api_endpoint is not None: @@ -315,7 +327,7 @@ def __init__( credentials_file=client_options.credentials_file, host=api_endpoint, scopes=client_options.scopes, - ssl_channel_credentials=ssl_credentials, + client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, ) @@ -333,12 +345,13 @@ def batch_annotate_images( images. Args: - request (:class:`~.image_annotator.BatchAnnotateImagesRequest`): + request (google.cloud.vision_v1p2beta1.types.BatchAnnotateImagesRequest): The request object. Multiple image annotation requests are batched into a single service call. - requests (:class:`Sequence[~.image_annotator.AnnotateImageRequest]`): + requests (Sequence[google.cloud.vision_v1p2beta1.types.AnnotateImageRequest]): Required. Individual image annotation requests for this batch. + This corresponds to the ``requests`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -350,7 +363,7 @@ def batch_annotate_images( sent along with the request as metadata. Returns: - ~.image_annotator.BatchAnnotateImagesResponse: + google.cloud.vision_v1p2beta1.types.BatchAnnotateImagesResponse: Response to a batch image annotation request. @@ -378,8 +391,8 @@ def batch_annotate_images( # If we have keyword arguments corresponding to fields on the # request, apply these. - if requests: - request.requests.extend(requests) + if requests is not None: + request.requests = requests # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -409,12 +422,13 @@ def async_batch_annotate_files( ``AsyncBatchAnnotateFilesResponse`` (results). Args: - request (:class:`~.image_annotator.AsyncBatchAnnotateFilesRequest`): + request (google.cloud.vision_v1p2beta1.types.AsyncBatchAnnotateFilesRequest): The request object. Multiple async file annotation requests are batched into a single service call. - requests (:class:`Sequence[~.image_annotator.AsyncAnnotateFileRequest]`): + requests (Sequence[google.cloud.vision_v1p2beta1.types.AsyncAnnotateFileRequest]): Required. Individual async file annotation requests for this batch. + This corresponds to the ``requests`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -426,11 +440,11 @@ def async_batch_annotate_files( sent along with the request as metadata. Returns: - ~.operation.Operation: + google.api_core.operation.Operation: An object representing a long-running operation. The result type for the operation will be - :class:``~.image_annotator.AsyncBatchAnnotateFilesResponse``: + :class:`google.cloud.vision_v1p2beta1.types.AsyncBatchAnnotateFilesResponse` Response to an async batch file annotation request. """ @@ -457,8 +471,8 @@ def async_batch_annotate_files( # If we have keyword arguments corresponding to fields on the # request, apply these. - if requests: - request.requests.extend(requests) + if requests is not None: + request.requests = requests # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. diff --git a/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc.py b/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc.py index 4795a3d6..fb17444c 100644 --- a/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc.py +++ b/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc.py @@ -62,6 +62,7 @@ def __init__( api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -92,6 +93,10 @@ def __init__( ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -108,6 +113,11 @@ def __init__( """ self._ssl_channel_credentials = ssl_channel_credentials + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -117,11 +127,6 @@ def __init__( self._grpc_channel = channel self._ssl_channel_credentials = None elif api_mtls_endpoint: - warnings.warn( - "api_mtls_endpoint and client_cert_source are deprecated", - DeprecationWarning, - ) - host = ( api_mtls_endpoint if ":" in api_mtls_endpoint @@ -165,12 +170,18 @@ def __init__( scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id ) + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + # create a new channel. The provided one is ignored. self._grpc_channel = type(self).create_channel( host, credentials=credentials, credentials_file=credentials_file, - ssl_credentials=ssl_channel_credentials, + ssl_credentials=self._ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ diff --git a/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc_asyncio.py b/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc_asyncio.py index aba72790..8b0c705f 100644 --- a/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc_asyncio.py +++ b/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc_asyncio.py @@ -106,6 +106,7 @@ def __init__( api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -137,6 +138,10 @@ def __init__( ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -153,6 +158,11 @@ def __init__( """ self._ssl_channel_credentials = ssl_channel_credentials + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -162,11 +172,6 @@ def __init__( self._grpc_channel = channel self._ssl_channel_credentials = None elif api_mtls_endpoint: - warnings.warn( - "api_mtls_endpoint and client_cert_source are deprecated", - DeprecationWarning, - ) - host = ( api_mtls_endpoint if ":" in api_mtls_endpoint @@ -210,12 +215,18 @@ def __init__( scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id ) + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + # create a new channel. The provided one is ignored. self._grpc_channel = type(self).create_channel( host, credentials=credentials, credentials_file=credentials_file, - ssl_credentials=ssl_channel_credentials, + ssl_credentials=self._ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ diff --git a/google/cloud/vision_v1p2beta1/types/geometry.py b/google/cloud/vision_v1p2beta1/types/geometry.py index 482f5ec2..42fb6ec0 100644 --- a/google/cloud/vision_v1p2beta1/types/geometry.py +++ b/google/cloud/vision_v1p2beta1/types/geometry.py @@ -62,9 +62,9 @@ class BoundingPoly(proto.Message): r"""A bounding polygon for the detected image annotation. Attributes: - vertices (Sequence[~.geometry.Vertex]): + vertices (Sequence[google.cloud.vision_v1p2beta1.types.Vertex]): The bounding polygon vertices. - normalized_vertices (Sequence[~.geometry.NormalizedVertex]): + normalized_vertices (Sequence[google.cloud.vision_v1p2beta1.types.NormalizedVertex]): The bounding polygon normalized vertices. """ diff --git a/google/cloud/vision_v1p2beta1/types/image_annotator.py b/google/cloud/vision_v1p2beta1/types/image_annotator.py index 0f3bee9c..5480edb6 100644 --- a/google/cloud/vision_v1p2beta1/types/image_annotator.py +++ b/google/cloud/vision_v1p2beta1/types/image_annotator.py @@ -86,7 +86,7 @@ class Feature(proto.Message): ``Feature`` objects can be specified in the ``features`` list. Attributes: - type_ (~.image_annotator.Feature.Type): + type_ (google.cloud.vision_v1p2beta1.types.Feature.Type): The feature type. max_results (int): Maximum number of results of this type. Does not apply to @@ -167,7 +167,7 @@ class Image(proto.Message): Image content, represented as a stream of bytes. Note: As with all ``bytes`` fields, protobuffers use a pure binary representation, whereas JSON representations use base64. - source (~.image_annotator.ImageSource): + source (google.cloud.vision_v1p2beta1.types.ImageSource): Google Cloud Storage image location, or publicly-accessible image URL. If both ``content`` and ``source`` are provided for an image, ``content`` takes precedence and is used to @@ -184,7 +184,7 @@ class FaceAnnotation(proto.Message): detection. Attributes: - bounding_poly (~.geometry.BoundingPoly): + bounding_poly (google.cloud.vision_v1p2beta1.types.BoundingPoly): The bounding polygon around the face. The coordinates of the bounding box are in the original image's scale, as returned in ``ImageParams``. The bounding box is computed to "frame" @@ -193,7 +193,7 @@ class FaceAnnotation(proto.Message): coordinates may not be generated in the ``BoundingPoly`` (the polygon will be unbounded) if only a partial face appears in the image to be annotated. - fd_bounding_poly (~.geometry.BoundingPoly): + fd_bounding_poly (google.cloud.vision_v1p2beta1.types.BoundingPoly): The ``fd_bounding_poly`` bounding polygon is tighter than the ``boundingPoly``, and encloses only the skin part of the face. Typically, it is used to eliminate the face from any @@ -201,7 +201,7 @@ class FaceAnnotation(proto.Message): an image. It is not based on the landmarker results, only on the initial face detection, hence the fd (face detection) prefix. - landmarks (Sequence[~.image_annotator.FaceAnnotation.Landmark]): + landmarks (Sequence[google.cloud.vision_v1p2beta1.types.FaceAnnotation.Landmark]): Detected face landmarks. roll_angle (float): Roll angle, which indicates the amount of @@ -220,19 +220,19 @@ class FaceAnnotation(proto.Message): Detection confidence. Range [0, 1]. landmarking_confidence (float): Face landmarking confidence. Range [0, 1]. - joy_likelihood (~.image_annotator.Likelihood): + joy_likelihood (google.cloud.vision_v1p2beta1.types.Likelihood): Joy likelihood. - sorrow_likelihood (~.image_annotator.Likelihood): + sorrow_likelihood (google.cloud.vision_v1p2beta1.types.Likelihood): Sorrow likelihood. - anger_likelihood (~.image_annotator.Likelihood): + anger_likelihood (google.cloud.vision_v1p2beta1.types.Likelihood): Anger likelihood. - surprise_likelihood (~.image_annotator.Likelihood): + surprise_likelihood (google.cloud.vision_v1p2beta1.types.Likelihood): Surprise likelihood. - under_exposed_likelihood (~.image_annotator.Likelihood): + under_exposed_likelihood (google.cloud.vision_v1p2beta1.types.Likelihood): Under-exposed likelihood. - blurred_likelihood (~.image_annotator.Likelihood): + blurred_likelihood (google.cloud.vision_v1p2beta1.types.Likelihood): Blurred likelihood. - headwear_likelihood (~.image_annotator.Likelihood): + headwear_likelihood (google.cloud.vision_v1p2beta1.types.Likelihood): Headwear likelihood. """ @@ -240,9 +240,9 @@ class Landmark(proto.Message): r"""A face-specific landmark (for example, a face feature). Attributes: - type_ (~.image_annotator.FaceAnnotation.Landmark.Type): + type_ (google.cloud.vision_v1p2beta1.types.FaceAnnotation.Landmark.Type): Face landmark type. - position (~.geometry.Position): + position (google.cloud.vision_v1p2beta1.types.Position): Face landmark position. """ @@ -329,7 +329,7 @@ class LocationInfo(proto.Message): r"""Detected entity location information. Attributes: - lat_lng (~.latlng.LatLng): + lat_lng (google.type.latlng_pb2.LatLng): lat/long location coordinates. """ @@ -384,17 +384,17 @@ class EntityAnnotation(proto.Message): than to an image containing a detected distant towering building, even though the confidence that there is a tower in each image may be the same. Range [0, 1]. - bounding_poly (~.geometry.BoundingPoly): + bounding_poly (google.cloud.vision_v1p2beta1.types.BoundingPoly): Image region to which this entity belongs. Not produced for ``LABEL_DETECTION`` features. - locations (Sequence[~.image_annotator.LocationInfo]): + locations (Sequence[google.cloud.vision_v1p2beta1.types.LocationInfo]): The location information for the detected entity. Multiple ``LocationInfo`` elements can be present because one location may indicate the location of the scene in the image, and another location may indicate the location of the place where the image was taken. Location information is usually present for landmarks. - properties (Sequence[~.image_annotator.Property]): + properties (Sequence[google.cloud.vision_v1p2beta1.types.Property]): Some entities may have optional user-supplied ``Property`` (name/value) fields, such a score or string that qualifies the entity. @@ -425,21 +425,21 @@ class SafeSearchAnnotation(proto.Message): spoof, medical, violence). Attributes: - adult (~.image_annotator.Likelihood): + adult (google.cloud.vision_v1p2beta1.types.Likelihood): Represents the adult content likelihood for the image. Adult content may contain elements such as nudity, pornographic images or cartoons, or sexual activities. - spoof (~.image_annotator.Likelihood): + spoof (google.cloud.vision_v1p2beta1.types.Likelihood): Spoof likelihood. The likelihood that an modification was made to the image's canonical version to make it appear funny or offensive. - medical (~.image_annotator.Likelihood): + medical (google.cloud.vision_v1p2beta1.types.Likelihood): Likelihood that this is a medical image. - violence (~.image_annotator.Likelihood): + violence (google.cloud.vision_v1p2beta1.types.Likelihood): Likelihood that this image contains violent content. - racy (~.image_annotator.Likelihood): + racy (google.cloud.vision_v1p2beta1.types.Likelihood): Likelihood that the request image contains racy content. Racy content may include (but is not limited to) skimpy or sheer clothing, @@ -463,9 +463,9 @@ class LatLongRect(proto.Message): r"""Rectangle determined by min and max ``LatLng`` pairs. Attributes: - min_lat_lng (~.latlng.LatLng): + min_lat_lng (google.type.latlng_pb2.LatLng): Min lat/long pair. - max_lat_lng (~.latlng.LatLng): + max_lat_lng (google.type.latlng_pb2.LatLng): Max lat/long pair. """ @@ -479,7 +479,7 @@ class ColorInfo(proto.Message): fraction of the image that the color occupies in the image. Attributes: - color (~.gt_color.Color): + color (google.type.color_pb2.Color): RGB components of the color. score (float): Image-specific score for this color. Value in range [0, 1]. @@ -499,7 +499,7 @@ class DominantColorsAnnotation(proto.Message): r"""Set of dominant colors and their corresponding scores. Attributes: - colors (Sequence[~.image_annotator.ColorInfo]): + colors (Sequence[google.cloud.vision_v1p2beta1.types.ColorInfo]): RGB color values with their score and pixel fraction. """ @@ -511,7 +511,7 @@ class ImageProperties(proto.Message): r"""Stores image properties, such as dominant colors. Attributes: - dominant_colors (~.image_annotator.DominantColorsAnnotation): + dominant_colors (google.cloud.vision_v1p2beta1.types.DominantColorsAnnotation): If present, dominant colors completed successfully. """ @@ -526,7 +526,7 @@ class CropHint(proto.Message): serving an image. Attributes: - bounding_poly (~.geometry.BoundingPoly): + bounding_poly (google.cloud.vision_v1p2beta1.types.BoundingPoly): The bounding polygon for the crop region. The coordinates of the bounding box are in the original image's scale, as returned in ``ImageParams``. @@ -549,7 +549,7 @@ class CropHintsAnnotation(proto.Message): serving images. Attributes: - crop_hints (Sequence[~.image_annotator.CropHint]): + crop_hints (Sequence[google.cloud.vision_v1p2beta1.types.CropHint]): Crop hint results. """ @@ -604,7 +604,7 @@ class ImageContext(proto.Message): r"""Image context and/or feature-specific parameters. Attributes: - lat_long_rect (~.image_annotator.LatLongRect): + lat_long_rect (google.cloud.vision_v1p2beta1.types.LatLongRect): Not used. language_hints (Sequence[str]): List of languages to use for TEXT_DETECTION. In most cases, @@ -617,11 +617,11 @@ class ImageContext(proto.Message): Text detection returns an error if one or more of the specified languages is not one of the `supported languages `__. - crop_hints_params (~.image_annotator.CropHintsParams): + crop_hints_params (google.cloud.vision_v1p2beta1.types.CropHintsParams): Parameters for crop hints annotation request. - web_detection_params (~.image_annotator.WebDetectionParams): + web_detection_params (google.cloud.vision_v1p2beta1.types.WebDetectionParams): Parameters for web detection. - text_detection_params (~.image_annotator.TextDetectionParams): + text_detection_params (google.cloud.vision_v1p2beta1.types.TextDetectionParams): Parameters for text detection and document text detection. """ @@ -646,11 +646,11 @@ class AnnotateImageRequest(proto.Message): user-provided image, with user-requested features. Attributes: - image (~.image_annotator.Image): + image (google.cloud.vision_v1p2beta1.types.Image): The image to be processed. - features (Sequence[~.image_annotator.Feature]): + features (Sequence[google.cloud.vision_v1p2beta1.types.Feature]): Requested features. - image_context (~.image_annotator.ImageContext): + image_context (google.cloud.vision_v1p2beta1.types.ImageContext): Additional context that may accompany the image. """ @@ -685,43 +685,43 @@ class AnnotateImageResponse(proto.Message): r"""Response to an image annotation request. Attributes: - face_annotations (Sequence[~.image_annotator.FaceAnnotation]): + face_annotations (Sequence[google.cloud.vision_v1p2beta1.types.FaceAnnotation]): If present, face detection has completed successfully. - landmark_annotations (Sequence[~.image_annotator.EntityAnnotation]): + landmark_annotations (Sequence[google.cloud.vision_v1p2beta1.types.EntityAnnotation]): If present, landmark detection has completed successfully. - logo_annotations (Sequence[~.image_annotator.EntityAnnotation]): + logo_annotations (Sequence[google.cloud.vision_v1p2beta1.types.EntityAnnotation]): If present, logo detection has completed successfully. - label_annotations (Sequence[~.image_annotator.EntityAnnotation]): + label_annotations (Sequence[google.cloud.vision_v1p2beta1.types.EntityAnnotation]): If present, label detection has completed successfully. - text_annotations (Sequence[~.image_annotator.EntityAnnotation]): + text_annotations (Sequence[google.cloud.vision_v1p2beta1.types.EntityAnnotation]): If present, text (OCR) detection has completed successfully. - full_text_annotation (~.text_annotation.TextAnnotation): + full_text_annotation (google.cloud.vision_v1p2beta1.types.TextAnnotation): If present, text (OCR) detection or document (OCR) text detection has completed successfully. This annotation provides the structural hierarchy for the OCR detected text. - safe_search_annotation (~.image_annotator.SafeSearchAnnotation): + safe_search_annotation (google.cloud.vision_v1p2beta1.types.SafeSearchAnnotation): If present, safe-search annotation has completed successfully. - image_properties_annotation (~.image_annotator.ImageProperties): + image_properties_annotation (google.cloud.vision_v1p2beta1.types.ImageProperties): If present, image properties were extracted successfully. - crop_hints_annotation (~.image_annotator.CropHintsAnnotation): + crop_hints_annotation (google.cloud.vision_v1p2beta1.types.CropHintsAnnotation): If present, crop hints have completed successfully. - web_detection (~.gcv_web_detection.WebDetection): + web_detection (google.cloud.vision_v1p2beta1.types.WebDetection): If present, web detection has completed successfully. - error (~.status.Status): + error (google.rpc.status_pb2.Status): If set, represents the error message for the operation. Note that filled-in image annotations are guaranteed to be correct, even when ``error`` is set. - context (~.image_annotator.ImageAnnotationContext): + context (google.cloud.vision_v1p2beta1.types.ImageAnnotationContext): If present, contextual information is needed to understand where this image comes from. """ @@ -777,10 +777,10 @@ class AnnotateFileResponse(proto.Message): responses. Attributes: - input_config (~.image_annotator.InputConfig): + input_config (google.cloud.vision_v1p2beta1.types.InputConfig): Information about the file for which this response is generated. - responses (Sequence[~.image_annotator.AnnotateImageResponse]): + responses (Sequence[google.cloud.vision_v1p2beta1.types.AnnotateImageResponse]): Individual responses to images found within the file. """ @@ -797,7 +797,7 @@ class BatchAnnotateImagesRequest(proto.Message): service call. Attributes: - requests (Sequence[~.image_annotator.AnnotateImageRequest]): + requests (Sequence[google.cloud.vision_v1p2beta1.types.AnnotateImageRequest]): Required. Individual image annotation requests for this batch. """ @@ -811,7 +811,7 @@ class BatchAnnotateImagesResponse(proto.Message): r"""Response to a batch image annotation request. Attributes: - responses (Sequence[~.image_annotator.AnnotateImageResponse]): + responses (Sequence[google.cloud.vision_v1p2beta1.types.AnnotateImageResponse]): Individual responses to image annotation requests within the batch. """ @@ -825,14 +825,14 @@ class AsyncAnnotateFileRequest(proto.Message): r"""An offline file annotation request. Attributes: - input_config (~.image_annotator.InputConfig): + input_config (google.cloud.vision_v1p2beta1.types.InputConfig): Required. Information about the input file. - features (Sequence[~.image_annotator.Feature]): + features (Sequence[google.cloud.vision_v1p2beta1.types.Feature]): Required. Requested features. - image_context (~.image_annotator.ImageContext): + image_context (google.cloud.vision_v1p2beta1.types.ImageContext): Additional context that may accompany the image(s) in the file. - output_config (~.image_annotator.OutputConfig): + output_config (google.cloud.vision_v1p2beta1.types.OutputConfig): Required. The desired output location and metadata (e.g. format). """ @@ -850,7 +850,7 @@ class AsyncAnnotateFileResponse(proto.Message): r"""The response for a single offline file annotation request. Attributes: - output_config (~.image_annotator.OutputConfig): + output_config (google.cloud.vision_v1p2beta1.types.OutputConfig): The output location and metadata from AsyncAnnotateFileRequest. """ @@ -863,7 +863,7 @@ class AsyncBatchAnnotateFilesRequest(proto.Message): single service call. Attributes: - requests (Sequence[~.image_annotator.AsyncAnnotateFileRequest]): + requests (Sequence[google.cloud.vision_v1p2beta1.types.AsyncAnnotateFileRequest]): Required. Individual async file annotation requests for this batch. """ @@ -877,7 +877,7 @@ class AsyncBatchAnnotateFilesResponse(proto.Message): r"""Response to an async batch file annotation request. Attributes: - responses (Sequence[~.image_annotator.AsyncAnnotateFileResponse]): + responses (Sequence[google.cloud.vision_v1p2beta1.types.AsyncAnnotateFileResponse]): The list of file annotation responses, one for each request in AsyncBatchAnnotateFilesRequest. @@ -892,7 +892,7 @@ class InputConfig(proto.Message): r"""The desired input location and metadata. Attributes: - gcs_source (~.image_annotator.GcsSource): + gcs_source (google.cloud.vision_v1p2beta1.types.GcsSource): The Google Cloud Storage location to read the input from. mime_type (str): @@ -910,7 +910,7 @@ class OutputConfig(proto.Message): r"""The desired output location and metadata. Attributes: - gcs_destination (~.image_annotator.GcsDestination): + gcs_destination (google.cloud.vision_v1p2beta1.types.GcsDestination): The Google Cloud Storage location to write the output(s) to. batch_size (int): @@ -978,11 +978,11 @@ class OperationMetadata(proto.Message): r"""Contains metadata for the BatchAnnotateImages operation. Attributes: - state (~.image_annotator.OperationMetadata.State): + state (google.cloud.vision_v1p2beta1.types.OperationMetadata.State): Current state of the batch operation. - create_time (~.timestamp.Timestamp): + create_time (google.protobuf.timestamp_pb2.Timestamp): The time when the batch request was received. - update_time (~.timestamp.Timestamp): + update_time (google.protobuf.timestamp_pb2.Timestamp): The time when the operation result was last updated. """ diff --git a/google/cloud/vision_v1p2beta1/types/text_annotation.py b/google/cloud/vision_v1p2beta1/types/text_annotation.py index c7c6de3d..e2366e17 100644 --- a/google/cloud/vision_v1p2beta1/types/text_annotation.py +++ b/google/cloud/vision_v1p2beta1/types/text_annotation.py @@ -38,7 +38,7 @@ class TextAnnotation(proto.Message): message definition below for more detail. Attributes: - pages (Sequence[~.text_annotation.Page]): + pages (Sequence[google.cloud.vision_v1p2beta1.types.Page]): List of pages detected by OCR. text (str): UTF-8 text detected on the pages. @@ -64,7 +64,7 @@ class DetectedBreak(proto.Message): r"""Detected start or end of a structural component. Attributes: - type_ (~.text_annotation.TextAnnotation.DetectedBreak.BreakType): + type_ (google.cloud.vision_v1p2beta1.types.TextAnnotation.DetectedBreak.BreakType): Detected break type. is_prefix (bool): True if break prepends the element. @@ -89,10 +89,10 @@ class TextProperty(proto.Message): r"""Additional information detected on the structural component. Attributes: - detected_languages (Sequence[~.text_annotation.TextAnnotation.DetectedLanguage]): + detected_languages (Sequence[google.cloud.vision_v1p2beta1.types.TextAnnotation.DetectedLanguage]): A list of detected languages together with confidence. - detected_break (~.text_annotation.TextAnnotation.DetectedBreak): + detected_break (google.cloud.vision_v1p2beta1.types.TextAnnotation.DetectedBreak): Detected start or end of a text segment. """ @@ -113,7 +113,7 @@ class Page(proto.Message): r"""Detected page from OCR. Attributes: - property (~.text_annotation.TextAnnotation.TextProperty): + property (google.cloud.vision_v1p2beta1.types.TextAnnotation.TextProperty): Additional information detected on the page. width (int): Page width. For PDFs the unit is points. For @@ -121,7 +121,7 @@ class Page(proto.Message): height (int): Page height. For PDFs the unit is points. For images (including TIFFs) the unit is pixels. - blocks (Sequence[~.text_annotation.Block]): + blocks (Sequence[google.cloud.vision_v1p2beta1.types.Block]): List of blocks of text, images etc on this page. confidence (float): @@ -145,10 +145,10 @@ class Block(proto.Message): r"""Logical element on the page. Attributes: - property (~.text_annotation.TextAnnotation.TextProperty): + property (google.cloud.vision_v1p2beta1.types.TextAnnotation.TextProperty): Additional information detected for the block. - bounding_box (~.geometry.BoundingPoly): + bounding_box (google.cloud.vision_v1p2beta1.types.BoundingPoly): The bounding box for the block. The vertices are in the order of top-left, top-right, bottom-right, bottom-left. When a rotation of the bounding box is detected the rotation @@ -173,10 +173,10 @@ class Block(proto.Message): 1----0 and the vertice order will still be (0, 1, 2, 3). - paragraphs (Sequence[~.text_annotation.Paragraph]): + paragraphs (Sequence[google.cloud.vision_v1p2beta1.types.Paragraph]): List of paragraphs in this block (if this blocks is of type text). - block_type (~.text_annotation.Block.BlockType): + block_type (google.cloud.vision_v1p2beta1.types.Block.BlockType): Detected block type (text, image etc) for this block. confidence (float): @@ -210,10 +210,10 @@ class Paragraph(proto.Message): certain order. Attributes: - property (~.text_annotation.TextAnnotation.TextProperty): + property (google.cloud.vision_v1p2beta1.types.TextAnnotation.TextProperty): Additional information detected for the paragraph. - bounding_box (~.geometry.BoundingPoly): + bounding_box (google.cloud.vision_v1p2beta1.types.BoundingPoly): The bounding box for the paragraph. The vertices are in the order of top-left, top-right, bottom-right, bottom-left. When a rotation of the bounding box is detected the rotation @@ -225,7 +225,7 @@ class Paragraph(proto.Message): - when it's rotated 180 degrees around the top-left corner it becomes: 2----3 \| \| 1----0 and the vertice order will still be (0, 1, 2, 3). - words (Sequence[~.text_annotation.Word]): + words (Sequence[google.cloud.vision_v1p2beta1.types.Word]): List of words in this paragraph. confidence (float): Confidence of the OCR results for the paragraph. Range [0, @@ -247,9 +247,9 @@ class Word(proto.Message): r"""A word representation. Attributes: - property (~.text_annotation.TextAnnotation.TextProperty): + property (google.cloud.vision_v1p2beta1.types.TextAnnotation.TextProperty): Additional information detected for the word. - bounding_box (~.geometry.BoundingPoly): + bounding_box (google.cloud.vision_v1p2beta1.types.BoundingPoly): The bounding box for the word. The vertices are in the order of top-left, top-right, bottom-right, bottom-left. When a rotation of the bounding box is detected the rotation is @@ -261,7 +261,7 @@ class Word(proto.Message): - when it's rotated 180 degrees around the top-left corner it becomes: 2----3 \| \| 1----0 and the vertice order will still be (0, 1, 2, 3). - symbols (Sequence[~.text_annotation.Symbol]): + symbols (Sequence[google.cloud.vision_v1p2beta1.types.Symbol]): List of symbols in the word. The order of the symbols follows the natural reading order. @@ -284,10 +284,10 @@ class Symbol(proto.Message): r"""A single symbol representation. Attributes: - property (~.text_annotation.TextAnnotation.TextProperty): + property (google.cloud.vision_v1p2beta1.types.TextAnnotation.TextProperty): Additional information detected for the symbol. - bounding_box (~.geometry.BoundingPoly): + bounding_box (google.cloud.vision_v1p2beta1.types.BoundingPoly): The bounding box for the symbol. The vertices are in the order of top-left, top-right, bottom-right, bottom-left. When a rotation of the bounding box is detected the rotation diff --git a/google/cloud/vision_v1p2beta1/types/web_detection.py b/google/cloud/vision_v1p2beta1/types/web_detection.py index 1a4f954d..d3a7ffee 100644 --- a/google/cloud/vision_v1p2beta1/types/web_detection.py +++ b/google/cloud/vision_v1p2beta1/types/web_detection.py @@ -27,24 +27,24 @@ class WebDetection(proto.Message): r"""Relevant information for the image from the Internet. Attributes: - web_entities (Sequence[~.web_detection.WebDetection.WebEntity]): + web_entities (Sequence[google.cloud.vision_v1p2beta1.types.WebDetection.WebEntity]): Deduced entities from similar images on the Internet. - full_matching_images (Sequence[~.web_detection.WebDetection.WebImage]): + full_matching_images (Sequence[google.cloud.vision_v1p2beta1.types.WebDetection.WebImage]): Fully matching images from the Internet. Can include resized copies of the query image. - partial_matching_images (Sequence[~.web_detection.WebDetection.WebImage]): + partial_matching_images (Sequence[google.cloud.vision_v1p2beta1.types.WebDetection.WebImage]): Partial matching images from the Internet. Those images are similar enough to share some key-point features. For example an original image will likely have partial matching for its crops. - pages_with_matching_images (Sequence[~.web_detection.WebDetection.WebPage]): + pages_with_matching_images (Sequence[google.cloud.vision_v1p2beta1.types.WebDetection.WebPage]): Web pages containing the matching images from the Internet. - visually_similar_images (Sequence[~.web_detection.WebDetection.WebImage]): + visually_similar_images (Sequence[google.cloud.vision_v1p2beta1.types.WebDetection.WebImage]): The visually similar image results. - best_guess_labels (Sequence[~.web_detection.WebDetection.WebLabel]): + best_guess_labels (Sequence[google.cloud.vision_v1p2beta1.types.WebDetection.WebLabel]): Best guess text labels for the request image. """ @@ -96,10 +96,10 @@ class WebPage(proto.Message): page_title (str): Title for the web page, may contain HTML markups. - full_matching_images (Sequence[~.web_detection.WebDetection.WebImage]): + full_matching_images (Sequence[google.cloud.vision_v1p2beta1.types.WebDetection.WebImage]): Fully matching images on the page. Can include resized copies of the query image. - partial_matching_images (Sequence[~.web_detection.WebDetection.WebImage]): + partial_matching_images (Sequence[google.cloud.vision_v1p2beta1.types.WebDetection.WebImage]): Partial matching images on the page. Those images are similar enough to share some key-point features. For example an original diff --git a/google/cloud/vision_v1p3beta1/services/image_annotator/async_client.py b/google/cloud/vision_v1p3beta1/services/image_annotator/async_client.py index c9e14583..1ca98853 100644 --- a/google/cloud/vision_v1p3beta1/services/image_annotator/async_client.py +++ b/google/cloud/vision_v1p3beta1/services/image_annotator/async_client.py @@ -83,6 +83,7 @@ class ImageAnnotatorAsyncClient: ImageAnnotatorClient.parse_common_location_path ) + from_service_account_info = ImageAnnotatorClient.from_service_account_info from_service_account_file = ImageAnnotatorClient.from_service_account_file from_service_account_json = from_service_account_file @@ -160,12 +161,13 @@ async def batch_annotate_images( images. Args: - request (:class:`~.image_annotator.BatchAnnotateImagesRequest`): + request (:class:`google.cloud.vision_v1p3beta1.types.BatchAnnotateImagesRequest`): The request object. Multiple image annotation requests are batched into a single service call. - requests (:class:`Sequence[~.image_annotator.AnnotateImageRequest]`): + requests (:class:`Sequence[google.cloud.vision_v1p3beta1.types.AnnotateImageRequest]`): Individual image annotation requests for this batch. + This corresponds to the ``requests`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -177,7 +179,7 @@ async def batch_annotate_images( sent along with the request as metadata. Returns: - ~.image_annotator.BatchAnnotateImagesResponse: + google.cloud.vision_v1p3beta1.types.BatchAnnotateImagesResponse: Response to a batch image annotation request. @@ -240,12 +242,13 @@ async def async_batch_annotate_files( ``AsyncBatchAnnotateFilesResponse`` (results). Args: - request (:class:`~.image_annotator.AsyncBatchAnnotateFilesRequest`): + request (:class:`google.cloud.vision_v1p3beta1.types.AsyncBatchAnnotateFilesRequest`): The request object. Multiple async file annotation requests are batched into a single service call. - requests (:class:`Sequence[~.image_annotator.AsyncAnnotateFileRequest]`): + requests (:class:`Sequence[google.cloud.vision_v1p3beta1.types.AsyncAnnotateFileRequest]`): Required. Individual async file annotation requests for this batch. + This corresponds to the ``requests`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -257,11 +260,11 @@ async def async_batch_annotate_files( sent along with the request as metadata. Returns: - ~.operation_async.AsyncOperation: + google.api_core.operation_async.AsyncOperation: An object representing a long-running operation. The result type for the operation will be - :class:``~.image_annotator.AsyncBatchAnnotateFilesResponse``: + :class:`google.cloud.vision_v1p3beta1.types.AsyncBatchAnnotateFilesResponse` Response to an async batch file annotation request. """ diff --git a/google/cloud/vision_v1p3beta1/services/image_annotator/client.py b/google/cloud/vision_v1p3beta1/services/image_annotator/client.py index 6792a030..eb5a0cf9 100644 --- a/google/cloud/vision_v1p3beta1/services/image_annotator/client.py +++ b/google/cloud/vision_v1p3beta1/services/image_annotator/client.py @@ -115,6 +115,22 @@ def _get_default_mtls_endpoint(api_endpoint): DEFAULT_ENDPOINT ) + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + ImageAnnotatorClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_info(info) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials @@ -127,7 +143,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): kwargs: Additional arguments to pass to the constructor. Returns: - {@api.name}: The constructed client. + ImageAnnotatorClient: The constructed client. """ credentials = service_account.Credentials.from_service_account_file(filename) kwargs["credentials"] = credentials @@ -251,10 +267,10 @@ def __init__( credentials identify the application to the service; if none are specified, the client will attempt to ascertain the credentials from the environment. - transport (Union[str, ~.ImageAnnotatorTransport]): The + transport (Union[str, ImageAnnotatorTransport]): The transport to use. If set to None, a transport is chosen automatically. - client_options (client_options_lib.ClientOptions): Custom options for the + client_options (google.api_core.client_options.ClientOptions): Custom options for the client. It won't take effect if a ``transport`` instance is provided. (1) The ``api_endpoint`` property can be used to override the default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT @@ -290,21 +306,17 @@ def __init__( util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")) ) - ssl_credentials = None + client_cert_source_func = None is_mtls = False if use_client_cert: if client_options.client_cert_source: - import grpc # type: ignore - - cert, key = client_options.client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) is_mtls = True + client_cert_source_func = client_options.client_cert_source else: - creds = SslCredentials() - is_mtls = creds.is_mtls - ssl_credentials = creds.ssl_credentials if is_mtls else None + is_mtls = mtls.has_default_client_cert_source() + client_cert_source_func = ( + mtls.default_client_cert_source() if is_mtls else None + ) # Figure out which api endpoint to use. if client_options.api_endpoint is not None: @@ -347,7 +359,7 @@ def __init__( credentials_file=client_options.credentials_file, host=api_endpoint, scopes=client_options.scopes, - ssl_channel_credentials=ssl_credentials, + client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, ) @@ -365,12 +377,13 @@ def batch_annotate_images( images. Args: - request (:class:`~.image_annotator.BatchAnnotateImagesRequest`): + request (google.cloud.vision_v1p3beta1.types.BatchAnnotateImagesRequest): The request object. Multiple image annotation requests are batched into a single service call. - requests (:class:`Sequence[~.image_annotator.AnnotateImageRequest]`): + requests (Sequence[google.cloud.vision_v1p3beta1.types.AnnotateImageRequest]): Individual image annotation requests for this batch. + This corresponds to the ``requests`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -382,7 +395,7 @@ def batch_annotate_images( sent along with the request as metadata. Returns: - ~.image_annotator.BatchAnnotateImagesResponse: + google.cloud.vision_v1p3beta1.types.BatchAnnotateImagesResponse: Response to a batch image annotation request. @@ -410,8 +423,8 @@ def batch_annotate_images( # If we have keyword arguments corresponding to fields on the # request, apply these. - if requests: - request.requests.extend(requests) + if requests is not None: + request.requests = requests # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -441,12 +454,13 @@ def async_batch_annotate_files( ``AsyncBatchAnnotateFilesResponse`` (results). Args: - request (:class:`~.image_annotator.AsyncBatchAnnotateFilesRequest`): + request (google.cloud.vision_v1p3beta1.types.AsyncBatchAnnotateFilesRequest): The request object. Multiple async file annotation requests are batched into a single service call. - requests (:class:`Sequence[~.image_annotator.AsyncAnnotateFileRequest]`): + requests (Sequence[google.cloud.vision_v1p3beta1.types.AsyncAnnotateFileRequest]): Required. Individual async file annotation requests for this batch. + This corresponds to the ``requests`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -458,11 +472,11 @@ def async_batch_annotate_files( sent along with the request as metadata. Returns: - ~.operation.Operation: + google.api_core.operation.Operation: An object representing a long-running operation. The result type for the operation will be - :class:``~.image_annotator.AsyncBatchAnnotateFilesResponse``: + :class:`google.cloud.vision_v1p3beta1.types.AsyncBatchAnnotateFilesResponse` Response to an async batch file annotation request. """ @@ -489,8 +503,8 @@ def async_batch_annotate_files( # If we have keyword arguments corresponding to fields on the # request, apply these. - if requests: - request.requests.extend(requests) + if requests is not None: + request.requests = requests # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. diff --git a/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc.py b/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc.py index 7edc9581..4c12c285 100644 --- a/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc.py +++ b/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc.py @@ -62,6 +62,7 @@ def __init__( api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -92,6 +93,10 @@ def __init__( ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -108,6 +113,11 @@ def __init__( """ self._ssl_channel_credentials = ssl_channel_credentials + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -117,11 +127,6 @@ def __init__( self._grpc_channel = channel self._ssl_channel_credentials = None elif api_mtls_endpoint: - warnings.warn( - "api_mtls_endpoint and client_cert_source are deprecated", - DeprecationWarning, - ) - host = ( api_mtls_endpoint if ":" in api_mtls_endpoint @@ -165,12 +170,18 @@ def __init__( scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id ) + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + # create a new channel. The provided one is ignored. self._grpc_channel = type(self).create_channel( host, credentials=credentials, credentials_file=credentials_file, - ssl_credentials=ssl_channel_credentials, + ssl_credentials=self._ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ diff --git a/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc_asyncio.py b/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc_asyncio.py index c496e829..d502a506 100644 --- a/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc_asyncio.py +++ b/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc_asyncio.py @@ -106,6 +106,7 @@ def __init__( api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -137,6 +138,10 @@ def __init__( ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -153,6 +158,11 @@ def __init__( """ self._ssl_channel_credentials = ssl_channel_credentials + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -162,11 +172,6 @@ def __init__( self._grpc_channel = channel self._ssl_channel_credentials = None elif api_mtls_endpoint: - warnings.warn( - "api_mtls_endpoint and client_cert_source are deprecated", - DeprecationWarning, - ) - host = ( api_mtls_endpoint if ":" in api_mtls_endpoint @@ -210,12 +215,18 @@ def __init__( scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id ) + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + # create a new channel. The provided one is ignored. self._grpc_channel = type(self).create_channel( host, credentials=credentials, credentials_file=credentials_file, - ssl_credentials=ssl_channel_credentials, + ssl_credentials=self._ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ diff --git a/google/cloud/vision_v1p3beta1/services/product_search/async_client.py b/google/cloud/vision_v1p3beta1/services/product_search/async_client.py index 60c3a3cd..6a7c3022 100644 --- a/google/cloud/vision_v1p3beta1/services/product_search/async_client.py +++ b/google/cloud/vision_v1p3beta1/services/product_search/async_client.py @@ -108,6 +108,7 @@ class ProductSearchAsyncClient: ProductSearchClient.parse_common_location_path ) + from_service_account_info = ProductSearchClient.from_service_account_info from_service_account_file = ProductSearchClient.from_service_account_file from_service_account_json = from_service_account_file @@ -191,7 +192,7 @@ async def create_product_set( longer than 4096 characters. Args: - request (:class:`~.product_search_service.CreateProductSetRequest`): + request (:class:`google.cloud.vision_v1p3beta1.types.CreateProductSetRequest`): The request object. Request message for the `CreateProductSet` method. parent (:class:`str`): @@ -199,10 +200,11 @@ async def create_product_set( created. Format is ``projects/PROJECT_ID/locations/LOC_ID``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - product_set (:class:`~.product_search_service.ProductSet`): + product_set (:class:`google.cloud.vision_v1p3beta1.types.ProductSet`): Required. The ProductSet to create. This corresponds to the ``product_set`` field on the ``request`` instance; if ``request`` is provided, this @@ -213,6 +215,7 @@ async def create_product_set( resource id. If it is already in use, an error is returned with code ALREADY_EXISTS. Must be at most 128 characters long. It cannot contain the character ``/``. + This corresponds to the ``product_set_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -224,7 +227,7 @@ async def create_product_set( sent along with the request as metadata. Returns: - ~.product_search_service.ProductSet: + google.cloud.vision_v1p3beta1.types.ProductSet: A ProductSet contains Products. A ProductSet can contain a maximum of 1 million reference images. If the limit @@ -297,7 +300,7 @@ async def list_product_sets( less than 1. Args: - request (:class:`~.product_search_service.ListProductSetsRequest`): + request (:class:`google.cloud.vision_v1p3beta1.types.ListProductSetsRequest`): The request object. Request message for the `ListProductSets` method. parent (:class:`str`): @@ -305,6 +308,7 @@ async def list_product_sets( listed. Format is ``projects/PROJECT_ID/locations/LOC_ID``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -316,8 +320,8 @@ async def list_product_sets( sent along with the request as metadata. Returns: - ~.pagers.ListProductSetsAsyncPager: - Response message for the ``ListProductSets`` method. + google.cloud.vision_v1p3beta1.services.product_search.pagers.ListProductSetsAsyncPager: + Response message for the ListProductSets method. Iterating over this object will yield results and resolve additional pages automatically. @@ -391,7 +395,7 @@ async def get_product_set( - Returns NOT_FOUND if the ProductSet does not exist. Args: - request (:class:`~.product_search_service.GetProductSetRequest`): + request (:class:`google.cloud.vision_v1p3beta1.types.GetProductSetRequest`): The request object. Request message for the `GetProductSet` method. name (:class:`str`): @@ -399,6 +403,7 @@ async def get_product_set( Format is: ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -410,7 +415,7 @@ async def get_product_set( sent along with the request as metadata. Returns: - ~.product_search_service.ProductSet: + google.cloud.vision_v1p3beta1.types.ProductSet: A ProductSet contains Products. A ProductSet can contain a maximum of 1 million reference images. If the limit @@ -485,20 +490,22 @@ async def update_product_set( characters. Args: - request (:class:`~.product_search_service.UpdateProductSetRequest`): + request (:class:`google.cloud.vision_v1p3beta1.types.UpdateProductSetRequest`): The request object. Request message for the `UpdateProductSet` method. - product_set (:class:`~.product_search_service.ProductSet`): + product_set (:class:`google.cloud.vision_v1p3beta1.types.ProductSet`): Required. The ProductSet resource which replaces the one on the server. + This corresponds to the ``product_set`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - update_mask (:class:`~.field_mask.FieldMask`): + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): The [FieldMask][google.protobuf.FieldMask] that specifies which fields to update. If update_mask isn't specified, all mutable fields are to be updated. Valid mask path is ``display_name``. + This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -510,7 +517,7 @@ async def update_product_set( sent along with the request as metadata. Returns: - ~.product_search_service.ProductSet: + google.cloud.vision_v1p3beta1.types.ProductSet: A ProductSet contains Products. A ProductSet can contain a maximum of 1 million reference images. If the limit @@ -586,7 +593,7 @@ async def delete_product_set( - Returns NOT_FOUND if the ProductSet does not exist. Args: - request (:class:`~.product_search_service.DeleteProductSetRequest`): + request (:class:`google.cloud.vision_v1p3beta1.types.DeleteProductSetRequest`): The request object. Request message for the `DeleteProductSet` method. name (:class:`str`): @@ -594,6 +601,7 @@ async def delete_product_set( Format is: ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -672,7 +680,7 @@ async def create_product( invalid. Args: - request (:class:`~.product_search_service.CreateProductRequest`): + request (:class:`google.cloud.vision_v1p3beta1.types.CreateProductRequest`): The request object. Request message for the `CreateProduct` method. parent (:class:`str`): @@ -680,10 +688,11 @@ async def create_product( created. Format is ``projects/PROJECT_ID/locations/LOC_ID``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - product (:class:`~.product_search_service.Product`): + product (:class:`google.cloud.vision_v1p3beta1.types.Product`): Required. The product to create. This corresponds to the ``product`` field on the ``request`` instance; if ``request`` is provided, this @@ -694,6 +703,7 @@ async def create_product( resource id. If it is already in use, an error is returned with code ALREADY_EXISTS. Must be at most 128 characters long. It cannot contain the character ``/``. + This corresponds to the ``product_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -705,7 +715,7 @@ async def create_product( sent along with the request as metadata. Returns: - ~.product_search_service.Product: + google.cloud.vision_v1p3beta1.types.Product: A Product contains ReferenceImages. """ # Create or coerce a protobuf request object. @@ -773,7 +783,7 @@ async def list_products( less than 1. Args: - request (:class:`~.product_search_service.ListProductsRequest`): + request (:class:`google.cloud.vision_v1p3beta1.types.ListProductsRequest`): The request object. Request message for the `ListProducts` method. parent (:class:`str`): @@ -781,6 +791,7 @@ async def list_products( should be listed. Format: ``projects/PROJECT_ID/locations/LOC_ID`` + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -792,8 +803,8 @@ async def list_products( sent along with the request as metadata. Returns: - ~.pagers.ListProductsAsyncPager: - Response message for the ``ListProducts`` method. + google.cloud.vision_v1p3beta1.services.product_search.pagers.ListProductsAsyncPager: + Response message for the ListProducts method. Iterating over this object will yield results and resolve additional pages automatically. @@ -867,7 +878,7 @@ async def get_product( - Returns NOT_FOUND if the Product does not exist. Args: - request (:class:`~.product_search_service.GetProductRequest`): + request (:class:`google.cloud.vision_v1p3beta1.types.GetProductRequest`): The request object. Request message for the `GetProduct` method. name (:class:`str`): @@ -875,6 +886,7 @@ async def get_product( Format is: ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -886,7 +898,7 @@ async def get_product( sent along with the request as metadata. Returns: - ~.product_search_service.Product: + google.cloud.vision_v1p3beta1.types.Product: A Product contains ReferenceImages. """ # Create or coerce a protobuf request object. @@ -963,22 +975,24 @@ async def update_product( update_mask. Args: - request (:class:`~.product_search_service.UpdateProductRequest`): + request (:class:`google.cloud.vision_v1p3beta1.types.UpdateProductRequest`): The request object. Request message for the `UpdateProduct` method. - product (:class:`~.product_search_service.Product`): + product (:class:`google.cloud.vision_v1p3beta1.types.Product`): Required. The Product resource which replaces the one on the server. product.name is immutable. + This corresponds to the ``product`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - update_mask (:class:`~.field_mask.FieldMask`): + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): The [FieldMask][google.protobuf.FieldMask] that specifies which fields to update. If update_mask isn't specified, all mutable fields are to be updated. Valid mask paths include ``product_labels``, ``display_name``, and ``description``. + This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -990,7 +1004,7 @@ async def update_product( sent along with the request as metadata. Returns: - ~.product_search_service.Product: + google.cloud.vision_v1p3beta1.types.Product: A Product contains ReferenceImages. """ # Create or coerce a protobuf request object. @@ -1061,7 +1075,7 @@ async def delete_product( - Returns NOT_FOUND if the product does not exist. Args: - request (:class:`~.product_search_service.DeleteProductRequest`): + request (:class:`google.cloud.vision_v1p3beta1.types.DeleteProductRequest`): The request object. Request message for the `DeleteProduct` method. name (:class:`str`): @@ -1069,6 +1083,7 @@ async def delete_product( Format is: ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1159,7 +1174,7 @@ async def create_reference_image( 10 polygons. Args: - request (:class:`~.product_search_service.CreateReferenceImageRequest`): + request (:class:`google.cloud.vision_v1p3beta1.types.CreateReferenceImageRequest`): The request object. Request message for the `CreateReferenceImage` method. parent (:class:`str`): @@ -1168,13 +1183,15 @@ async def create_reference_image( Format is ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - reference_image (:class:`~.product_search_service.ReferenceImage`): + reference_image (:class:`google.cloud.vision_v1p3beta1.types.ReferenceImage`): Required. The reference image to create. If an image ID is specified, it is ignored. + This corresponds to the ``reference_image`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1184,6 +1201,7 @@ async def create_reference_image( as the resource id. If it is already in use, an error is returned with code ALREADY_EXISTS. Must be at most 128 characters long. It cannot contain the character ``/``. + This corresponds to the ``reference_image_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1195,9 +1213,9 @@ async def create_reference_image( sent along with the request as metadata. Returns: - ~.product_search_service.ReferenceImage: - A ``ReferenceImage`` represents a product image and its - associated metadata, such as bounding boxes. + google.cloud.vision_v1p3beta1.types.ReferenceImage: + A ReferenceImage represents a product image and its associated metadata, + such as bounding boxes. """ # Create or coerce a protobuf request object. @@ -1271,7 +1289,7 @@ async def delete_reference_image( - Returns NOT_FOUND if the reference image does not exist. Args: - request (:class:`~.product_search_service.DeleteReferenceImageRequest`): + request (:class:`google.cloud.vision_v1p3beta1.types.DeleteReferenceImageRequest`): The request object. Request message for the `DeleteReferenceImage` method. name (:class:`str`): @@ -1281,6 +1299,7 @@ async def delete_reference_image( Format is: ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1354,7 +1373,7 @@ async def list_reference_images( 100, or less than 1. Args: - request (:class:`~.product_search_service.ListReferenceImagesRequest`): + request (:class:`google.cloud.vision_v1p3beta1.types.ListReferenceImagesRequest`): The request object. Request message for the `ListReferenceImages` method. parent (:class:`str`): @@ -1363,6 +1382,7 @@ async def list_reference_images( Format is ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1374,8 +1394,8 @@ async def list_reference_images( sent along with the request as metadata. Returns: - ~.pagers.ListReferenceImagesAsyncPager: - Response message for the ``ListReferenceImages`` method. + google.cloud.vision_v1p3beta1.services.product_search.pagers.ListReferenceImagesAsyncPager: + Response message for the ListReferenceImages method. Iterating over this object will yield results and resolve additional pages automatically. @@ -1449,7 +1469,7 @@ async def get_reference_image( - Returns NOT_FOUND if the specified image does not exist. Args: - request (:class:`~.product_search_service.GetReferenceImageRequest`): + request (:class:`google.cloud.vision_v1p3beta1.types.GetReferenceImageRequest`): The request object. Request message for the `GetReferenceImage` method. name (:class:`str`): @@ -1459,6 +1479,7 @@ async def get_reference_image( Format is: ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1470,9 +1491,9 @@ async def get_reference_image( sent along with the request as metadata. Returns: - ~.product_search_service.ReferenceImage: - A ``ReferenceImage`` represents a product image and its - associated metadata, such as bounding boxes. + google.cloud.vision_v1p3beta1.types.ReferenceImage: + A ReferenceImage represents a product image and its associated metadata, + such as bounding boxes. """ # Create or coerce a protobuf request object. @@ -1542,7 +1563,7 @@ async def add_product_to_product_set( exist. Args: - request (:class:`~.product_search_service.AddProductToProductSetRequest`): + request (:class:`google.cloud.vision_v1p3beta1.types.AddProductToProductSetRequest`): The request object. Request message for the `AddProductToProductSet` method. name (:class:`str`): @@ -1551,6 +1572,7 @@ async def add_product_to_product_set( Format is: ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1560,6 +1582,7 @@ async def add_product_to_product_set( Format is: ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + This corresponds to the ``product`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1633,7 +1656,7 @@ async def remove_product_from_product_set( ProductSet. Args: - request (:class:`~.product_search_service.RemoveProductFromProductSetRequest`): + request (:class:`google.cloud.vision_v1p3beta1.types.RemoveProductFromProductSetRequest`): The request object. Request message for the `RemoveProductFromProductSet` method. name (:class:`str`): @@ -1642,6 +1665,7 @@ async def remove_product_from_product_set( Format is: ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1651,6 +1675,7 @@ async def remove_product_from_product_set( Format is: ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + This corresponds to the ``product`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1725,7 +1750,7 @@ async def list_products_in_product_set( less than 1. Args: - request (:class:`~.product_search_service.ListProductsInProductSetRequest`): + request (:class:`google.cloud.vision_v1p3beta1.types.ListProductsInProductSetRequest`): The request object. Request message for the `ListProductsInProductSet` method. name (:class:`str`): @@ -1734,6 +1759,7 @@ async def list_products_in_product_set( Format is: ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1745,8 +1771,8 @@ async def list_products_in_product_set( sent along with the request as metadata. Returns: - ~.pagers.ListProductsInProductSetAsyncPager: - Response message for the ``ListProductsInProductSet`` + google.cloud.vision_v1p3beta1.services.product_search.pagers.ListProductsInProductSetAsyncPager: + Response message for the ListProductsInProductSet method. Iterating over this object will yield results and @@ -1829,7 +1855,7 @@ async def import_product_sets( [ImportProductSetsGcsSource.csv_file_uri][google.cloud.vision.v1p3beta1.ImportProductSetsGcsSource.csv_file_uri]. Args: - request (:class:`~.product_search_service.ImportProductSetsRequest`): + request (:class:`google.cloud.vision_v1p3beta1.types.ImportProductSetsRequest`): The request object. Request message for the `ImportProductSets` method. parent (:class:`str`): @@ -1837,12 +1863,14 @@ async def import_product_sets( imported. Format is ``projects/PROJECT_ID/locations/LOC_ID``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - input_config (:class:`~.product_search_service.ImportProductSetsInputConfig`): + input_config (:class:`google.cloud.vision_v1p3beta1.types.ImportProductSetsInputConfig`): Required. The input content for the list of requests. + This corresponds to the ``input_config`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1854,18 +1882,18 @@ async def import_product_sets( sent along with the request as metadata. Returns: - ~.operation_async.AsyncOperation: + google.api_core.operation_async.AsyncOperation: An object representing a long-running operation. The result type for the operation will be - :class:``~.product_search_service.ImportProductSetsResponse``: - Response message for the ``ImportProductSets`` method. - - This message is returned by the - [google.longrunning.Operations.GetOperation][google.longrunning.Operations.GetOperation] - method in the returned - [google.longrunning.Operation.response][google.longrunning.Operation.response] - field. + :class:`google.cloud.vision_v1p3beta1.types.ImportProductSetsResponse` + Response message for the ImportProductSets method. + + This message is returned by the + [google.longrunning.Operations.GetOperation][google.longrunning.Operations.GetOperation] + method in the returned + [google.longrunning.Operation.response][google.longrunning.Operation.response] + field. """ # Create or coerce a protobuf request object. diff --git a/google/cloud/vision_v1p3beta1/services/product_search/client.py b/google/cloud/vision_v1p3beta1/services/product_search/client.py index 804985ed..729476be 100644 --- a/google/cloud/vision_v1p3beta1/services/product_search/client.py +++ b/google/cloud/vision_v1p3beta1/services/product_search/client.py @@ -134,6 +134,22 @@ def _get_default_mtls_endpoint(api_endpoint): DEFAULT_ENDPOINT ) + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + ProductSearchClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_info(info) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials @@ -146,7 +162,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): kwargs: Additional arguments to pass to the constructor. Returns: - {@api.name}: The constructed client. + ProductSearchClient: The constructed client. """ credentials = service_account.Credentials.from_service_account_file(filename) kwargs["credentials"] = credentials @@ -291,10 +307,10 @@ def __init__( credentials identify the application to the service; if none are specified, the client will attempt to ascertain the credentials from the environment. - transport (Union[str, ~.ProductSearchTransport]): The + transport (Union[str, ProductSearchTransport]): The transport to use. If set to None, a transport is chosen automatically. - client_options (client_options_lib.ClientOptions): Custom options for the + client_options (google.api_core.client_options.ClientOptions): Custom options for the client. It won't take effect if a ``transport`` instance is provided. (1) The ``api_endpoint`` property can be used to override the default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT @@ -330,21 +346,17 @@ def __init__( util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")) ) - ssl_credentials = None + client_cert_source_func = None is_mtls = False if use_client_cert: if client_options.client_cert_source: - import grpc # type: ignore - - cert, key = client_options.client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) is_mtls = True + client_cert_source_func = client_options.client_cert_source else: - creds = SslCredentials() - is_mtls = creds.is_mtls - ssl_credentials = creds.ssl_credentials if is_mtls else None + is_mtls = mtls.has_default_client_cert_source() + client_cert_source_func = ( + mtls.default_client_cert_source() if is_mtls else None + ) # Figure out which api endpoint to use. if client_options.api_endpoint is not None: @@ -387,7 +399,7 @@ def __init__( credentials_file=client_options.credentials_file, host=api_endpoint, scopes=client_options.scopes, - ssl_channel_credentials=ssl_credentials, + client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, ) @@ -411,28 +423,30 @@ def create_product_set( longer than 4096 characters. Args: - request (:class:`~.product_search_service.CreateProductSetRequest`): + request (google.cloud.vision_v1p3beta1.types.CreateProductSetRequest): The request object. Request message for the `CreateProductSet` method. - parent (:class:`str`): + parent (str): Required. The project in which the ProductSet should be created. Format is ``projects/PROJECT_ID/locations/LOC_ID``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - product_set (:class:`~.product_search_service.ProductSet`): + product_set (google.cloud.vision_v1p3beta1.types.ProductSet): Required. The ProductSet to create. This corresponds to the ``product_set`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - product_set_id (:class:`str`): + product_set_id (str): A user-supplied resource id for this ProductSet. If set, the server will attempt to use this value as the resource id. If it is already in use, an error is returned with code ALREADY_EXISTS. Must be at most 128 characters long. It cannot contain the character ``/``. + This corresponds to the ``product_set_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -444,7 +458,7 @@ def create_product_set( sent along with the request as metadata. Returns: - ~.product_search_service.ProductSet: + google.cloud.vision_v1p3beta1.types.ProductSet: A ProductSet contains Products. A ProductSet can contain a maximum of 1 million reference images. If the limit @@ -512,14 +526,15 @@ def list_product_sets( less than 1. Args: - request (:class:`~.product_search_service.ListProductSetsRequest`): + request (google.cloud.vision_v1p3beta1.types.ListProductSetsRequest): The request object. Request message for the `ListProductSets` method. - parent (:class:`str`): + parent (str): Required. The project from which ProductSets should be listed. Format is ``projects/PROJECT_ID/locations/LOC_ID``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -531,8 +546,8 @@ def list_product_sets( sent along with the request as metadata. Returns: - ~.pagers.ListProductSetsPager: - Response message for the ``ListProductSets`` method. + google.cloud.vision_v1p3beta1.services.product_search.pagers.ListProductSetsPager: + Response message for the ListProductSets method. Iterating over this object will yield results and resolve additional pages automatically. @@ -599,14 +614,15 @@ def get_product_set( - Returns NOT_FOUND if the ProductSet does not exist. Args: - request (:class:`~.product_search_service.GetProductSetRequest`): + request (google.cloud.vision_v1p3beta1.types.GetProductSetRequest): The request object. Request message for the `GetProductSet` method. - name (:class:`str`): + name (str): Required. Resource name of the ProductSet to get. Format is: ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -618,7 +634,7 @@ def get_product_set( sent along with the request as metadata. Returns: - ~.product_search_service.ProductSet: + google.cloud.vision_v1p3beta1.types.ProductSet: A ProductSet contains Products. A ProductSet can contain a maximum of 1 million reference images. If the limit @@ -686,20 +702,22 @@ def update_product_set( characters. Args: - request (:class:`~.product_search_service.UpdateProductSetRequest`): + request (google.cloud.vision_v1p3beta1.types.UpdateProductSetRequest): The request object. Request message for the `UpdateProductSet` method. - product_set (:class:`~.product_search_service.ProductSet`): + product_set (google.cloud.vision_v1p3beta1.types.ProductSet): Required. The ProductSet resource which replaces the one on the server. + This corresponds to the ``product_set`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - update_mask (:class:`~.field_mask.FieldMask`): + update_mask (google.protobuf.field_mask_pb2.FieldMask): The [FieldMask][google.protobuf.FieldMask] that specifies which fields to update. If update_mask isn't specified, all mutable fields are to be updated. Valid mask path is ``display_name``. + This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -711,7 +729,7 @@ def update_product_set( sent along with the request as metadata. Returns: - ~.product_search_service.ProductSet: + google.cloud.vision_v1p3beta1.types.ProductSet: A ProductSet contains Products. A ProductSet can contain a maximum of 1 million reference images. If the limit @@ -782,14 +800,15 @@ def delete_product_set( - Returns NOT_FOUND if the ProductSet does not exist. Args: - request (:class:`~.product_search_service.DeleteProductSetRequest`): + request (google.cloud.vision_v1p3beta1.types.DeleteProductSetRequest): The request object. Request message for the `DeleteProductSet` method. - name (:class:`str`): + name (str): Required. Resource name of the ProductSet to delete. Format is: ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -861,28 +880,30 @@ def create_product( invalid. Args: - request (:class:`~.product_search_service.CreateProductRequest`): + request (google.cloud.vision_v1p3beta1.types.CreateProductRequest): The request object. Request message for the `CreateProduct` method. - parent (:class:`str`): + parent (str): Required. The project in which the Product should be created. Format is ``projects/PROJECT_ID/locations/LOC_ID``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - product (:class:`~.product_search_service.Product`): + product (google.cloud.vision_v1p3beta1.types.Product): Required. The product to create. This corresponds to the ``product`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - product_id (:class:`str`): + product_id (str): A user-supplied resource id for this Product. If set, the server will attempt to use this value as the resource id. If it is already in use, an error is returned with code ALREADY_EXISTS. Must be at most 128 characters long. It cannot contain the character ``/``. + This corresponds to the ``product_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -894,7 +915,7 @@ def create_product( sent along with the request as metadata. Returns: - ~.product_search_service.Product: + google.cloud.vision_v1p3beta1.types.Product: A Product contains ReferenceImages. """ # Create or coerce a protobuf request object. @@ -957,14 +978,15 @@ def list_products( less than 1. Args: - request (:class:`~.product_search_service.ListProductsRequest`): + request (google.cloud.vision_v1p3beta1.types.ListProductsRequest): The request object. Request message for the `ListProducts` method. - parent (:class:`str`): + parent (str): Required. The project OR ProductSet from which Products should be listed. Format: ``projects/PROJECT_ID/locations/LOC_ID`` + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -976,8 +998,8 @@ def list_products( sent along with the request as metadata. Returns: - ~.pagers.ListProductsPager: - Response message for the ``ListProducts`` method. + google.cloud.vision_v1p3beta1.services.product_search.pagers.ListProductsPager: + Response message for the ListProducts method. Iterating over this object will yield results and resolve additional pages automatically. @@ -1044,14 +1066,15 @@ def get_product( - Returns NOT_FOUND if the Product does not exist. Args: - request (:class:`~.product_search_service.GetProductRequest`): + request (google.cloud.vision_v1p3beta1.types.GetProductRequest): The request object. Request message for the `GetProduct` method. - name (:class:`str`): + name (str): Required. Resource name of the Product to get. Format is: ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1063,7 +1086,7 @@ def get_product( sent along with the request as metadata. Returns: - ~.product_search_service.Product: + google.cloud.vision_v1p3beta1.types.Product: A Product contains ReferenceImages. """ # Create or coerce a protobuf request object. @@ -1133,22 +1156,24 @@ def update_product( update_mask. Args: - request (:class:`~.product_search_service.UpdateProductRequest`): + request (google.cloud.vision_v1p3beta1.types.UpdateProductRequest): The request object. Request message for the `UpdateProduct` method. - product (:class:`~.product_search_service.Product`): + product (google.cloud.vision_v1p3beta1.types.Product): Required. The Product resource which replaces the one on the server. product.name is immutable. + This corresponds to the ``product`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - update_mask (:class:`~.field_mask.FieldMask`): + update_mask (google.protobuf.field_mask_pb2.FieldMask): The [FieldMask][google.protobuf.FieldMask] that specifies which fields to update. If update_mask isn't specified, all mutable fields are to be updated. Valid mask paths include ``product_labels``, ``display_name``, and ``description``. + This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1160,7 +1185,7 @@ def update_product( sent along with the request as metadata. Returns: - ~.product_search_service.Product: + google.cloud.vision_v1p3beta1.types.Product: A Product contains ReferenceImages. """ # Create or coerce a protobuf request object. @@ -1226,14 +1251,15 @@ def delete_product( - Returns NOT_FOUND if the product does not exist. Args: - request (:class:`~.product_search_service.DeleteProductRequest`): + request (google.cloud.vision_v1p3beta1.types.DeleteProductRequest): The request object. Request message for the `DeleteProduct` method. - name (:class:`str`): + name (str): Required. Resource name of product to delete. Format is: ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1317,31 +1343,34 @@ def create_reference_image( 10 polygons. Args: - request (:class:`~.product_search_service.CreateReferenceImageRequest`): + request (google.cloud.vision_v1p3beta1.types.CreateReferenceImageRequest): The request object. Request message for the `CreateReferenceImage` method. - parent (:class:`str`): + parent (str): Required. Resource name of the product in which to create the reference image. Format is ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - reference_image (:class:`~.product_search_service.ReferenceImage`): + reference_image (google.cloud.vision_v1p3beta1.types.ReferenceImage): Required. The reference image to create. If an image ID is specified, it is ignored. + This corresponds to the ``reference_image`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - reference_image_id (:class:`str`): + reference_image_id (str): A user-supplied resource id for the ReferenceImage to be added. If set, the server will attempt to use this value as the resource id. If it is already in use, an error is returned with code ALREADY_EXISTS. Must be at most 128 characters long. It cannot contain the character ``/``. + This corresponds to the ``reference_image_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1353,9 +1382,9 @@ def create_reference_image( sent along with the request as metadata. Returns: - ~.product_search_service.ReferenceImage: - A ``ReferenceImage`` represents a product image and its - associated metadata, such as bounding boxes. + google.cloud.vision_v1p3beta1.types.ReferenceImage: + A ReferenceImage represents a product image and its associated metadata, + such as bounding boxes. """ # Create or coerce a protobuf request object. @@ -1424,16 +1453,17 @@ def delete_reference_image( - Returns NOT_FOUND if the reference image does not exist. Args: - request (:class:`~.product_search_service.DeleteReferenceImageRequest`): + request (google.cloud.vision_v1p3beta1.types.DeleteReferenceImageRequest): The request object. Request message for the `DeleteReferenceImage` method. - name (:class:`str`): + name (str): Required. The resource name of the reference image to delete. Format is: ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1500,15 +1530,16 @@ def list_reference_images( 100, or less than 1. Args: - request (:class:`~.product_search_service.ListReferenceImagesRequest`): + request (google.cloud.vision_v1p3beta1.types.ListReferenceImagesRequest): The request object. Request message for the `ListReferenceImages` method. - parent (:class:`str`): + parent (str): Required. Resource name of the product containing the reference images. Format is ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1520,8 +1551,8 @@ def list_reference_images( sent along with the request as metadata. Returns: - ~.pagers.ListReferenceImagesPager: - Response message for the ``ListReferenceImages`` method. + google.cloud.vision_v1p3beta1.services.product_search.pagers.ListReferenceImagesPager: + Response message for the ListReferenceImages method. Iterating over this object will yield results and resolve additional pages automatically. @@ -1588,16 +1619,17 @@ def get_reference_image( - Returns NOT_FOUND if the specified image does not exist. Args: - request (:class:`~.product_search_service.GetReferenceImageRequest`): + request (google.cloud.vision_v1p3beta1.types.GetReferenceImageRequest): The request object. Request message for the `GetReferenceImage` method. - name (:class:`str`): + name (str): Required. The resource name of the ReferenceImage to get. Format is: ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1609,9 +1641,9 @@ def get_reference_image( sent along with the request as metadata. Returns: - ~.product_search_service.ReferenceImage: - A ``ReferenceImage`` represents a product image and its - associated metadata, such as bounding boxes. + google.cloud.vision_v1p3beta1.types.ReferenceImage: + A ReferenceImage represents a product image and its associated metadata, + such as bounding boxes. """ # Create or coerce a protobuf request object. @@ -1674,24 +1706,26 @@ def add_product_to_product_set( exist. Args: - request (:class:`~.product_search_service.AddProductToProductSetRequest`): + request (google.cloud.vision_v1p3beta1.types.AddProductToProductSetRequest): The request object. Request message for the `AddProductToProductSet` method. - name (:class:`str`): + name (str): Required. The resource name for the ProductSet to modify. Format is: ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - product (:class:`str`): + product (str): Required. The resource name for the Product to be added to this ProductSet. Format is: ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + This corresponds to the ``product`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1764,24 +1798,26 @@ def remove_product_from_product_set( ProductSet. Args: - request (:class:`~.product_search_service.RemoveProductFromProductSetRequest`): + request (google.cloud.vision_v1p3beta1.types.RemoveProductFromProductSetRequest): The request object. Request message for the `RemoveProductFromProductSet` method. - name (:class:`str`): + name (str): Required. The resource name for the ProductSet to modify. Format is: ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - product (:class:`str`): + product (str): Required. The resource name for the Product to be removed from this ProductSet. Format is: ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + This corresponds to the ``product`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1855,15 +1891,16 @@ def list_products_in_product_set( less than 1. Args: - request (:class:`~.product_search_service.ListProductsInProductSetRequest`): + request (google.cloud.vision_v1p3beta1.types.ListProductsInProductSetRequest): The request object. Request message for the `ListProductsInProductSet` method. - name (:class:`str`): + name (str): Required. The ProductSet resource for which to retrieve Products. Format is: ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1875,8 +1912,8 @@ def list_products_in_product_set( sent along with the request as metadata. Returns: - ~.pagers.ListProductsInProductSetPager: - Response message for the ``ListProductsInProductSet`` + google.cloud.vision_v1p3beta1.services.product_search.pagers.ListProductsInProductSetPager: + Response message for the ListProductsInProductSet method. Iterating over this object will yield results and @@ -1956,20 +1993,22 @@ def import_product_sets( [ImportProductSetsGcsSource.csv_file_uri][google.cloud.vision.v1p3beta1.ImportProductSetsGcsSource.csv_file_uri]. Args: - request (:class:`~.product_search_service.ImportProductSetsRequest`): + request (google.cloud.vision_v1p3beta1.types.ImportProductSetsRequest): The request object. Request message for the `ImportProductSets` method. - parent (:class:`str`): + parent (str): Required. The project in which the ProductSets should be imported. Format is ``projects/PROJECT_ID/locations/LOC_ID``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - input_config (:class:`~.product_search_service.ImportProductSetsInputConfig`): + input_config (google.cloud.vision_v1p3beta1.types.ImportProductSetsInputConfig): Required. The input content for the list of requests. + This corresponds to the ``input_config`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1981,18 +2020,18 @@ def import_product_sets( sent along with the request as metadata. Returns: - ~.operation.Operation: + google.api_core.operation.Operation: An object representing a long-running operation. The result type for the operation will be - :class:``~.product_search_service.ImportProductSetsResponse``: - Response message for the ``ImportProductSets`` method. - - This message is returned by the - [google.longrunning.Operations.GetOperation][google.longrunning.Operations.GetOperation] - method in the returned - [google.longrunning.Operation.response][google.longrunning.Operation.response] - field. + :class:`google.cloud.vision_v1p3beta1.types.ImportProductSetsResponse` + Response message for the ImportProductSets method. + + This message is returned by the + [google.longrunning.Operations.GetOperation][google.longrunning.Operations.GetOperation] + method in the returned + [google.longrunning.Operation.response][google.longrunning.Operation.response] + field. """ # Create or coerce a protobuf request object. diff --git a/google/cloud/vision_v1p3beta1/services/product_search/pagers.py b/google/cloud/vision_v1p3beta1/services/product_search/pagers.py index 85829a6e..49f585a6 100644 --- a/google/cloud/vision_v1p3beta1/services/product_search/pagers.py +++ b/google/cloud/vision_v1p3beta1/services/product_search/pagers.py @@ -15,7 +15,16 @@ # limitations under the License. # -from typing import Any, AsyncIterable, Awaitable, Callable, Iterable, Sequence, Tuple +from typing import ( + Any, + AsyncIterable, + Awaitable, + Callable, + Iterable, + Sequence, + Tuple, + Optional, +) from google.cloud.vision_v1p3beta1.types import product_search_service @@ -24,7 +33,7 @@ class ListProductSetsPager: """A pager for iterating through ``list_product_sets`` requests. This class thinly wraps an initial - :class:`~.product_search_service.ListProductSetsResponse` object, and + :class:`google.cloud.vision_v1p3beta1.types.ListProductSetsResponse` object, and provides an ``__iter__`` method to iterate through its ``product_sets`` field. @@ -33,7 +42,7 @@ class ListProductSetsPager: through the ``product_sets`` field on the corresponding responses. - All the usual :class:`~.product_search_service.ListProductSetsResponse` + All the usual :class:`google.cloud.vision_v1p3beta1.types.ListProductSetsResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -51,9 +60,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.product_search_service.ListProductSetsRequest`): + request (google.cloud.vision_v1p3beta1.types.ListProductSetsRequest): The initial request object. - response (:class:`~.product_search_service.ListProductSetsResponse`): + response (google.cloud.vision_v1p3beta1.types.ListProductSetsResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -86,7 +95,7 @@ class ListProductSetsAsyncPager: """A pager for iterating through ``list_product_sets`` requests. This class thinly wraps an initial - :class:`~.product_search_service.ListProductSetsResponse` object, and + :class:`google.cloud.vision_v1p3beta1.types.ListProductSetsResponse` object, and provides an ``__aiter__`` method to iterate through its ``product_sets`` field. @@ -95,7 +104,7 @@ class ListProductSetsAsyncPager: through the ``product_sets`` field on the corresponding responses. - All the usual :class:`~.product_search_service.ListProductSetsResponse` + All the usual :class:`google.cloud.vision_v1p3beta1.types.ListProductSetsResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -115,9 +124,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.product_search_service.ListProductSetsRequest`): + request (google.cloud.vision_v1p3beta1.types.ListProductSetsRequest): The initial request object. - response (:class:`~.product_search_service.ListProductSetsResponse`): + response (google.cloud.vision_v1p3beta1.types.ListProductSetsResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -156,7 +165,7 @@ class ListProductsPager: """A pager for iterating through ``list_products`` requests. This class thinly wraps an initial - :class:`~.product_search_service.ListProductsResponse` object, and + :class:`google.cloud.vision_v1p3beta1.types.ListProductsResponse` object, and provides an ``__iter__`` method to iterate through its ``products`` field. @@ -165,7 +174,7 @@ class ListProductsPager: through the ``products`` field on the corresponding responses. - All the usual :class:`~.product_search_service.ListProductsResponse` + All the usual :class:`google.cloud.vision_v1p3beta1.types.ListProductsResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -183,9 +192,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.product_search_service.ListProductsRequest`): + request (google.cloud.vision_v1p3beta1.types.ListProductsRequest): The initial request object. - response (:class:`~.product_search_service.ListProductsResponse`): + response (google.cloud.vision_v1p3beta1.types.ListProductsResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -218,7 +227,7 @@ class ListProductsAsyncPager: """A pager for iterating through ``list_products`` requests. This class thinly wraps an initial - :class:`~.product_search_service.ListProductsResponse` object, and + :class:`google.cloud.vision_v1p3beta1.types.ListProductsResponse` object, and provides an ``__aiter__`` method to iterate through its ``products`` field. @@ -227,7 +236,7 @@ class ListProductsAsyncPager: through the ``products`` field on the corresponding responses. - All the usual :class:`~.product_search_service.ListProductsResponse` + All the usual :class:`google.cloud.vision_v1p3beta1.types.ListProductsResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -245,9 +254,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.product_search_service.ListProductsRequest`): + request (google.cloud.vision_v1p3beta1.types.ListProductsRequest): The initial request object. - response (:class:`~.product_search_service.ListProductsResponse`): + response (google.cloud.vision_v1p3beta1.types.ListProductsResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -284,7 +293,7 @@ class ListReferenceImagesPager: """A pager for iterating through ``list_reference_images`` requests. This class thinly wraps an initial - :class:`~.product_search_service.ListReferenceImagesResponse` object, and + :class:`google.cloud.vision_v1p3beta1.types.ListReferenceImagesResponse` object, and provides an ``__iter__`` method to iterate through its ``reference_images`` field. @@ -293,7 +302,7 @@ class ListReferenceImagesPager: through the ``reference_images`` field on the corresponding responses. - All the usual :class:`~.product_search_service.ListReferenceImagesResponse` + All the usual :class:`google.cloud.vision_v1p3beta1.types.ListReferenceImagesResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -311,9 +320,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.product_search_service.ListReferenceImagesRequest`): + request (google.cloud.vision_v1p3beta1.types.ListReferenceImagesRequest): The initial request object. - response (:class:`~.product_search_service.ListReferenceImagesResponse`): + response (google.cloud.vision_v1p3beta1.types.ListReferenceImagesResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -346,7 +355,7 @@ class ListReferenceImagesAsyncPager: """A pager for iterating through ``list_reference_images`` requests. This class thinly wraps an initial - :class:`~.product_search_service.ListReferenceImagesResponse` object, and + :class:`google.cloud.vision_v1p3beta1.types.ListReferenceImagesResponse` object, and provides an ``__aiter__`` method to iterate through its ``reference_images`` field. @@ -355,7 +364,7 @@ class ListReferenceImagesAsyncPager: through the ``reference_images`` field on the corresponding responses. - All the usual :class:`~.product_search_service.ListReferenceImagesResponse` + All the usual :class:`google.cloud.vision_v1p3beta1.types.ListReferenceImagesResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -375,9 +384,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.product_search_service.ListReferenceImagesRequest`): + request (google.cloud.vision_v1p3beta1.types.ListReferenceImagesRequest): The initial request object. - response (:class:`~.product_search_service.ListReferenceImagesResponse`): + response (google.cloud.vision_v1p3beta1.types.ListReferenceImagesResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -416,7 +425,7 @@ class ListProductsInProductSetPager: """A pager for iterating through ``list_products_in_product_set`` requests. This class thinly wraps an initial - :class:`~.product_search_service.ListProductsInProductSetResponse` object, and + :class:`google.cloud.vision_v1p3beta1.types.ListProductsInProductSetResponse` object, and provides an ``__iter__`` method to iterate through its ``products`` field. @@ -425,7 +434,7 @@ class ListProductsInProductSetPager: through the ``products`` field on the corresponding responses. - All the usual :class:`~.product_search_service.ListProductsInProductSetResponse` + All the usual :class:`google.cloud.vision_v1p3beta1.types.ListProductsInProductSetResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -443,9 +452,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.product_search_service.ListProductsInProductSetRequest`): + request (google.cloud.vision_v1p3beta1.types.ListProductsInProductSetRequest): The initial request object. - response (:class:`~.product_search_service.ListProductsInProductSetResponse`): + response (google.cloud.vision_v1p3beta1.types.ListProductsInProductSetResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -480,7 +489,7 @@ class ListProductsInProductSetAsyncPager: """A pager for iterating through ``list_products_in_product_set`` requests. This class thinly wraps an initial - :class:`~.product_search_service.ListProductsInProductSetResponse` object, and + :class:`google.cloud.vision_v1p3beta1.types.ListProductsInProductSetResponse` object, and provides an ``__aiter__`` method to iterate through its ``products`` field. @@ -489,7 +498,7 @@ class ListProductsInProductSetAsyncPager: through the ``products`` field on the corresponding responses. - All the usual :class:`~.product_search_service.ListProductsInProductSetResponse` + All the usual :class:`google.cloud.vision_v1p3beta1.types.ListProductsInProductSetResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -509,9 +518,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.product_search_service.ListProductsInProductSetRequest`): + request (google.cloud.vision_v1p3beta1.types.ListProductsInProductSetRequest): The initial request object. - response (:class:`~.product_search_service.ListProductsInProductSetResponse`): + response (google.cloud.vision_v1p3beta1.types.ListProductsInProductSetResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. diff --git a/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc.py b/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc.py index d48af7d8..b2fc91ee 100644 --- a/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc.py +++ b/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc.py @@ -79,6 +79,7 @@ def __init__( api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -109,6 +110,10 @@ def __init__( ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -125,6 +130,11 @@ def __init__( """ self._ssl_channel_credentials = ssl_channel_credentials + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -134,11 +144,6 @@ def __init__( self._grpc_channel = channel self._ssl_channel_credentials = None elif api_mtls_endpoint: - warnings.warn( - "api_mtls_endpoint and client_cert_source are deprecated", - DeprecationWarning, - ) - host = ( api_mtls_endpoint if ":" in api_mtls_endpoint @@ -182,12 +187,18 @@ def __init__( scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id ) + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + # create a new channel. The provided one is ignored. self._grpc_channel = type(self).create_channel( host, credentials=credentials, credentials_file=credentials_file, - ssl_credentials=ssl_channel_credentials, + ssl_credentials=self._ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ diff --git a/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc_asyncio.py b/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc_asyncio.py index 68078018..082a5a4a 100644 --- a/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc_asyncio.py +++ b/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc_asyncio.py @@ -123,6 +123,7 @@ def __init__( api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -154,6 +155,10 @@ def __init__( ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -170,6 +175,11 @@ def __init__( """ self._ssl_channel_credentials = ssl_channel_credentials + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -179,11 +189,6 @@ def __init__( self._grpc_channel = channel self._ssl_channel_credentials = None elif api_mtls_endpoint: - warnings.warn( - "api_mtls_endpoint and client_cert_source are deprecated", - DeprecationWarning, - ) - host = ( api_mtls_endpoint if ":" in api_mtls_endpoint @@ -227,12 +232,18 @@ def __init__( scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id ) + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + # create a new channel. The provided one is ignored. self._grpc_channel = type(self).create_channel( host, credentials=credentials, credentials_file=credentials_file, - ssl_credentials=ssl_channel_credentials, + ssl_credentials=self._ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ diff --git a/google/cloud/vision_v1p3beta1/types/geometry.py b/google/cloud/vision_v1p3beta1/types/geometry.py index e6107175..c1b1fd91 100644 --- a/google/cloud/vision_v1p3beta1/types/geometry.py +++ b/google/cloud/vision_v1p3beta1/types/geometry.py @@ -68,9 +68,9 @@ class BoundingPoly(proto.Message): r"""A bounding polygon for the detected image annotation. Attributes: - vertices (Sequence[~.geometry.Vertex]): + vertices (Sequence[google.cloud.vision_v1p3beta1.types.Vertex]): The bounding polygon vertices. - normalized_vertices (Sequence[~.geometry.NormalizedVertex]): + normalized_vertices (Sequence[google.cloud.vision_v1p3beta1.types.NormalizedVertex]): The bounding polygon normalized vertices. """ @@ -85,7 +85,7 @@ class NormalizedBoundingPoly(proto.Message): r"""A normalized bounding polygon around a portion of an image. Attributes: - vertices (Sequence[~.geometry.NormalizedVertex]): + vertices (Sequence[google.cloud.vision_v1p3beta1.types.NormalizedVertex]): Normalized vertices of the bounding polygon. """ diff --git a/google/cloud/vision_v1p3beta1/types/image_annotator.py b/google/cloud/vision_v1p3beta1/types/image_annotator.py index 7c5f1d41..0af98b5a 100644 --- a/google/cloud/vision_v1p3beta1/types/image_annotator.py +++ b/google/cloud/vision_v1p3beta1/types/image_annotator.py @@ -88,7 +88,7 @@ class Feature(proto.Message): ``Feature`` objects can be specified in the ``features`` list. Attributes: - type_ (~.image_annotator.Feature.Type): + type_ (google.cloud.vision_v1p3beta1.types.Feature.Type): The feature type. max_results (int): Maximum number of results of this type. Does not apply to @@ -171,7 +171,7 @@ class Image(proto.Message): Image content, represented as a stream of bytes. Note: As with all ``bytes`` fields, protobuffers use a pure binary representation, whereas JSON representations use base64. - source (~.image_annotator.ImageSource): + source (google.cloud.vision_v1p3beta1.types.ImageSource): Google Cloud Storage image location, or publicly-accessible image URL. If both ``content`` and ``source`` are provided for an image, ``content`` takes precedence and is used to @@ -188,7 +188,7 @@ class FaceAnnotation(proto.Message): detection. Attributes: - bounding_poly (~.geometry.BoundingPoly): + bounding_poly (google.cloud.vision_v1p3beta1.types.BoundingPoly): The bounding polygon around the face. The coordinates of the bounding box are in the original image's scale, as returned in ``ImageParams``. The bounding box is computed to "frame" @@ -197,7 +197,7 @@ class FaceAnnotation(proto.Message): coordinates may not be generated in the ``BoundingPoly`` (the polygon will be unbounded) if only a partial face appears in the image to be annotated. - fd_bounding_poly (~.geometry.BoundingPoly): + fd_bounding_poly (google.cloud.vision_v1p3beta1.types.BoundingPoly): The ``fd_bounding_poly`` bounding polygon is tighter than the ``boundingPoly``, and encloses only the skin part of the face. Typically, it is used to eliminate the face from any @@ -205,7 +205,7 @@ class FaceAnnotation(proto.Message): an image. It is not based on the landmarker results, only on the initial face detection, hence the fd (face detection) prefix. - landmarks (Sequence[~.image_annotator.FaceAnnotation.Landmark]): + landmarks (Sequence[google.cloud.vision_v1p3beta1.types.FaceAnnotation.Landmark]): Detected face landmarks. roll_angle (float): Roll angle, which indicates the amount of @@ -224,19 +224,19 @@ class FaceAnnotation(proto.Message): Detection confidence. Range [0, 1]. landmarking_confidence (float): Face landmarking confidence. Range [0, 1]. - joy_likelihood (~.image_annotator.Likelihood): + joy_likelihood (google.cloud.vision_v1p3beta1.types.Likelihood): Joy likelihood. - sorrow_likelihood (~.image_annotator.Likelihood): + sorrow_likelihood (google.cloud.vision_v1p3beta1.types.Likelihood): Sorrow likelihood. - anger_likelihood (~.image_annotator.Likelihood): + anger_likelihood (google.cloud.vision_v1p3beta1.types.Likelihood): Anger likelihood. - surprise_likelihood (~.image_annotator.Likelihood): + surprise_likelihood (google.cloud.vision_v1p3beta1.types.Likelihood): Surprise likelihood. - under_exposed_likelihood (~.image_annotator.Likelihood): + under_exposed_likelihood (google.cloud.vision_v1p3beta1.types.Likelihood): Under-exposed likelihood. - blurred_likelihood (~.image_annotator.Likelihood): + blurred_likelihood (google.cloud.vision_v1p3beta1.types.Likelihood): Blurred likelihood. - headwear_likelihood (~.image_annotator.Likelihood): + headwear_likelihood (google.cloud.vision_v1p3beta1.types.Likelihood): Headwear likelihood. """ @@ -244,9 +244,9 @@ class Landmark(proto.Message): r"""A face-specific landmark (for example, a face feature). Attributes: - type_ (~.image_annotator.FaceAnnotation.Landmark.Type): + type_ (google.cloud.vision_v1p3beta1.types.FaceAnnotation.Landmark.Type): Face landmark type. - position (~.geometry.Position): + position (google.cloud.vision_v1p3beta1.types.Position): Face landmark position. """ @@ -333,7 +333,7 @@ class LocationInfo(proto.Message): r"""Detected entity location information. Attributes: - lat_lng (~.latlng.LatLng): + lat_lng (google.type.latlng_pb2.LatLng): lat/long location coordinates. """ @@ -388,17 +388,17 @@ class EntityAnnotation(proto.Message): than to an image containing a detected distant towering building, even though the confidence that there is a tower in each image may be the same. Range [0, 1]. - bounding_poly (~.geometry.BoundingPoly): + bounding_poly (google.cloud.vision_v1p3beta1.types.BoundingPoly): Image region to which this entity belongs. Not produced for ``LABEL_DETECTION`` features. - locations (Sequence[~.image_annotator.LocationInfo]): + locations (Sequence[google.cloud.vision_v1p3beta1.types.LocationInfo]): The location information for the detected entity. Multiple ``LocationInfo`` elements can be present because one location may indicate the location of the scene in the image, and another location may indicate the location of the place where the image was taken. Location information is usually present for landmarks. - properties (Sequence[~.image_annotator.Property]): + properties (Sequence[google.cloud.vision_v1p3beta1.types.Property]): Some entities may have optional user-supplied ``Property`` (name/value) fields, such a score or string that qualifies the entity. @@ -438,7 +438,7 @@ class LocalizedObjectAnnotation(proto.Message): Object name, expressed in its ``language_code`` language. score (float): Score of the result. Range [0, 1]. - bounding_poly (~.geometry.BoundingPoly): + bounding_poly (google.cloud.vision_v1p3beta1.types.BoundingPoly): Image region to which this object belongs. This must be populated. """ @@ -460,21 +460,21 @@ class SafeSearchAnnotation(proto.Message): spoof, medical, violence). Attributes: - adult (~.image_annotator.Likelihood): + adult (google.cloud.vision_v1p3beta1.types.Likelihood): Represents the adult content likelihood for the image. Adult content may contain elements such as nudity, pornographic images or cartoons, or sexual activities. - spoof (~.image_annotator.Likelihood): + spoof (google.cloud.vision_v1p3beta1.types.Likelihood): Spoof likelihood. The likelihood that an modification was made to the image's canonical version to make it appear funny or offensive. - medical (~.image_annotator.Likelihood): + medical (google.cloud.vision_v1p3beta1.types.Likelihood): Likelihood that this is a medical image. - violence (~.image_annotator.Likelihood): + violence (google.cloud.vision_v1p3beta1.types.Likelihood): Likelihood that this image contains violent content. - racy (~.image_annotator.Likelihood): + racy (google.cloud.vision_v1p3beta1.types.Likelihood): Likelihood that the request image contains racy content. Racy content may include (but is not limited to) skimpy or sheer clothing, @@ -498,9 +498,9 @@ class LatLongRect(proto.Message): r"""Rectangle determined by min and max ``LatLng`` pairs. Attributes: - min_lat_lng (~.latlng.LatLng): + min_lat_lng (google.type.latlng_pb2.LatLng): Min lat/long pair. - max_lat_lng (~.latlng.LatLng): + max_lat_lng (google.type.latlng_pb2.LatLng): Max lat/long pair. """ @@ -514,7 +514,7 @@ class ColorInfo(proto.Message): fraction of the image that the color occupies in the image. Attributes: - color (~.gt_color.Color): + color (google.type.color_pb2.Color): RGB components of the color. score (float): Image-specific score for this color. Value in range [0, 1]. @@ -534,7 +534,7 @@ class DominantColorsAnnotation(proto.Message): r"""Set of dominant colors and their corresponding scores. Attributes: - colors (Sequence[~.image_annotator.ColorInfo]): + colors (Sequence[google.cloud.vision_v1p3beta1.types.ColorInfo]): RGB color values with their score and pixel fraction. """ @@ -546,7 +546,7 @@ class ImageProperties(proto.Message): r"""Stores image properties, such as dominant colors. Attributes: - dominant_colors (~.image_annotator.DominantColorsAnnotation): + dominant_colors (google.cloud.vision_v1p3beta1.types.DominantColorsAnnotation): If present, dominant colors completed successfully. """ @@ -561,7 +561,7 @@ class CropHint(proto.Message): serving an image. Attributes: - bounding_poly (~.geometry.BoundingPoly): + bounding_poly (google.cloud.vision_v1p3beta1.types.BoundingPoly): The bounding polygon for the crop region. The coordinates of the bounding box are in the original image's scale, as returned in ``ImageParams``. @@ -584,7 +584,7 @@ class CropHintsAnnotation(proto.Message): serving images. Attributes: - crop_hints (Sequence[~.image_annotator.CropHint]): + crop_hints (Sequence[google.cloud.vision_v1p3beta1.types.CropHint]): Crop hint results. """ @@ -639,7 +639,7 @@ class ImageContext(proto.Message): r"""Image context and/or feature-specific parameters. Attributes: - lat_long_rect (~.image_annotator.LatLongRect): + lat_long_rect (google.cloud.vision_v1p3beta1.types.LatLongRect): Not used. language_hints (Sequence[str]): List of languages to use for TEXT_DETECTION. In most cases, @@ -652,13 +652,13 @@ class ImageContext(proto.Message): Text detection returns an error if one or more of the specified languages is not one of the `supported languages `__. - crop_hints_params (~.image_annotator.CropHintsParams): + crop_hints_params (google.cloud.vision_v1p3beta1.types.CropHintsParams): Parameters for crop hints annotation request. - product_search_params (~.product_search.ProductSearchParams): + product_search_params (google.cloud.vision_v1p3beta1.types.ProductSearchParams): Parameters for product search. - web_detection_params (~.image_annotator.WebDetectionParams): + web_detection_params (google.cloud.vision_v1p3beta1.types.WebDetectionParams): Parameters for web detection. - text_detection_params (~.image_annotator.TextDetectionParams): + text_detection_params (google.cloud.vision_v1p3beta1.types.TextDetectionParams): Parameters for text detection and document text detection. """ @@ -687,11 +687,11 @@ class AnnotateImageRequest(proto.Message): user-provided image, with user-requested features. Attributes: - image (~.image_annotator.Image): + image (google.cloud.vision_v1p3beta1.types.Image): The image to be processed. - features (Sequence[~.image_annotator.Feature]): + features (Sequence[google.cloud.vision_v1p3beta1.types.Feature]): Requested features. - image_context (~.image_annotator.ImageContext): + image_context (google.cloud.vision_v1p3beta1.types.ImageContext): Additional context that may accompany the image. """ @@ -726,50 +726,50 @@ class AnnotateImageResponse(proto.Message): r"""Response to an image annotation request. Attributes: - face_annotations (Sequence[~.image_annotator.FaceAnnotation]): + face_annotations (Sequence[google.cloud.vision_v1p3beta1.types.FaceAnnotation]): If present, face detection has completed successfully. - landmark_annotations (Sequence[~.image_annotator.EntityAnnotation]): + landmark_annotations (Sequence[google.cloud.vision_v1p3beta1.types.EntityAnnotation]): If present, landmark detection has completed successfully. - logo_annotations (Sequence[~.image_annotator.EntityAnnotation]): + logo_annotations (Sequence[google.cloud.vision_v1p3beta1.types.EntityAnnotation]): If present, logo detection has completed successfully. - label_annotations (Sequence[~.image_annotator.EntityAnnotation]): + label_annotations (Sequence[google.cloud.vision_v1p3beta1.types.EntityAnnotation]): If present, label detection has completed successfully. - localized_object_annotations (Sequence[~.image_annotator.LocalizedObjectAnnotation]): + localized_object_annotations (Sequence[google.cloud.vision_v1p3beta1.types.LocalizedObjectAnnotation]): If present, localized object detection has completed successfully. This will be sorted descending by confidence score. - text_annotations (Sequence[~.image_annotator.EntityAnnotation]): + text_annotations (Sequence[google.cloud.vision_v1p3beta1.types.EntityAnnotation]): If present, text (OCR) detection has completed successfully. - full_text_annotation (~.text_annotation.TextAnnotation): + full_text_annotation (google.cloud.vision_v1p3beta1.types.TextAnnotation): If present, text (OCR) detection or document (OCR) text detection has completed successfully. This annotation provides the structural hierarchy for the OCR detected text. - safe_search_annotation (~.image_annotator.SafeSearchAnnotation): + safe_search_annotation (google.cloud.vision_v1p3beta1.types.SafeSearchAnnotation): If present, safe-search annotation has completed successfully. - image_properties_annotation (~.image_annotator.ImageProperties): + image_properties_annotation (google.cloud.vision_v1p3beta1.types.ImageProperties): If present, image properties were extracted successfully. - crop_hints_annotation (~.image_annotator.CropHintsAnnotation): + crop_hints_annotation (google.cloud.vision_v1p3beta1.types.CropHintsAnnotation): If present, crop hints have completed successfully. - web_detection (~.gcv_web_detection.WebDetection): + web_detection (google.cloud.vision_v1p3beta1.types.WebDetection): If present, web detection has completed successfully. - product_search_results (~.product_search.ProductSearchResults): + product_search_results (google.cloud.vision_v1p3beta1.types.ProductSearchResults): If present, product search has completed successfully. - error (~.status.Status): + error (google.rpc.status_pb2.Status): If set, represents the error message for the operation. Note that filled-in image annotations are guaranteed to be correct, even when ``error`` is set. - context (~.image_annotator.ImageAnnotationContext): + context (google.cloud.vision_v1p3beta1.types.ImageAnnotationContext): If present, contextual information is needed to understand where this image comes from. """ @@ -833,10 +833,10 @@ class AnnotateFileResponse(proto.Message): responses. Attributes: - input_config (~.image_annotator.InputConfig): + input_config (google.cloud.vision_v1p3beta1.types.InputConfig): Information about the file for which this response is generated. - responses (Sequence[~.image_annotator.AnnotateImageResponse]): + responses (Sequence[google.cloud.vision_v1p3beta1.types.AnnotateImageResponse]): Individual responses to images found within the file. """ @@ -853,7 +853,7 @@ class BatchAnnotateImagesRequest(proto.Message): service call. Attributes: - requests (Sequence[~.image_annotator.AnnotateImageRequest]): + requests (Sequence[google.cloud.vision_v1p3beta1.types.AnnotateImageRequest]): Individual image annotation requests for this batch. """ @@ -867,7 +867,7 @@ class BatchAnnotateImagesResponse(proto.Message): r"""Response to a batch image annotation request. Attributes: - responses (Sequence[~.image_annotator.AnnotateImageResponse]): + responses (Sequence[google.cloud.vision_v1p3beta1.types.AnnotateImageResponse]): Individual responses to image annotation requests within the batch. """ @@ -881,14 +881,14 @@ class AsyncAnnotateFileRequest(proto.Message): r"""An offline file annotation request. Attributes: - input_config (~.image_annotator.InputConfig): + input_config (google.cloud.vision_v1p3beta1.types.InputConfig): Required. Information about the input file. - features (Sequence[~.image_annotator.Feature]): + features (Sequence[google.cloud.vision_v1p3beta1.types.Feature]): Required. Requested features. - image_context (~.image_annotator.ImageContext): + image_context (google.cloud.vision_v1p3beta1.types.ImageContext): Additional context that may accompany the image(s) in the file. - output_config (~.image_annotator.OutputConfig): + output_config (google.cloud.vision_v1p3beta1.types.OutputConfig): Required. The desired output location and metadata (e.g. format). """ @@ -906,7 +906,7 @@ class AsyncAnnotateFileResponse(proto.Message): r"""The response for a single offline file annotation request. Attributes: - output_config (~.image_annotator.OutputConfig): + output_config (google.cloud.vision_v1p3beta1.types.OutputConfig): The output location and metadata from AsyncAnnotateFileRequest. """ @@ -919,7 +919,7 @@ class AsyncBatchAnnotateFilesRequest(proto.Message): single service call. Attributes: - requests (Sequence[~.image_annotator.AsyncAnnotateFileRequest]): + requests (Sequence[google.cloud.vision_v1p3beta1.types.AsyncAnnotateFileRequest]): Required. Individual async file annotation requests for this batch. """ @@ -933,7 +933,7 @@ class AsyncBatchAnnotateFilesResponse(proto.Message): r"""Response to an async batch file annotation request. Attributes: - responses (Sequence[~.image_annotator.AsyncAnnotateFileResponse]): + responses (Sequence[google.cloud.vision_v1p3beta1.types.AsyncAnnotateFileResponse]): The list of file annotation responses, one for each request in AsyncBatchAnnotateFilesRequest. @@ -948,7 +948,7 @@ class InputConfig(proto.Message): r"""The desired input location and metadata. Attributes: - gcs_source (~.image_annotator.GcsSource): + gcs_source (google.cloud.vision_v1p3beta1.types.GcsSource): The Google Cloud Storage location to read the input from. mime_type (str): @@ -966,7 +966,7 @@ class OutputConfig(proto.Message): r"""The desired output location and metadata. Attributes: - gcs_destination (~.image_annotator.GcsDestination): + gcs_destination (google.cloud.vision_v1p3beta1.types.GcsDestination): The Google Cloud Storage location to write the output(s) to. batch_size (int): @@ -1034,11 +1034,11 @@ class OperationMetadata(proto.Message): r"""Contains metadata for the BatchAnnotateImages operation. Attributes: - state (~.image_annotator.OperationMetadata.State): + state (google.cloud.vision_v1p3beta1.types.OperationMetadata.State): Current state of the batch operation. - create_time (~.timestamp.Timestamp): + create_time (google.protobuf.timestamp_pb2.Timestamp): The time when the batch request was received. - update_time (~.timestamp.Timestamp): + update_time (google.protobuf.timestamp_pb2.Timestamp): The time when the operation result was last updated. """ diff --git a/google/cloud/vision_v1p3beta1/types/product_search.py b/google/cloud/vision_v1p3beta1/types/product_search.py index 375bd701..43cb9f3a 100644 --- a/google/cloud/vision_v1p3beta1/types/product_search.py +++ b/google/cloud/vision_v1p3beta1/types/product_search.py @@ -55,7 +55,7 @@ class ProductSearchParams(proto.Message): The resource name of the catalog to search. Format is: ``productSearch/catalogs/CATALOG_NAME``. - category (~.product_search.ProductSearchCategory): + category (google.cloud.vision_v1p3beta1.types.ProductSearchCategory): The category to search in. Optional. It is inferred by the system if it is not specified. [Deprecated] Use ``product_category``. @@ -64,15 +64,15 @@ class ProductSearchParams(proto.Message): by the system if it is not specified. Supported values are ``bag``, ``shoe``, ``sunglasses``, ``dress``, ``outerwear``, ``skirt``, ``top``, ``shorts``, and ``pants``. - normalized_bounding_poly (~.geometry.NormalizedBoundingPoly): + normalized_bounding_poly (google.cloud.vision_v1p3beta1.types.NormalizedBoundingPoly): The bounding polygon around the area of interest in the image. Optional. If it is not specified, system discretion will be applied. [Deprecated] Use ``bounding_poly``. - bounding_poly (~.geometry.BoundingPoly): + bounding_poly (google.cloud.vision_v1p3beta1.types.BoundingPoly): The bounding polygon around the area of interest in the image. Optional. If it is not specified, system discretion will be applied. - view (~.product_search.ProductSearchResultsView): + view (google.cloud.vision_v1p3beta1.types.ProductSearchResultsView): Specifies the verbosity of the product search results. Optional. Defaults to ``BASIC``. product_set (str): @@ -123,19 +123,19 @@ class ProductSearchResults(proto.Message): r"""Results for a product search request. Attributes: - category (~.product_search.ProductSearchCategory): + category (google.cloud.vision_v1p3beta1.types.ProductSearchCategory): Product category. [Deprecated] Use ``product_category``. product_category (str): Product category. Supported values are ``bag`` and ``shoe``. [Deprecated] ``product_category`` is provided in each Product. - index_time (~.timestamp.Timestamp): + index_time (google.protobuf.timestamp_pb2.Timestamp): Timestamp of the index which provided these results. Changes made after this time are not reflected in the current results. - products (Sequence[~.product_search.ProductSearchResults.ProductInfo]): + products (Sequence[google.cloud.vision_v1p3beta1.types.ProductSearchResults.ProductInfo]): List of detected products. - results (Sequence[~.product_search.ProductSearchResults.Result]): + results (Sequence[google.cloud.vision_v1p3beta1.types.ProductSearchResults.Result]): List of results, one for each product match. """ @@ -168,7 +168,7 @@ class Result(proto.Message): r"""Information about a product. Attributes: - product (~.product_search_service.Product): + product (google.cloud.vision_v1p3beta1.types.Product): The Product. score (float): A confidence level on the match, ranging from 0 (no diff --git a/google/cloud/vision_v1p3beta1/types/product_search_service.py b/google/cloud/vision_v1p3beta1/types/product_search_service.py index 1f13e1ba..aef592b7 100644 --- a/google/cloud/vision_v1p3beta1/types/product_search_service.py +++ b/google/cloud/vision_v1p3beta1/types/product_search_service.py @@ -85,7 +85,7 @@ class Product(proto.Message): "toys-v2". The legacy categories "homegoods", "apparel", and "toys" are still supported, but these should not be used for new products. - product_labels (Sequence[~.product_search_service.Product.KeyValue]): + product_labels (Sequence[google.cloud.vision_v1p3beta1.types.Product.KeyValue]): Key-value pairs that can be attached to a product. At query time, constraints can be specified based on the product_labels. @@ -143,7 +143,7 @@ class ProductSet(proto.Message): The user-provided name for this ProductSet. Must not be empty. Must be at most 4096 characters long. - index_time (~.timestamp.Timestamp): + index_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The time at which this ProductSet was last indexed. Query results will reflect all updates before this time. If this @@ -152,7 +152,7 @@ class ProductSet(proto.Message): This field is ignored when creating a ProductSet. - index_error (~.status.Status): + index_error (google.rpc.status_pb2.Status): Output only. If there was an error with indexing the product set, the field is populated. @@ -187,7 +187,7 @@ class ReferenceImage(proto.Message): image. The URI must start with ``gs://``. - bounding_polys (Sequence[~.geometry.BoundingPoly]): + bounding_polys (Sequence[google.cloud.vision_v1p3beta1.types.BoundingPoly]): Optional. Bounding polygons around the areas of interest in the reference image. If this field is empty, the system will try to detect @@ -218,7 +218,7 @@ class CreateProductRequest(proto.Message): created. Format is ``projects/PROJECT_ID/locations/LOC_ID``. - product (~.product_search_service.Product): + product (google.cloud.vision_v1p3beta1.types.Product): Required. The product to create. product_id (str): A user-supplied resource id for this Product. If set, the @@ -263,7 +263,7 @@ class ListProductsResponse(proto.Message): r"""Response message for the ``ListProducts`` method. Attributes: - products (Sequence[~.product_search_service.Product]): + products (Sequence[google.cloud.vision_v1p3beta1.types.Product]): List of products. next_page_token (str): Token to retrieve the next page of results, @@ -298,11 +298,11 @@ class UpdateProductRequest(proto.Message): r"""Request message for the ``UpdateProduct`` method. Attributes: - product (~.product_search_service.Product): + product (google.cloud.vision_v1p3beta1.types.Product): Required. The Product resource which replaces the one on the server. product.name is immutable. - update_mask (~.field_mask.FieldMask): + update_mask (google.protobuf.field_mask_pb2.FieldMask): The [FieldMask][google.protobuf.FieldMask] that specifies which fields to update. If update_mask isn't specified, all mutable fields are to be updated. Valid mask paths include @@ -337,7 +337,7 @@ class CreateProductSetRequest(proto.Message): created. Format is ``projects/PROJECT_ID/locations/LOC_ID``. - product_set (~.product_search_service.ProductSet): + product_set (google.cloud.vision_v1p3beta1.types.ProductSet): Required. The ProductSet to create. product_set_id (str): A user-supplied resource id for this ProductSet. If set, the @@ -382,7 +382,7 @@ class ListProductSetsResponse(proto.Message): r"""Response message for the ``ListProductSets`` method. Attributes: - product_sets (Sequence[~.product_search_service.ProductSet]): + product_sets (Sequence[google.cloud.vision_v1p3beta1.types.ProductSet]): List of ProductSets. next_page_token (str): Token to retrieve the next page of results, @@ -417,10 +417,10 @@ class UpdateProductSetRequest(proto.Message): r"""Request message for the ``UpdateProductSet`` method. Attributes: - product_set (~.product_search_service.ProductSet): + product_set (google.cloud.vision_v1p3beta1.types.ProductSet): Required. The ProductSet resource which replaces the one on the server. - update_mask (~.field_mask.FieldMask): + update_mask (google.protobuf.field_mask_pb2.FieldMask): The [FieldMask][google.protobuf.FieldMask] that specifies which fields to update. If update_mask isn't specified, all mutable fields are to be updated. Valid mask path is @@ -456,7 +456,7 @@ class CreateReferenceImageRequest(proto.Message): Format is ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. - reference_image (~.product_search_service.ReferenceImage): + reference_image (google.cloud.vision_v1p3beta1.types.ReferenceImage): Required. The reference image to create. If an image ID is specified, it is ignored. reference_image_id (str): @@ -506,7 +506,7 @@ class ListReferenceImagesResponse(proto.Message): r"""Response message for the ``ListReferenceImages`` method. Attributes: - reference_images (Sequence[~.product_search_service.ReferenceImage]): + reference_images (Sequence[google.cloud.vision_v1p3beta1.types.ReferenceImage]): The list of reference images. page_size (int): The maximum number of items to return. @@ -633,7 +633,7 @@ class ListProductsInProductSetResponse(proto.Message): r"""Response message for the ``ListProductsInProductSet`` method. Attributes: - products (Sequence[~.product_search_service.Product]): + products (Sequence[google.cloud.vision_v1p3beta1.types.Product]): The list of Products. next_page_token (str): Token to retrieve the next page of results, @@ -725,7 +725,7 @@ class ImportProductSetsInputConfig(proto.Message): r"""The input content for the ``ImportProductSets`` method. Attributes: - gcs_source (~.product_search_service.ImportProductSetsGcsSource): + gcs_source (google.cloud.vision_v1p3beta1.types.ImportProductSetsGcsSource): The Google Cloud Storage location for a csv file which preserves a list of ImportProductSetRequests in each line. @@ -745,7 +745,7 @@ class ImportProductSetsRequest(proto.Message): imported. Format is ``projects/PROJECT_ID/locations/LOC_ID``. - input_config (~.product_search_service.ImportProductSetsInputConfig): + input_config (google.cloud.vision_v1p3beta1.types.ImportProductSetsInputConfig): Required. The input content for the list of requests. """ @@ -767,9 +767,9 @@ class ImportProductSetsResponse(proto.Message): field. Attributes: - reference_images (Sequence[~.product_search_service.ReferenceImage]): + reference_images (Sequence[google.cloud.vision_v1p3beta1.types.ReferenceImage]): The list of reference_images that are imported successfully. - statuses (Sequence[~.status.Status]): + statuses (Sequence[google.rpc.status_pb2.Status]): The rpc status for each ImportProductSet request, including both successes and errors. @@ -794,12 +794,12 @@ class BatchOperationMetadata(proto.Message): ``google::longrunning::Operations`` service. Attributes: - state (~.product_search_service.BatchOperationMetadata.State): + state (google.cloud.vision_v1p3beta1.types.BatchOperationMetadata.State): The current state of the batch operation. - submit_time (~.timestamp.Timestamp): + submit_time (google.protobuf.timestamp_pb2.Timestamp): The time when the batch request was submitted to the server. - end_time (~.timestamp.Timestamp): + end_time (google.protobuf.timestamp_pb2.Timestamp): The time when the batch request is finished and [google.longrunning.Operation.done][google.longrunning.Operation.done] is set to true. diff --git a/google/cloud/vision_v1p3beta1/types/text_annotation.py b/google/cloud/vision_v1p3beta1/types/text_annotation.py index e1252879..47423028 100644 --- a/google/cloud/vision_v1p3beta1/types/text_annotation.py +++ b/google/cloud/vision_v1p3beta1/types/text_annotation.py @@ -38,7 +38,7 @@ class TextAnnotation(proto.Message): message definition below for more detail. Attributes: - pages (Sequence[~.text_annotation.Page]): + pages (Sequence[google.cloud.vision_v1p3beta1.types.Page]): List of pages detected by OCR. text (str): UTF-8 text detected on the pages. @@ -64,7 +64,7 @@ class DetectedBreak(proto.Message): r"""Detected start or end of a structural component. Attributes: - type_ (~.text_annotation.TextAnnotation.DetectedBreak.BreakType): + type_ (google.cloud.vision_v1p3beta1.types.TextAnnotation.DetectedBreak.BreakType): Detected break type. is_prefix (bool): True if break prepends the element. @@ -89,10 +89,10 @@ class TextProperty(proto.Message): r"""Additional information detected on the structural component. Attributes: - detected_languages (Sequence[~.text_annotation.TextAnnotation.DetectedLanguage]): + detected_languages (Sequence[google.cloud.vision_v1p3beta1.types.TextAnnotation.DetectedLanguage]): A list of detected languages together with confidence. - detected_break (~.text_annotation.TextAnnotation.DetectedBreak): + detected_break (google.cloud.vision_v1p3beta1.types.TextAnnotation.DetectedBreak): Detected start or end of a text segment. """ @@ -113,7 +113,7 @@ class Page(proto.Message): r"""Detected page from OCR. Attributes: - property (~.text_annotation.TextAnnotation.TextProperty): + property (google.cloud.vision_v1p3beta1.types.TextAnnotation.TextProperty): Additional information detected on the page. width (int): Page width. For PDFs the unit is points. For @@ -121,7 +121,7 @@ class Page(proto.Message): height (int): Page height. For PDFs the unit is points. For images (including TIFFs) the unit is pixels. - blocks (Sequence[~.text_annotation.Block]): + blocks (Sequence[google.cloud.vision_v1p3beta1.types.Block]): List of blocks of text, images etc on this page. confidence (float): @@ -145,10 +145,10 @@ class Block(proto.Message): r"""Logical element on the page. Attributes: - property (~.text_annotation.TextAnnotation.TextProperty): + property (google.cloud.vision_v1p3beta1.types.TextAnnotation.TextProperty): Additional information detected for the block. - bounding_box (~.geometry.BoundingPoly): + bounding_box (google.cloud.vision_v1p3beta1.types.BoundingPoly): The bounding box for the block. The vertices are in the order of top-left, top-right, bottom-right, bottom-left. When a rotation of the bounding box is detected the rotation @@ -173,10 +173,10 @@ class Block(proto.Message): 1----0 and the vertice order will still be (0, 1, 2, 3). - paragraphs (Sequence[~.text_annotation.Paragraph]): + paragraphs (Sequence[google.cloud.vision_v1p3beta1.types.Paragraph]): List of paragraphs in this block (if this blocks is of type text). - block_type (~.text_annotation.Block.BlockType): + block_type (google.cloud.vision_v1p3beta1.types.Block.BlockType): Detected block type (text, image etc) for this block. confidence (float): @@ -210,10 +210,10 @@ class Paragraph(proto.Message): certain order. Attributes: - property (~.text_annotation.TextAnnotation.TextProperty): + property (google.cloud.vision_v1p3beta1.types.TextAnnotation.TextProperty): Additional information detected for the paragraph. - bounding_box (~.geometry.BoundingPoly): + bounding_box (google.cloud.vision_v1p3beta1.types.BoundingPoly): The bounding box for the paragraph. The vertices are in the order of top-left, top-right, bottom-right, bottom-left. When a rotation of the bounding box is detected the rotation @@ -225,7 +225,7 @@ class Paragraph(proto.Message): - when it's rotated 180 degrees around the top-left corner it becomes: 2----3 \| \| 1----0 and the vertice order will still be (0, 1, 2, 3). - words (Sequence[~.text_annotation.Word]): + words (Sequence[google.cloud.vision_v1p3beta1.types.Word]): List of words in this paragraph. confidence (float): Confidence of the OCR results for the paragraph. Range [0, @@ -247,9 +247,9 @@ class Word(proto.Message): r"""A word representation. Attributes: - property (~.text_annotation.TextAnnotation.TextProperty): + property (google.cloud.vision_v1p3beta1.types.TextAnnotation.TextProperty): Additional information detected for the word. - bounding_box (~.geometry.BoundingPoly): + bounding_box (google.cloud.vision_v1p3beta1.types.BoundingPoly): The bounding box for the word. The vertices are in the order of top-left, top-right, bottom-right, bottom-left. When a rotation of the bounding box is detected the rotation is @@ -261,7 +261,7 @@ class Word(proto.Message): - when it's rotated 180 degrees around the top-left corner it becomes: 2----3 \| \| 1----0 and the vertice order will still be (0, 1, 2, 3). - symbols (Sequence[~.text_annotation.Symbol]): + symbols (Sequence[google.cloud.vision_v1p3beta1.types.Symbol]): List of symbols in the word. The order of the symbols follows the natural reading order. @@ -284,10 +284,10 @@ class Symbol(proto.Message): r"""A single symbol representation. Attributes: - property (~.text_annotation.TextAnnotation.TextProperty): + property (google.cloud.vision_v1p3beta1.types.TextAnnotation.TextProperty): Additional information detected for the symbol. - bounding_box (~.geometry.BoundingPoly): + bounding_box (google.cloud.vision_v1p3beta1.types.BoundingPoly): The bounding box for the symbol. The vertices are in the order of top-left, top-right, bottom-right, bottom-left. When a rotation of the bounding box is detected the rotation diff --git a/google/cloud/vision_v1p3beta1/types/web_detection.py b/google/cloud/vision_v1p3beta1/types/web_detection.py index 6a24d5c2..66587d99 100644 --- a/google/cloud/vision_v1p3beta1/types/web_detection.py +++ b/google/cloud/vision_v1p3beta1/types/web_detection.py @@ -27,24 +27,24 @@ class WebDetection(proto.Message): r"""Relevant information for the image from the Internet. Attributes: - web_entities (Sequence[~.web_detection.WebDetection.WebEntity]): + web_entities (Sequence[google.cloud.vision_v1p3beta1.types.WebDetection.WebEntity]): Deduced entities from similar images on the Internet. - full_matching_images (Sequence[~.web_detection.WebDetection.WebImage]): + full_matching_images (Sequence[google.cloud.vision_v1p3beta1.types.WebDetection.WebImage]): Fully matching images from the Internet. Can include resized copies of the query image. - partial_matching_images (Sequence[~.web_detection.WebDetection.WebImage]): + partial_matching_images (Sequence[google.cloud.vision_v1p3beta1.types.WebDetection.WebImage]): Partial matching images from the Internet. Those images are similar enough to share some key-point features. For example an original image will likely have partial matching for its crops. - pages_with_matching_images (Sequence[~.web_detection.WebDetection.WebPage]): + pages_with_matching_images (Sequence[google.cloud.vision_v1p3beta1.types.WebDetection.WebPage]): Web pages containing the matching images from the Internet. - visually_similar_images (Sequence[~.web_detection.WebDetection.WebImage]): + visually_similar_images (Sequence[google.cloud.vision_v1p3beta1.types.WebDetection.WebImage]): The visually similar image results. - best_guess_labels (Sequence[~.web_detection.WebDetection.WebLabel]): + best_guess_labels (Sequence[google.cloud.vision_v1p3beta1.types.WebDetection.WebLabel]): Best guess text labels for the request image. """ @@ -96,10 +96,10 @@ class WebPage(proto.Message): page_title (str): Title for the web page, may contain HTML markups. - full_matching_images (Sequence[~.web_detection.WebDetection.WebImage]): + full_matching_images (Sequence[google.cloud.vision_v1p3beta1.types.WebDetection.WebImage]): Fully matching images on the page. Can include resized copies of the query image. - partial_matching_images (Sequence[~.web_detection.WebDetection.WebImage]): + partial_matching_images (Sequence[google.cloud.vision_v1p3beta1.types.WebDetection.WebImage]): Partial matching images on the page. Those images are similar enough to share some key-point features. For example an original diff --git a/google/cloud/vision_v1p4beta1/services/image_annotator/async_client.py b/google/cloud/vision_v1p4beta1/services/image_annotator/async_client.py index 581f63bd..1a9f75e6 100644 --- a/google/cloud/vision_v1p4beta1/services/image_annotator/async_client.py +++ b/google/cloud/vision_v1p4beta1/services/image_annotator/async_client.py @@ -83,6 +83,7 @@ class ImageAnnotatorAsyncClient: ImageAnnotatorClient.parse_common_location_path ) + from_service_account_info = ImageAnnotatorClient.from_service_account_info from_service_account_file = ImageAnnotatorClient.from_service_account_file from_service_account_json = from_service_account_file @@ -160,12 +161,13 @@ async def batch_annotate_images( images. Args: - request (:class:`~.image_annotator.BatchAnnotateImagesRequest`): + request (:class:`google.cloud.vision_v1p4beta1.types.BatchAnnotateImagesRequest`): The request object. Multiple image annotation requests are batched into a single service call. - requests (:class:`Sequence[~.image_annotator.AnnotateImageRequest]`): + requests (:class:`Sequence[google.cloud.vision_v1p4beta1.types.AnnotateImageRequest]`): Required. Individual image annotation requests for this batch. + This corresponds to the ``requests`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -177,7 +179,7 @@ async def batch_annotate_images( sent along with the request as metadata. Returns: - ~.image_annotator.BatchAnnotateImagesResponse: + google.cloud.vision_v1p4beta1.types.BatchAnnotateImagesResponse: Response to a batch image annotation request. @@ -239,14 +241,15 @@ async def batch_annotate_files( extracted. Args: - request (:class:`~.image_annotator.BatchAnnotateFilesRequest`): + request (:class:`google.cloud.vision_v1p4beta1.types.BatchAnnotateFilesRequest`): The request object. A list of requests to annotate files using the BatchAnnotateFiles API. - requests (:class:`Sequence[~.image_annotator.AnnotateFileRequest]`): + requests (:class:`Sequence[google.cloud.vision_v1p4beta1.types.AnnotateFileRequest]`): Required. The list of file annotation requests. Right now we support only one AnnotateFileRequest in BatchAnnotateFilesRequest. + This corresponds to the ``requests`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -258,7 +261,7 @@ async def batch_annotate_files( sent along with the request as metadata. Returns: - ~.image_annotator.BatchAnnotateFilesResponse: + google.cloud.vision_v1p4beta1.types.BatchAnnotateFilesResponse: A list of file annotation responses. """ # Create or coerce a protobuf request object. @@ -323,18 +326,20 @@ async def async_batch_annotate_images( BatchAnnotateImagesResponse proto. Args: - request (:class:`~.image_annotator.AsyncBatchAnnotateImagesRequest`): + request (:class:`google.cloud.vision_v1p4beta1.types.AsyncBatchAnnotateImagesRequest`): The request object. Request for async image annotation for a list of images. - requests (:class:`Sequence[~.image_annotator.AnnotateImageRequest]`): + requests (:class:`Sequence[google.cloud.vision_v1p4beta1.types.AnnotateImageRequest]`): Required. Individual image annotation requests for this batch. + This corresponds to the ``requests`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - output_config (:class:`~.image_annotator.OutputConfig`): + output_config (:class:`google.cloud.vision_v1p4beta1.types.OutputConfig`): Required. The desired output location and metadata (e.g. format). + This corresponds to the ``output_config`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -346,11 +351,11 @@ async def async_batch_annotate_images( sent along with the request as metadata. Returns: - ~.operation_async.AsyncOperation: + google.api_core.operation_async.AsyncOperation: An object representing a long-running operation. The result type for the operation will be - :class:``~.image_annotator.AsyncBatchAnnotateImagesResponse``: + :class:`google.cloud.vision_v1p4beta1.types.AsyncBatchAnnotateImagesResponse` Response to an async batch image annotation request. """ @@ -421,12 +426,13 @@ async def async_batch_annotate_files( ``AsyncBatchAnnotateFilesResponse`` (results). Args: - request (:class:`~.image_annotator.AsyncBatchAnnotateFilesRequest`): + request (:class:`google.cloud.vision_v1p4beta1.types.AsyncBatchAnnotateFilesRequest`): The request object. Multiple async file annotation requests are batched into a single service call. - requests (:class:`Sequence[~.image_annotator.AsyncAnnotateFileRequest]`): + requests (:class:`Sequence[google.cloud.vision_v1p4beta1.types.AsyncAnnotateFileRequest]`): Required. Individual async file annotation requests for this batch. + This corresponds to the ``requests`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -438,11 +444,11 @@ async def async_batch_annotate_files( sent along with the request as metadata. Returns: - ~.operation_async.AsyncOperation: + google.api_core.operation_async.AsyncOperation: An object representing a long-running operation. The result type for the operation will be - :class:``~.image_annotator.AsyncBatchAnnotateFilesResponse``: + :class:`google.cloud.vision_v1p4beta1.types.AsyncBatchAnnotateFilesResponse` Response to an async batch file annotation request. """ diff --git a/google/cloud/vision_v1p4beta1/services/image_annotator/client.py b/google/cloud/vision_v1p4beta1/services/image_annotator/client.py index 160e68ef..340a462f 100644 --- a/google/cloud/vision_v1p4beta1/services/image_annotator/client.py +++ b/google/cloud/vision_v1p4beta1/services/image_annotator/client.py @@ -115,6 +115,22 @@ def _get_default_mtls_endpoint(api_endpoint): DEFAULT_ENDPOINT ) + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + ImageAnnotatorClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_info(info) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials @@ -127,7 +143,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): kwargs: Additional arguments to pass to the constructor. Returns: - {@api.name}: The constructed client. + ImageAnnotatorClient: The constructed client. """ credentials = service_account.Credentials.from_service_account_file(filename) kwargs["credentials"] = credentials @@ -251,10 +267,10 @@ def __init__( credentials identify the application to the service; if none are specified, the client will attempt to ascertain the credentials from the environment. - transport (Union[str, ~.ImageAnnotatorTransport]): The + transport (Union[str, ImageAnnotatorTransport]): The transport to use. If set to None, a transport is chosen automatically. - client_options (client_options_lib.ClientOptions): Custom options for the + client_options (google.api_core.client_options.ClientOptions): Custom options for the client. It won't take effect if a ``transport`` instance is provided. (1) The ``api_endpoint`` property can be used to override the default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT @@ -290,21 +306,17 @@ def __init__( util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")) ) - ssl_credentials = None + client_cert_source_func = None is_mtls = False if use_client_cert: if client_options.client_cert_source: - import grpc # type: ignore - - cert, key = client_options.client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) is_mtls = True + client_cert_source_func = client_options.client_cert_source else: - creds = SslCredentials() - is_mtls = creds.is_mtls - ssl_credentials = creds.ssl_credentials if is_mtls else None + is_mtls = mtls.has_default_client_cert_source() + client_cert_source_func = ( + mtls.default_client_cert_source() if is_mtls else None + ) # Figure out which api endpoint to use. if client_options.api_endpoint is not None: @@ -347,7 +359,7 @@ def __init__( credentials_file=client_options.credentials_file, host=api_endpoint, scopes=client_options.scopes, - ssl_channel_credentials=ssl_credentials, + client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, ) @@ -365,12 +377,13 @@ def batch_annotate_images( images. Args: - request (:class:`~.image_annotator.BatchAnnotateImagesRequest`): + request (google.cloud.vision_v1p4beta1.types.BatchAnnotateImagesRequest): The request object. Multiple image annotation requests are batched into a single service call. - requests (:class:`Sequence[~.image_annotator.AnnotateImageRequest]`): + requests (Sequence[google.cloud.vision_v1p4beta1.types.AnnotateImageRequest]): Required. Individual image annotation requests for this batch. + This corresponds to the ``requests`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -382,7 +395,7 @@ def batch_annotate_images( sent along with the request as metadata. Returns: - ~.image_annotator.BatchAnnotateImagesResponse: + google.cloud.vision_v1p4beta1.types.BatchAnnotateImagesResponse: Response to a batch image annotation request. @@ -410,8 +423,8 @@ def batch_annotate_images( # If we have keyword arguments corresponding to fields on the # request, apply these. - if requests: - request.requests.extend(requests) + if requests is not None: + request.requests = requests # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -442,14 +455,15 @@ def batch_annotate_files( extracted. Args: - request (:class:`~.image_annotator.BatchAnnotateFilesRequest`): + request (google.cloud.vision_v1p4beta1.types.BatchAnnotateFilesRequest): The request object. A list of requests to annotate files using the BatchAnnotateFiles API. - requests (:class:`Sequence[~.image_annotator.AnnotateFileRequest]`): + requests (Sequence[google.cloud.vision_v1p4beta1.types.AnnotateFileRequest]): Required. The list of file annotation requests. Right now we support only one AnnotateFileRequest in BatchAnnotateFilesRequest. + This corresponds to the ``requests`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -461,7 +475,7 @@ def batch_annotate_files( sent along with the request as metadata. Returns: - ~.image_annotator.BatchAnnotateFilesResponse: + google.cloud.vision_v1p4beta1.types.BatchAnnotateFilesResponse: A list of file annotation responses. """ # Create or coerce a protobuf request object. @@ -487,8 +501,8 @@ def batch_annotate_files( # If we have keyword arguments corresponding to fields on the # request, apply these. - if requests: - request.requests.extend(requests) + if requests is not None: + request.requests = requests # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -524,18 +538,20 @@ def async_batch_annotate_images( BatchAnnotateImagesResponse proto. Args: - request (:class:`~.image_annotator.AsyncBatchAnnotateImagesRequest`): + request (google.cloud.vision_v1p4beta1.types.AsyncBatchAnnotateImagesRequest): The request object. Request for async image annotation for a list of images. - requests (:class:`Sequence[~.image_annotator.AnnotateImageRequest]`): + requests (Sequence[google.cloud.vision_v1p4beta1.types.AnnotateImageRequest]): Required. Individual image annotation requests for this batch. + This corresponds to the ``requests`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - output_config (:class:`~.image_annotator.OutputConfig`): + output_config (google.cloud.vision_v1p4beta1.types.OutputConfig): Required. The desired output location and metadata (e.g. format). + This corresponds to the ``output_config`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -547,11 +563,11 @@ def async_batch_annotate_images( sent along with the request as metadata. Returns: - ~.operation.Operation: + google.api_core.operation.Operation: An object representing a long-running operation. The result type for the operation will be - :class:``~.image_annotator.AsyncBatchAnnotateImagesResponse``: + :class:`google.cloud.vision_v1p4beta1.types.AsyncBatchAnnotateImagesResponse` Response to an async batch image annotation request. """ @@ -578,12 +594,11 @@ def async_batch_annotate_images( # If we have keyword arguments corresponding to fields on the # request, apply these. + if requests is not None: + request.requests = requests if output_config is not None: request.output_config = output_config - if requests: - request.requests.extend(requests) - # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = self._transport._wrapped_methods[ @@ -622,12 +637,13 @@ def async_batch_annotate_files( ``AsyncBatchAnnotateFilesResponse`` (results). Args: - request (:class:`~.image_annotator.AsyncBatchAnnotateFilesRequest`): + request (google.cloud.vision_v1p4beta1.types.AsyncBatchAnnotateFilesRequest): The request object. Multiple async file annotation requests are batched into a single service call. - requests (:class:`Sequence[~.image_annotator.AsyncAnnotateFileRequest]`): + requests (Sequence[google.cloud.vision_v1p4beta1.types.AsyncAnnotateFileRequest]): Required. Individual async file annotation requests for this batch. + This corresponds to the ``requests`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -639,11 +655,11 @@ def async_batch_annotate_files( sent along with the request as metadata. Returns: - ~.operation.Operation: + google.api_core.operation.Operation: An object representing a long-running operation. The result type for the operation will be - :class:``~.image_annotator.AsyncBatchAnnotateFilesResponse``: + :class:`google.cloud.vision_v1p4beta1.types.AsyncBatchAnnotateFilesResponse` Response to an async batch file annotation request. """ @@ -670,8 +686,8 @@ def async_batch_annotate_files( # If we have keyword arguments corresponding to fields on the # request, apply these. - if requests: - request.requests.extend(requests) + if requests is not None: + request.requests = requests # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. diff --git a/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc.py b/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc.py index 01609395..e4918610 100644 --- a/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc.py +++ b/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc.py @@ -62,6 +62,7 @@ def __init__( api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -92,6 +93,10 @@ def __init__( ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -108,6 +113,11 @@ def __init__( """ self._ssl_channel_credentials = ssl_channel_credentials + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -117,11 +127,6 @@ def __init__( self._grpc_channel = channel self._ssl_channel_credentials = None elif api_mtls_endpoint: - warnings.warn( - "api_mtls_endpoint and client_cert_source are deprecated", - DeprecationWarning, - ) - host = ( api_mtls_endpoint if ":" in api_mtls_endpoint @@ -165,12 +170,18 @@ def __init__( scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id ) + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + # create a new channel. The provided one is ignored. self._grpc_channel = type(self).create_channel( host, credentials=credentials, credentials_file=credentials_file, - ssl_credentials=ssl_channel_credentials, + ssl_credentials=self._ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ diff --git a/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc_asyncio.py b/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc_asyncio.py index 1386542d..3e26363e 100644 --- a/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc_asyncio.py +++ b/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc_asyncio.py @@ -106,6 +106,7 @@ def __init__( api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -137,6 +138,10 @@ def __init__( ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -153,6 +158,11 @@ def __init__( """ self._ssl_channel_credentials = ssl_channel_credentials + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -162,11 +172,6 @@ def __init__( self._grpc_channel = channel self._ssl_channel_credentials = None elif api_mtls_endpoint: - warnings.warn( - "api_mtls_endpoint and client_cert_source are deprecated", - DeprecationWarning, - ) - host = ( api_mtls_endpoint if ":" in api_mtls_endpoint @@ -210,12 +215,18 @@ def __init__( scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id ) + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + # create a new channel. The provided one is ignored. self._grpc_channel = type(self).create_channel( host, credentials=credentials, credentials_file=credentials_file, - ssl_credentials=ssl_channel_credentials, + ssl_credentials=self._ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ diff --git a/google/cloud/vision_v1p4beta1/services/product_search/async_client.py b/google/cloud/vision_v1p4beta1/services/product_search/async_client.py index 1c50dd67..41e45889 100644 --- a/google/cloud/vision_v1p4beta1/services/product_search/async_client.py +++ b/google/cloud/vision_v1p4beta1/services/product_search/async_client.py @@ -109,6 +109,7 @@ class ProductSearchAsyncClient: ProductSearchClient.parse_common_location_path ) + from_service_account_info = ProductSearchClient.from_service_account_info from_service_account_file = ProductSearchClient.from_service_account_file from_service_account_json = from_service_account_file @@ -192,7 +193,7 @@ async def create_product_set( longer than 4096 characters. Args: - request (:class:`~.product_search_service.CreateProductSetRequest`): + request (:class:`google.cloud.vision_v1p4beta1.types.CreateProductSetRequest`): The request object. Request message for the `CreateProductSet` method. parent (:class:`str`): @@ -200,10 +201,11 @@ async def create_product_set( created. Format is ``projects/PROJECT_ID/locations/LOC_ID``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - product_set (:class:`~.product_search_service.ProductSet`): + product_set (:class:`google.cloud.vision_v1p4beta1.types.ProductSet`): Required. The ProductSet to create. This corresponds to the ``product_set`` field on the ``request`` instance; if ``request`` is provided, this @@ -214,6 +216,7 @@ async def create_product_set( resource id. If it is already in use, an error is returned with code ALREADY_EXISTS. Must be at most 128 characters long. It cannot contain the character ``/``. + This corresponds to the ``product_set_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -225,7 +228,7 @@ async def create_product_set( sent along with the request as metadata. Returns: - ~.product_search_service.ProductSet: + google.cloud.vision_v1p4beta1.types.ProductSet: A ProductSet contains Products. A ProductSet can contain a maximum of 1 million reference images. If the limit @@ -298,7 +301,7 @@ async def list_product_sets( less than 1. Args: - request (:class:`~.product_search_service.ListProductSetsRequest`): + request (:class:`google.cloud.vision_v1p4beta1.types.ListProductSetsRequest`): The request object. Request message for the `ListProductSets` method. parent (:class:`str`): @@ -306,6 +309,7 @@ async def list_product_sets( listed. Format is ``projects/PROJECT_ID/locations/LOC_ID``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -317,8 +321,8 @@ async def list_product_sets( sent along with the request as metadata. Returns: - ~.pagers.ListProductSetsAsyncPager: - Response message for the ``ListProductSets`` method. + google.cloud.vision_v1p4beta1.services.product_search.pagers.ListProductSetsAsyncPager: + Response message for the ListProductSets method. Iterating over this object will yield results and resolve additional pages automatically. @@ -392,7 +396,7 @@ async def get_product_set( - Returns NOT_FOUND if the ProductSet does not exist. Args: - request (:class:`~.product_search_service.GetProductSetRequest`): + request (:class:`google.cloud.vision_v1p4beta1.types.GetProductSetRequest`): The request object. Request message for the `GetProductSet` method. name (:class:`str`): @@ -400,6 +404,7 @@ async def get_product_set( Format is: ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -411,7 +416,7 @@ async def get_product_set( sent along with the request as metadata. Returns: - ~.product_search_service.ProductSet: + google.cloud.vision_v1p4beta1.types.ProductSet: A ProductSet contains Products. A ProductSet can contain a maximum of 1 million reference images. If the limit @@ -486,20 +491,22 @@ async def update_product_set( characters. Args: - request (:class:`~.product_search_service.UpdateProductSetRequest`): + request (:class:`google.cloud.vision_v1p4beta1.types.UpdateProductSetRequest`): The request object. Request message for the `UpdateProductSet` method. - product_set (:class:`~.product_search_service.ProductSet`): + product_set (:class:`google.cloud.vision_v1p4beta1.types.ProductSet`): Required. The ProductSet resource which replaces the one on the server. + This corresponds to the ``product_set`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - update_mask (:class:`~.field_mask.FieldMask`): + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): The [FieldMask][google.protobuf.FieldMask] that specifies which fields to update. If update_mask isn't specified, all mutable fields are to be updated. Valid mask path is ``display_name``. + This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -511,7 +518,7 @@ async def update_product_set( sent along with the request as metadata. Returns: - ~.product_search_service.ProductSet: + google.cloud.vision_v1p4beta1.types.ProductSet: A ProductSet contains Products. A ProductSet can contain a maximum of 1 million reference images. If the limit @@ -582,7 +589,7 @@ async def delete_product_set( Storage. Args: - request (:class:`~.product_search_service.DeleteProductSetRequest`): + request (:class:`google.cloud.vision_v1p4beta1.types.DeleteProductSetRequest`): The request object. Request message for the `DeleteProductSet` method. name (:class:`str`): @@ -590,6 +597,7 @@ async def delete_product_set( Format is: ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -668,7 +676,7 @@ async def create_product( invalid. Args: - request (:class:`~.product_search_service.CreateProductRequest`): + request (:class:`google.cloud.vision_v1p4beta1.types.CreateProductRequest`): The request object. Request message for the `CreateProduct` method. parent (:class:`str`): @@ -676,10 +684,11 @@ async def create_product( created. Format is ``projects/PROJECT_ID/locations/LOC_ID``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - product (:class:`~.product_search_service.Product`): + product (:class:`google.cloud.vision_v1p4beta1.types.Product`): Required. The product to create. This corresponds to the ``product`` field on the ``request`` instance; if ``request`` is provided, this @@ -690,6 +699,7 @@ async def create_product( resource id. If it is already in use, an error is returned with code ALREADY_EXISTS. Must be at most 128 characters long. It cannot contain the character ``/``. + This corresponds to the ``product_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -701,7 +711,7 @@ async def create_product( sent along with the request as metadata. Returns: - ~.product_search_service.Product: + google.cloud.vision_v1p4beta1.types.Product: A Product contains ReferenceImages. """ # Create or coerce a protobuf request object. @@ -769,7 +779,7 @@ async def list_products( less than 1. Args: - request (:class:`~.product_search_service.ListProductsRequest`): + request (:class:`google.cloud.vision_v1p4beta1.types.ListProductsRequest`): The request object. Request message for the `ListProducts` method. parent (:class:`str`): @@ -777,6 +787,7 @@ async def list_products( should be listed. Format: ``projects/PROJECT_ID/locations/LOC_ID`` + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -788,8 +799,8 @@ async def list_products( sent along with the request as metadata. Returns: - ~.pagers.ListProductsAsyncPager: - Response message for the ``ListProducts`` method. + google.cloud.vision_v1p4beta1.services.product_search.pagers.ListProductsAsyncPager: + Response message for the ListProducts method. Iterating over this object will yield results and resolve additional pages automatically. @@ -863,7 +874,7 @@ async def get_product( - Returns NOT_FOUND if the Product does not exist. Args: - request (:class:`~.product_search_service.GetProductRequest`): + request (:class:`google.cloud.vision_v1p4beta1.types.GetProductRequest`): The request object. Request message for the `GetProduct` method. name (:class:`str`): @@ -871,6 +882,7 @@ async def get_product( Format is: ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -882,7 +894,7 @@ async def get_product( sent along with the request as metadata. Returns: - ~.product_search_service.Product: + google.cloud.vision_v1p4beta1.types.Product: A Product contains ReferenceImages. """ # Create or coerce a protobuf request object. @@ -959,22 +971,24 @@ async def update_product( update_mask. Args: - request (:class:`~.product_search_service.UpdateProductRequest`): + request (:class:`google.cloud.vision_v1p4beta1.types.UpdateProductRequest`): The request object. Request message for the `UpdateProduct` method. - product (:class:`~.product_search_service.Product`): + product (:class:`google.cloud.vision_v1p4beta1.types.Product`): Required. The Product resource which replaces the one on the server. product.name is immutable. + This corresponds to the ``product`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - update_mask (:class:`~.field_mask.FieldMask`): + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): The [FieldMask][google.protobuf.FieldMask] that specifies which fields to update. If update_mask isn't specified, all mutable fields are to be updated. Valid mask paths include ``product_labels``, ``display_name``, and ``description``. + This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -986,7 +1000,7 @@ async def update_product( sent along with the request as metadata. Returns: - ~.product_search_service.Product: + google.cloud.vision_v1p4beta1.types.Product: A Product contains ReferenceImages. """ # Create or coerce a protobuf request object. @@ -1054,7 +1068,7 @@ async def delete_product( all related caches are refreshed. Args: - request (:class:`~.product_search_service.DeleteProductRequest`): + request (:class:`google.cloud.vision_v1p4beta1.types.DeleteProductRequest`): The request object. Request message for the `DeleteProduct` method. name (:class:`str`): @@ -1062,6 +1076,7 @@ async def delete_product( Format is: ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1152,7 +1167,7 @@ async def create_reference_image( 10 polygons. Args: - request (:class:`~.product_search_service.CreateReferenceImageRequest`): + request (:class:`google.cloud.vision_v1p4beta1.types.CreateReferenceImageRequest`): The request object. Request message for the `CreateReferenceImage` method. parent (:class:`str`): @@ -1161,13 +1176,15 @@ async def create_reference_image( Format is ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - reference_image (:class:`~.product_search_service.ReferenceImage`): + reference_image (:class:`google.cloud.vision_v1p4beta1.types.ReferenceImage`): Required. The reference image to create. If an image ID is specified, it is ignored. + This corresponds to the ``reference_image`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1177,6 +1194,7 @@ async def create_reference_image( as the resource id. If it is already in use, an error is returned with code ALREADY_EXISTS. Must be at most 128 characters long. It cannot contain the character ``/``. + This corresponds to the ``reference_image_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1188,9 +1206,9 @@ async def create_reference_image( sent along with the request as metadata. Returns: - ~.product_search_service.ReferenceImage: - A ``ReferenceImage`` represents a product image and its - associated metadata, such as bounding boxes. + google.cloud.vision_v1p4beta1.types.ReferenceImage: + A ReferenceImage represents a product image and its associated metadata, + such as bounding boxes. """ # Create or coerce a protobuf request object. @@ -1259,7 +1277,7 @@ async def delete_reference_image( Storage. Args: - request (:class:`~.product_search_service.DeleteReferenceImageRequest`): + request (:class:`google.cloud.vision_v1p4beta1.types.DeleteReferenceImageRequest`): The request object. Request message for the `DeleteReferenceImage` method. name (:class:`str`): @@ -1269,6 +1287,7 @@ async def delete_reference_image( Format is: ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1342,7 +1361,7 @@ async def list_reference_images( 100, or less than 1. Args: - request (:class:`~.product_search_service.ListReferenceImagesRequest`): + request (:class:`google.cloud.vision_v1p4beta1.types.ListReferenceImagesRequest`): The request object. Request message for the `ListReferenceImages` method. parent (:class:`str`): @@ -1351,6 +1370,7 @@ async def list_reference_images( Format is ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1362,8 +1382,8 @@ async def list_reference_images( sent along with the request as metadata. Returns: - ~.pagers.ListReferenceImagesAsyncPager: - Response message for the ``ListReferenceImages`` method. + google.cloud.vision_v1p4beta1.services.product_search.pagers.ListReferenceImagesAsyncPager: + Response message for the ListReferenceImages method. Iterating over this object will yield results and resolve additional pages automatically. @@ -1437,7 +1457,7 @@ async def get_reference_image( - Returns NOT_FOUND if the specified image does not exist. Args: - request (:class:`~.product_search_service.GetReferenceImageRequest`): + request (:class:`google.cloud.vision_v1p4beta1.types.GetReferenceImageRequest`): The request object. Request message for the `GetReferenceImage` method. name (:class:`str`): @@ -1447,6 +1467,7 @@ async def get_reference_image( Format is: ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1458,9 +1479,9 @@ async def get_reference_image( sent along with the request as metadata. Returns: - ~.product_search_service.ReferenceImage: - A ``ReferenceImage`` represents a product image and its - associated metadata, such as bounding boxes. + google.cloud.vision_v1p4beta1.types.ReferenceImage: + A ReferenceImage represents a product image and its associated metadata, + such as bounding boxes. """ # Create or coerce a protobuf request object. @@ -1530,7 +1551,7 @@ async def add_product_to_product_set( exist. Args: - request (:class:`~.product_search_service.AddProductToProductSetRequest`): + request (:class:`google.cloud.vision_v1p4beta1.types.AddProductToProductSetRequest`): The request object. Request message for the `AddProductToProductSet` method. name (:class:`str`): @@ -1539,6 +1560,7 @@ async def add_product_to_product_set( Format is: ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1548,6 +1570,7 @@ async def add_product_to_product_set( Format is: ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + This corresponds to the ``product`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1616,7 +1639,7 @@ async def remove_product_from_product_set( r"""Removes a Product from the specified ProductSet. Args: - request (:class:`~.product_search_service.RemoveProductFromProductSetRequest`): + request (:class:`google.cloud.vision_v1p4beta1.types.RemoveProductFromProductSetRequest`): The request object. Request message for the `RemoveProductFromProductSet` method. name (:class:`str`): @@ -1625,6 +1648,7 @@ async def remove_product_from_product_set( Format is: ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1634,6 +1658,7 @@ async def remove_product_from_product_set( Format is: ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + This corresponds to the ``product`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1708,7 +1733,7 @@ async def list_products_in_product_set( less than 1. Args: - request (:class:`~.product_search_service.ListProductsInProductSetRequest`): + request (:class:`google.cloud.vision_v1p4beta1.types.ListProductsInProductSetRequest`): The request object. Request message for the `ListProductsInProductSet` method. name (:class:`str`): @@ -1717,6 +1742,7 @@ async def list_products_in_product_set( Format is: ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1728,8 +1754,8 @@ async def list_products_in_product_set( sent along with the request as metadata. Returns: - ~.pagers.ListProductsInProductSetAsyncPager: - Response message for the ``ListProductsInProductSet`` + google.cloud.vision_v1p4beta1.services.product_search.pagers.ListProductsInProductSetAsyncPager: + Response message for the ListProductsInProductSet method. Iterating over this object will yield results and @@ -1812,7 +1838,7 @@ async def import_product_sets( [ImportProductSetsGcsSource.csv_file_uri][google.cloud.vision.v1p4beta1.ImportProductSetsGcsSource.csv_file_uri]. Args: - request (:class:`~.product_search_service.ImportProductSetsRequest`): + request (:class:`google.cloud.vision_v1p4beta1.types.ImportProductSetsRequest`): The request object. Request message for the `ImportProductSets` method. parent (:class:`str`): @@ -1820,12 +1846,14 @@ async def import_product_sets( imported. Format is ``projects/PROJECT_ID/locations/LOC_ID``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - input_config (:class:`~.product_search_service.ImportProductSetsInputConfig`): + input_config (:class:`google.cloud.vision_v1p4beta1.types.ImportProductSetsInputConfig`): Required. The input content for the list of requests. + This corresponds to the ``input_config`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1837,18 +1865,18 @@ async def import_product_sets( sent along with the request as metadata. Returns: - ~.operation_async.AsyncOperation: + google.api_core.operation_async.AsyncOperation: An object representing a long-running operation. The result type for the operation will be - :class:``~.product_search_service.ImportProductSetsResponse``: - Response message for the ``ImportProductSets`` method. + :class:`google.cloud.vision_v1p4beta1.types.ImportProductSetsResponse` + Response message for the ImportProductSets method. - This message is returned by the - [google.longrunning.Operations.GetOperation][google.longrunning.Operations.GetOperation] - method in the returned - [google.longrunning.Operation.response][google.longrunning.Operation.response] - field. + This message is returned by the + [google.longrunning.Operations.GetOperation][google.longrunning.Operations.GetOperation] + method in the returned + [google.longrunning.Operation.response][google.longrunning.Operation.response] + field. """ # Create or coerce a protobuf request object. @@ -1943,7 +1971,7 @@ async def purge_products( ``BatchOperationMetadata``. (progress) Args: - request (:class:`~.product_search_service.PurgeProductsRequest`): + request (:class:`google.cloud.vision_v1p4beta1.types.PurgeProductsRequest`): The request object. Request message for the `PurgeProducts` method. parent (:class:`str`): @@ -1951,6 +1979,7 @@ async def purge_products( should be deleted. Format is ``projects/PROJECT_ID/locations/LOC_ID``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1962,24 +1991,22 @@ async def purge_products( sent along with the request as metadata. Returns: - ~.operation_async.AsyncOperation: + google.api_core.operation_async.AsyncOperation: An object representing a long-running operation. - The result type for the operation will be - :class:``~.empty.Empty``: A generic empty message that - you can re-use to avoid defining duplicated empty - messages in your APIs. A typical example is to use it as - the request or the response type of an API method. For - instance: + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: - :: + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); - service Foo { - rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); - } + } - The JSON representation for ``Empty`` is empty JSON - object ``{}``. + The JSON representation for Empty is empty JSON + object {}. """ # Create or coerce a protobuf request object. diff --git a/google/cloud/vision_v1p4beta1/services/product_search/client.py b/google/cloud/vision_v1p4beta1/services/product_search/client.py index dc704e28..485d3ebd 100644 --- a/google/cloud/vision_v1p4beta1/services/product_search/client.py +++ b/google/cloud/vision_v1p4beta1/services/product_search/client.py @@ -135,6 +135,22 @@ def _get_default_mtls_endpoint(api_endpoint): DEFAULT_ENDPOINT ) + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + ProductSearchClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_info(info) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials @@ -147,7 +163,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): kwargs: Additional arguments to pass to the constructor. Returns: - {@api.name}: The constructed client. + ProductSearchClient: The constructed client. """ credentials = service_account.Credentials.from_service_account_file(filename) kwargs["credentials"] = credentials @@ -292,10 +308,10 @@ def __init__( credentials identify the application to the service; if none are specified, the client will attempt to ascertain the credentials from the environment. - transport (Union[str, ~.ProductSearchTransport]): The + transport (Union[str, ProductSearchTransport]): The transport to use. If set to None, a transport is chosen automatically. - client_options (client_options_lib.ClientOptions): Custom options for the + client_options (google.api_core.client_options.ClientOptions): Custom options for the client. It won't take effect if a ``transport`` instance is provided. (1) The ``api_endpoint`` property can be used to override the default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT @@ -331,21 +347,17 @@ def __init__( util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")) ) - ssl_credentials = None + client_cert_source_func = None is_mtls = False if use_client_cert: if client_options.client_cert_source: - import grpc # type: ignore - - cert, key = client_options.client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) is_mtls = True + client_cert_source_func = client_options.client_cert_source else: - creds = SslCredentials() - is_mtls = creds.is_mtls - ssl_credentials = creds.ssl_credentials if is_mtls else None + is_mtls = mtls.has_default_client_cert_source() + client_cert_source_func = ( + mtls.default_client_cert_source() if is_mtls else None + ) # Figure out which api endpoint to use. if client_options.api_endpoint is not None: @@ -388,7 +400,7 @@ def __init__( credentials_file=client_options.credentials_file, host=api_endpoint, scopes=client_options.scopes, - ssl_channel_credentials=ssl_credentials, + client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, ) @@ -412,28 +424,30 @@ def create_product_set( longer than 4096 characters. Args: - request (:class:`~.product_search_service.CreateProductSetRequest`): + request (google.cloud.vision_v1p4beta1.types.CreateProductSetRequest): The request object. Request message for the `CreateProductSet` method. - parent (:class:`str`): + parent (str): Required. The project in which the ProductSet should be created. Format is ``projects/PROJECT_ID/locations/LOC_ID``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - product_set (:class:`~.product_search_service.ProductSet`): + product_set (google.cloud.vision_v1p4beta1.types.ProductSet): Required. The ProductSet to create. This corresponds to the ``product_set`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - product_set_id (:class:`str`): + product_set_id (str): A user-supplied resource id for this ProductSet. If set, the server will attempt to use this value as the resource id. If it is already in use, an error is returned with code ALREADY_EXISTS. Must be at most 128 characters long. It cannot contain the character ``/``. + This corresponds to the ``product_set_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -445,7 +459,7 @@ def create_product_set( sent along with the request as metadata. Returns: - ~.product_search_service.ProductSet: + google.cloud.vision_v1p4beta1.types.ProductSet: A ProductSet contains Products. A ProductSet can contain a maximum of 1 million reference images. If the limit @@ -513,14 +527,15 @@ def list_product_sets( less than 1. Args: - request (:class:`~.product_search_service.ListProductSetsRequest`): + request (google.cloud.vision_v1p4beta1.types.ListProductSetsRequest): The request object. Request message for the `ListProductSets` method. - parent (:class:`str`): + parent (str): Required. The project from which ProductSets should be listed. Format is ``projects/PROJECT_ID/locations/LOC_ID``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -532,8 +547,8 @@ def list_product_sets( sent along with the request as metadata. Returns: - ~.pagers.ListProductSetsPager: - Response message for the ``ListProductSets`` method. + google.cloud.vision_v1p4beta1.services.product_search.pagers.ListProductSetsPager: + Response message for the ListProductSets method. Iterating over this object will yield results and resolve additional pages automatically. @@ -600,14 +615,15 @@ def get_product_set( - Returns NOT_FOUND if the ProductSet does not exist. Args: - request (:class:`~.product_search_service.GetProductSetRequest`): + request (google.cloud.vision_v1p4beta1.types.GetProductSetRequest): The request object. Request message for the `GetProductSet` method. - name (:class:`str`): + name (str): Required. Resource name of the ProductSet to get. Format is: ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -619,7 +635,7 @@ def get_product_set( sent along with the request as metadata. Returns: - ~.product_search_service.ProductSet: + google.cloud.vision_v1p4beta1.types.ProductSet: A ProductSet contains Products. A ProductSet can contain a maximum of 1 million reference images. If the limit @@ -687,20 +703,22 @@ def update_product_set( characters. Args: - request (:class:`~.product_search_service.UpdateProductSetRequest`): + request (google.cloud.vision_v1p4beta1.types.UpdateProductSetRequest): The request object. Request message for the `UpdateProductSet` method. - product_set (:class:`~.product_search_service.ProductSet`): + product_set (google.cloud.vision_v1p4beta1.types.ProductSet): Required. The ProductSet resource which replaces the one on the server. + This corresponds to the ``product_set`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - update_mask (:class:`~.field_mask.FieldMask`): + update_mask (google.protobuf.field_mask_pb2.FieldMask): The [FieldMask][google.protobuf.FieldMask] that specifies which fields to update. If update_mask isn't specified, all mutable fields are to be updated. Valid mask path is ``display_name``. + This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -712,7 +730,7 @@ def update_product_set( sent along with the request as metadata. Returns: - ~.product_search_service.ProductSet: + google.cloud.vision_v1p4beta1.types.ProductSet: A ProductSet contains Products. A ProductSet can contain a maximum of 1 million reference images. If the limit @@ -778,14 +796,15 @@ def delete_product_set( Storage. Args: - request (:class:`~.product_search_service.DeleteProductSetRequest`): + request (google.cloud.vision_v1p4beta1.types.DeleteProductSetRequest): The request object. Request message for the `DeleteProductSet` method. - name (:class:`str`): + name (str): Required. Resource name of the ProductSet to delete. Format is: ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -857,28 +876,30 @@ def create_product( invalid. Args: - request (:class:`~.product_search_service.CreateProductRequest`): + request (google.cloud.vision_v1p4beta1.types.CreateProductRequest): The request object. Request message for the `CreateProduct` method. - parent (:class:`str`): + parent (str): Required. The project in which the Product should be created. Format is ``projects/PROJECT_ID/locations/LOC_ID``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - product (:class:`~.product_search_service.Product`): + product (google.cloud.vision_v1p4beta1.types.Product): Required. The product to create. This corresponds to the ``product`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - product_id (:class:`str`): + product_id (str): A user-supplied resource id for this Product. If set, the server will attempt to use this value as the resource id. If it is already in use, an error is returned with code ALREADY_EXISTS. Must be at most 128 characters long. It cannot contain the character ``/``. + This corresponds to the ``product_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -890,7 +911,7 @@ def create_product( sent along with the request as metadata. Returns: - ~.product_search_service.Product: + google.cloud.vision_v1p4beta1.types.Product: A Product contains ReferenceImages. """ # Create or coerce a protobuf request object. @@ -953,14 +974,15 @@ def list_products( less than 1. Args: - request (:class:`~.product_search_service.ListProductsRequest`): + request (google.cloud.vision_v1p4beta1.types.ListProductsRequest): The request object. Request message for the `ListProducts` method. - parent (:class:`str`): + parent (str): Required. The project OR ProductSet from which Products should be listed. Format: ``projects/PROJECT_ID/locations/LOC_ID`` + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -972,8 +994,8 @@ def list_products( sent along with the request as metadata. Returns: - ~.pagers.ListProductsPager: - Response message for the ``ListProducts`` method. + google.cloud.vision_v1p4beta1.services.product_search.pagers.ListProductsPager: + Response message for the ListProducts method. Iterating over this object will yield results and resolve additional pages automatically. @@ -1040,14 +1062,15 @@ def get_product( - Returns NOT_FOUND if the Product does not exist. Args: - request (:class:`~.product_search_service.GetProductRequest`): + request (google.cloud.vision_v1p4beta1.types.GetProductRequest): The request object. Request message for the `GetProduct` method. - name (:class:`str`): + name (str): Required. Resource name of the Product to get. Format is: ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1059,7 +1082,7 @@ def get_product( sent along with the request as metadata. Returns: - ~.product_search_service.Product: + google.cloud.vision_v1p4beta1.types.Product: A Product contains ReferenceImages. """ # Create or coerce a protobuf request object. @@ -1129,22 +1152,24 @@ def update_product( update_mask. Args: - request (:class:`~.product_search_service.UpdateProductRequest`): + request (google.cloud.vision_v1p4beta1.types.UpdateProductRequest): The request object. Request message for the `UpdateProduct` method. - product (:class:`~.product_search_service.Product`): + product (google.cloud.vision_v1p4beta1.types.Product): Required. The Product resource which replaces the one on the server. product.name is immutable. + This corresponds to the ``product`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - update_mask (:class:`~.field_mask.FieldMask`): + update_mask (google.protobuf.field_mask_pb2.FieldMask): The [FieldMask][google.protobuf.FieldMask] that specifies which fields to update. If update_mask isn't specified, all mutable fields are to be updated. Valid mask paths include ``product_labels``, ``display_name``, and ``description``. + This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1156,7 +1181,7 @@ def update_product( sent along with the request as metadata. Returns: - ~.product_search_service.Product: + google.cloud.vision_v1p4beta1.types.Product: A Product contains ReferenceImages. """ # Create or coerce a protobuf request object. @@ -1219,14 +1244,15 @@ def delete_product( all related caches are refreshed. Args: - request (:class:`~.product_search_service.DeleteProductRequest`): + request (google.cloud.vision_v1p4beta1.types.DeleteProductRequest): The request object. Request message for the `DeleteProduct` method. - name (:class:`str`): + name (str): Required. Resource name of product to delete. Format is: ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1310,31 +1336,34 @@ def create_reference_image( 10 polygons. Args: - request (:class:`~.product_search_service.CreateReferenceImageRequest`): + request (google.cloud.vision_v1p4beta1.types.CreateReferenceImageRequest): The request object. Request message for the `CreateReferenceImage` method. - parent (:class:`str`): + parent (str): Required. Resource name of the product in which to create the reference image. Format is ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - reference_image (:class:`~.product_search_service.ReferenceImage`): + reference_image (google.cloud.vision_v1p4beta1.types.ReferenceImage): Required. The reference image to create. If an image ID is specified, it is ignored. + This corresponds to the ``reference_image`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - reference_image_id (:class:`str`): + reference_image_id (str): A user-supplied resource id for the ReferenceImage to be added. If set, the server will attempt to use this value as the resource id. If it is already in use, an error is returned with code ALREADY_EXISTS. Must be at most 128 characters long. It cannot contain the character ``/``. + This corresponds to the ``reference_image_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1346,9 +1375,9 @@ def create_reference_image( sent along with the request as metadata. Returns: - ~.product_search_service.ReferenceImage: - A ``ReferenceImage`` represents a product image and its - associated metadata, such as bounding boxes. + google.cloud.vision_v1p4beta1.types.ReferenceImage: + A ReferenceImage represents a product image and its associated metadata, + such as bounding boxes. """ # Create or coerce a protobuf request object. @@ -1412,16 +1441,17 @@ def delete_reference_image( Storage. Args: - request (:class:`~.product_search_service.DeleteReferenceImageRequest`): + request (google.cloud.vision_v1p4beta1.types.DeleteReferenceImageRequest): The request object. Request message for the `DeleteReferenceImage` method. - name (:class:`str`): + name (str): Required. The resource name of the reference image to delete. Format is: ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1488,15 +1518,16 @@ def list_reference_images( 100, or less than 1. Args: - request (:class:`~.product_search_service.ListReferenceImagesRequest`): + request (google.cloud.vision_v1p4beta1.types.ListReferenceImagesRequest): The request object. Request message for the `ListReferenceImages` method. - parent (:class:`str`): + parent (str): Required. Resource name of the product containing the reference images. Format is ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1508,8 +1539,8 @@ def list_reference_images( sent along with the request as metadata. Returns: - ~.pagers.ListReferenceImagesPager: - Response message for the ``ListReferenceImages`` method. + google.cloud.vision_v1p4beta1.services.product_search.pagers.ListReferenceImagesPager: + Response message for the ListReferenceImages method. Iterating over this object will yield results and resolve additional pages automatically. @@ -1576,16 +1607,17 @@ def get_reference_image( - Returns NOT_FOUND if the specified image does not exist. Args: - request (:class:`~.product_search_service.GetReferenceImageRequest`): + request (google.cloud.vision_v1p4beta1.types.GetReferenceImageRequest): The request object. Request message for the `GetReferenceImage` method. - name (:class:`str`): + name (str): Required. The resource name of the ReferenceImage to get. Format is: ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1597,9 +1629,9 @@ def get_reference_image( sent along with the request as metadata. Returns: - ~.product_search_service.ReferenceImage: - A ``ReferenceImage`` represents a product image and its - associated metadata, such as bounding boxes. + google.cloud.vision_v1p4beta1.types.ReferenceImage: + A ReferenceImage represents a product image and its associated metadata, + such as bounding boxes. """ # Create or coerce a protobuf request object. @@ -1662,24 +1694,26 @@ def add_product_to_product_set( exist. Args: - request (:class:`~.product_search_service.AddProductToProductSetRequest`): + request (google.cloud.vision_v1p4beta1.types.AddProductToProductSetRequest): The request object. Request message for the `AddProductToProductSet` method. - name (:class:`str`): + name (str): Required. The resource name for the ProductSet to modify. Format is: ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - product (:class:`str`): + product (str): Required. The resource name for the Product to be added to this ProductSet. Format is: ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + This corresponds to the ``product`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1747,24 +1781,26 @@ def remove_product_from_product_set( r"""Removes a Product from the specified ProductSet. Args: - request (:class:`~.product_search_service.RemoveProductFromProductSetRequest`): + request (google.cloud.vision_v1p4beta1.types.RemoveProductFromProductSetRequest): The request object. Request message for the `RemoveProductFromProductSet` method. - name (:class:`str`): + name (str): Required. The resource name for the ProductSet to modify. Format is: ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - product (:class:`str`): + product (str): Required. The resource name for the Product to be removed from this ProductSet. Format is: ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + This corresponds to the ``product`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1838,15 +1874,16 @@ def list_products_in_product_set( less than 1. Args: - request (:class:`~.product_search_service.ListProductsInProductSetRequest`): + request (google.cloud.vision_v1p4beta1.types.ListProductsInProductSetRequest): The request object. Request message for the `ListProductsInProductSet` method. - name (:class:`str`): + name (str): Required. The ProductSet resource for which to retrieve Products. Format is: ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1858,8 +1895,8 @@ def list_products_in_product_set( sent along with the request as metadata. Returns: - ~.pagers.ListProductsInProductSetPager: - Response message for the ``ListProductsInProductSet`` + google.cloud.vision_v1p4beta1.services.product_search.pagers.ListProductsInProductSetPager: + Response message for the ListProductsInProductSet method. Iterating over this object will yield results and @@ -1939,20 +1976,22 @@ def import_product_sets( [ImportProductSetsGcsSource.csv_file_uri][google.cloud.vision.v1p4beta1.ImportProductSetsGcsSource.csv_file_uri]. Args: - request (:class:`~.product_search_service.ImportProductSetsRequest`): + request (google.cloud.vision_v1p4beta1.types.ImportProductSetsRequest): The request object. Request message for the `ImportProductSets` method. - parent (:class:`str`): + parent (str): Required. The project in which the ProductSets should be imported. Format is ``projects/PROJECT_ID/locations/LOC_ID``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - input_config (:class:`~.product_search_service.ImportProductSetsInputConfig`): + input_config (google.cloud.vision_v1p4beta1.types.ImportProductSetsInputConfig): Required. The input content for the list of requests. + This corresponds to the ``input_config`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1964,18 +2003,18 @@ def import_product_sets( sent along with the request as metadata. Returns: - ~.operation.Operation: + google.api_core.operation.Operation: An object representing a long-running operation. The result type for the operation will be - :class:``~.product_search_service.ImportProductSetsResponse``: - Response message for the ``ImportProductSets`` method. + :class:`google.cloud.vision_v1p4beta1.types.ImportProductSetsResponse` + Response message for the ImportProductSets method. - This message is returned by the - [google.longrunning.Operations.GetOperation][google.longrunning.Operations.GetOperation] - method in the returned - [google.longrunning.Operation.response][google.longrunning.Operation.response] - field. + This message is returned by the + [google.longrunning.Operations.GetOperation][google.longrunning.Operations.GetOperation] + method in the returned + [google.longrunning.Operation.response][google.longrunning.Operation.response] + field. """ # Create or coerce a protobuf request object. @@ -2065,14 +2104,15 @@ def purge_products( ``BatchOperationMetadata``. (progress) Args: - request (:class:`~.product_search_service.PurgeProductsRequest`): + request (google.cloud.vision_v1p4beta1.types.PurgeProductsRequest): The request object. Request message for the `PurgeProducts` method. - parent (:class:`str`): + parent (str): Required. The project and location in which the Products should be deleted. Format is ``projects/PROJECT_ID/locations/LOC_ID``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -2084,24 +2124,22 @@ def purge_products( sent along with the request as metadata. Returns: - ~.operation.Operation: + google.api_core.operation.Operation: An object representing a long-running operation. - The result type for the operation will be - :class:``~.empty.Empty``: A generic empty message that - you can re-use to avoid defining duplicated empty - messages in your APIs. A typical example is to use it as - the request or the response type of an API method. For - instance: + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: - :: + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); - service Foo { - rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); - } + } - The JSON representation for ``Empty`` is empty JSON - object ``{}``. + The JSON representation for Empty is empty JSON + object {}. """ # Create or coerce a protobuf request object. diff --git a/google/cloud/vision_v1p4beta1/services/product_search/pagers.py b/google/cloud/vision_v1p4beta1/services/product_search/pagers.py index c3ac34cd..2786380e 100644 --- a/google/cloud/vision_v1p4beta1/services/product_search/pagers.py +++ b/google/cloud/vision_v1p4beta1/services/product_search/pagers.py @@ -15,7 +15,16 @@ # limitations under the License. # -from typing import Any, AsyncIterable, Awaitable, Callable, Iterable, Sequence, Tuple +from typing import ( + Any, + AsyncIterable, + Awaitable, + Callable, + Iterable, + Sequence, + Tuple, + Optional, +) from google.cloud.vision_v1p4beta1.types import product_search_service @@ -24,7 +33,7 @@ class ListProductSetsPager: """A pager for iterating through ``list_product_sets`` requests. This class thinly wraps an initial - :class:`~.product_search_service.ListProductSetsResponse` object, and + :class:`google.cloud.vision_v1p4beta1.types.ListProductSetsResponse` object, and provides an ``__iter__`` method to iterate through its ``product_sets`` field. @@ -33,7 +42,7 @@ class ListProductSetsPager: through the ``product_sets`` field on the corresponding responses. - All the usual :class:`~.product_search_service.ListProductSetsResponse` + All the usual :class:`google.cloud.vision_v1p4beta1.types.ListProductSetsResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -51,9 +60,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.product_search_service.ListProductSetsRequest`): + request (google.cloud.vision_v1p4beta1.types.ListProductSetsRequest): The initial request object. - response (:class:`~.product_search_service.ListProductSetsResponse`): + response (google.cloud.vision_v1p4beta1.types.ListProductSetsResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -86,7 +95,7 @@ class ListProductSetsAsyncPager: """A pager for iterating through ``list_product_sets`` requests. This class thinly wraps an initial - :class:`~.product_search_service.ListProductSetsResponse` object, and + :class:`google.cloud.vision_v1p4beta1.types.ListProductSetsResponse` object, and provides an ``__aiter__`` method to iterate through its ``product_sets`` field. @@ -95,7 +104,7 @@ class ListProductSetsAsyncPager: through the ``product_sets`` field on the corresponding responses. - All the usual :class:`~.product_search_service.ListProductSetsResponse` + All the usual :class:`google.cloud.vision_v1p4beta1.types.ListProductSetsResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -115,9 +124,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.product_search_service.ListProductSetsRequest`): + request (google.cloud.vision_v1p4beta1.types.ListProductSetsRequest): The initial request object. - response (:class:`~.product_search_service.ListProductSetsResponse`): + response (google.cloud.vision_v1p4beta1.types.ListProductSetsResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -156,7 +165,7 @@ class ListProductsPager: """A pager for iterating through ``list_products`` requests. This class thinly wraps an initial - :class:`~.product_search_service.ListProductsResponse` object, and + :class:`google.cloud.vision_v1p4beta1.types.ListProductsResponse` object, and provides an ``__iter__`` method to iterate through its ``products`` field. @@ -165,7 +174,7 @@ class ListProductsPager: through the ``products`` field on the corresponding responses. - All the usual :class:`~.product_search_service.ListProductsResponse` + All the usual :class:`google.cloud.vision_v1p4beta1.types.ListProductsResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -183,9 +192,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.product_search_service.ListProductsRequest`): + request (google.cloud.vision_v1p4beta1.types.ListProductsRequest): The initial request object. - response (:class:`~.product_search_service.ListProductsResponse`): + response (google.cloud.vision_v1p4beta1.types.ListProductsResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -218,7 +227,7 @@ class ListProductsAsyncPager: """A pager for iterating through ``list_products`` requests. This class thinly wraps an initial - :class:`~.product_search_service.ListProductsResponse` object, and + :class:`google.cloud.vision_v1p4beta1.types.ListProductsResponse` object, and provides an ``__aiter__`` method to iterate through its ``products`` field. @@ -227,7 +236,7 @@ class ListProductsAsyncPager: through the ``products`` field on the corresponding responses. - All the usual :class:`~.product_search_service.ListProductsResponse` + All the usual :class:`google.cloud.vision_v1p4beta1.types.ListProductsResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -245,9 +254,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.product_search_service.ListProductsRequest`): + request (google.cloud.vision_v1p4beta1.types.ListProductsRequest): The initial request object. - response (:class:`~.product_search_service.ListProductsResponse`): + response (google.cloud.vision_v1p4beta1.types.ListProductsResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -284,7 +293,7 @@ class ListReferenceImagesPager: """A pager for iterating through ``list_reference_images`` requests. This class thinly wraps an initial - :class:`~.product_search_service.ListReferenceImagesResponse` object, and + :class:`google.cloud.vision_v1p4beta1.types.ListReferenceImagesResponse` object, and provides an ``__iter__`` method to iterate through its ``reference_images`` field. @@ -293,7 +302,7 @@ class ListReferenceImagesPager: through the ``reference_images`` field on the corresponding responses. - All the usual :class:`~.product_search_service.ListReferenceImagesResponse` + All the usual :class:`google.cloud.vision_v1p4beta1.types.ListReferenceImagesResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -311,9 +320,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.product_search_service.ListReferenceImagesRequest`): + request (google.cloud.vision_v1p4beta1.types.ListReferenceImagesRequest): The initial request object. - response (:class:`~.product_search_service.ListReferenceImagesResponse`): + response (google.cloud.vision_v1p4beta1.types.ListReferenceImagesResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -346,7 +355,7 @@ class ListReferenceImagesAsyncPager: """A pager for iterating through ``list_reference_images`` requests. This class thinly wraps an initial - :class:`~.product_search_service.ListReferenceImagesResponse` object, and + :class:`google.cloud.vision_v1p4beta1.types.ListReferenceImagesResponse` object, and provides an ``__aiter__`` method to iterate through its ``reference_images`` field. @@ -355,7 +364,7 @@ class ListReferenceImagesAsyncPager: through the ``reference_images`` field on the corresponding responses. - All the usual :class:`~.product_search_service.ListReferenceImagesResponse` + All the usual :class:`google.cloud.vision_v1p4beta1.types.ListReferenceImagesResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -375,9 +384,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.product_search_service.ListReferenceImagesRequest`): + request (google.cloud.vision_v1p4beta1.types.ListReferenceImagesRequest): The initial request object. - response (:class:`~.product_search_service.ListReferenceImagesResponse`): + response (google.cloud.vision_v1p4beta1.types.ListReferenceImagesResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -416,7 +425,7 @@ class ListProductsInProductSetPager: """A pager for iterating through ``list_products_in_product_set`` requests. This class thinly wraps an initial - :class:`~.product_search_service.ListProductsInProductSetResponse` object, and + :class:`google.cloud.vision_v1p4beta1.types.ListProductsInProductSetResponse` object, and provides an ``__iter__`` method to iterate through its ``products`` field. @@ -425,7 +434,7 @@ class ListProductsInProductSetPager: through the ``products`` field on the corresponding responses. - All the usual :class:`~.product_search_service.ListProductsInProductSetResponse` + All the usual :class:`google.cloud.vision_v1p4beta1.types.ListProductsInProductSetResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -443,9 +452,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.product_search_service.ListProductsInProductSetRequest`): + request (google.cloud.vision_v1p4beta1.types.ListProductsInProductSetRequest): The initial request object. - response (:class:`~.product_search_service.ListProductsInProductSetResponse`): + response (google.cloud.vision_v1p4beta1.types.ListProductsInProductSetResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -480,7 +489,7 @@ class ListProductsInProductSetAsyncPager: """A pager for iterating through ``list_products_in_product_set`` requests. This class thinly wraps an initial - :class:`~.product_search_service.ListProductsInProductSetResponse` object, and + :class:`google.cloud.vision_v1p4beta1.types.ListProductsInProductSetResponse` object, and provides an ``__aiter__`` method to iterate through its ``products`` field. @@ -489,7 +498,7 @@ class ListProductsInProductSetAsyncPager: through the ``products`` field on the corresponding responses. - All the usual :class:`~.product_search_service.ListProductsInProductSetResponse` + All the usual :class:`google.cloud.vision_v1p4beta1.types.ListProductsInProductSetResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -509,9 +518,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.product_search_service.ListProductsInProductSetRequest`): + request (google.cloud.vision_v1p4beta1.types.ListProductsInProductSetRequest): The initial request object. - response (:class:`~.product_search_service.ListProductsInProductSetResponse`): + response (google.cloud.vision_v1p4beta1.types.ListProductsInProductSetResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. diff --git a/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc.py b/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc.py index 3e8ea680..cded719d 100644 --- a/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc.py +++ b/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc.py @@ -79,6 +79,7 @@ def __init__( api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -109,6 +110,10 @@ def __init__( ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -125,6 +130,11 @@ def __init__( """ self._ssl_channel_credentials = ssl_channel_credentials + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -134,11 +144,6 @@ def __init__( self._grpc_channel = channel self._ssl_channel_credentials = None elif api_mtls_endpoint: - warnings.warn( - "api_mtls_endpoint and client_cert_source are deprecated", - DeprecationWarning, - ) - host = ( api_mtls_endpoint if ":" in api_mtls_endpoint @@ -182,12 +187,18 @@ def __init__( scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id ) + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + # create a new channel. The provided one is ignored. self._grpc_channel = type(self).create_channel( host, credentials=credentials, credentials_file=credentials_file, - ssl_credentials=ssl_channel_credentials, + ssl_credentials=self._ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ diff --git a/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc_asyncio.py b/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc_asyncio.py index 6a0af863..3edf5094 100644 --- a/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc_asyncio.py +++ b/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc_asyncio.py @@ -123,6 +123,7 @@ def __init__( api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -154,6 +155,10 @@ def __init__( ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -170,6 +175,11 @@ def __init__( """ self._ssl_channel_credentials = ssl_channel_credentials + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -179,11 +189,6 @@ def __init__( self._grpc_channel = channel self._ssl_channel_credentials = None elif api_mtls_endpoint: - warnings.warn( - "api_mtls_endpoint and client_cert_source are deprecated", - DeprecationWarning, - ) - host = ( api_mtls_endpoint if ":" in api_mtls_endpoint @@ -227,12 +232,18 @@ def __init__( scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id ) + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + # create a new channel. The provided one is ignored. self._grpc_channel = type(self).create_channel( host, credentials=credentials, credentials_file=credentials_file, - ssl_credentials=ssl_channel_credentials, + ssl_credentials=self._ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ diff --git a/google/cloud/vision_v1p4beta1/types/face.py b/google/cloud/vision_v1p4beta1/types/face.py index 34ca9aa9..89fbc30b 100644 --- a/google/cloud/vision_v1p4beta1/types/face.py +++ b/google/cloud/vision_v1p4beta1/types/face.py @@ -64,7 +64,7 @@ class FaceRecognitionResult(proto.Message): r"""Information about a face's identity. Attributes: - celebrity (~.face.Celebrity): + celebrity (google.cloud.vision_v1p4beta1.types.Celebrity): The [Celebrity][google.cloud.vision.v1p4beta1.Celebrity] that this face was matched to. confidence (float): diff --git a/google/cloud/vision_v1p4beta1/types/geometry.py b/google/cloud/vision_v1p4beta1/types/geometry.py index 60c32e6e..b43c8d06 100644 --- a/google/cloud/vision_v1p4beta1/types/geometry.py +++ b/google/cloud/vision_v1p4beta1/types/geometry.py @@ -62,9 +62,9 @@ class BoundingPoly(proto.Message): r"""A bounding polygon for the detected image annotation. Attributes: - vertices (Sequence[~.geometry.Vertex]): + vertices (Sequence[google.cloud.vision_v1p4beta1.types.Vertex]): The bounding polygon vertices. - normalized_vertices (Sequence[~.geometry.NormalizedVertex]): + normalized_vertices (Sequence[google.cloud.vision_v1p4beta1.types.NormalizedVertex]): The bounding polygon normalized vertices. """ diff --git a/google/cloud/vision_v1p4beta1/types/image_annotator.py b/google/cloud/vision_v1p4beta1/types/image_annotator.py index 98788127..b4e3b321 100644 --- a/google/cloud/vision_v1p4beta1/types/image_annotator.py +++ b/google/cloud/vision_v1p4beta1/types/image_annotator.py @@ -94,7 +94,7 @@ class Feature(proto.Message): ``Feature`` objects can be specified in the ``features`` list. Attributes: - type_ (~.image_annotator.Feature.Type): + type_ (google.cloud.vision_v1p4beta1.types.Feature.Type): The feature type. max_results (int): Maximum number of results of this type. Does not apply to @@ -177,7 +177,7 @@ class Image(proto.Message): Image content, represented as a stream of bytes. Note: As with all ``bytes`` fields, protobuffers use a pure binary representation, whereas JSON representations use base64. - source (~.image_annotator.ImageSource): + source (google.cloud.vision_v1p4beta1.types.ImageSource): Google Cloud Storage image location, or publicly-accessible image URL. If both ``content`` and ``source`` are provided for an image, ``content`` takes precedence and is used to @@ -194,7 +194,7 @@ class FaceAnnotation(proto.Message): detection. Attributes: - bounding_poly (~.geometry.BoundingPoly): + bounding_poly (google.cloud.vision_v1p4beta1.types.BoundingPoly): The bounding polygon around the face. The coordinates of the bounding box are in the original image's scale. The bounding box is computed to "frame" the face in accordance with human @@ -202,7 +202,7 @@ class FaceAnnotation(proto.Message): that one or more x and/or y coordinates may not be generated in the ``BoundingPoly`` (the polygon will be unbounded) if only a partial face appears in the image to be annotated. - fd_bounding_poly (~.geometry.BoundingPoly): + fd_bounding_poly (google.cloud.vision_v1p4beta1.types.BoundingPoly): The ``fd_bounding_poly`` bounding polygon is tighter than the ``boundingPoly``, and encloses only the skin part of the face. Typically, it is used to eliminate the face from any @@ -210,7 +210,7 @@ class FaceAnnotation(proto.Message): an image. It is not based on the landmarker results, only on the initial face detection, hence the fd (face detection) prefix. - landmarks (Sequence[~.image_annotator.FaceAnnotation.Landmark]): + landmarks (Sequence[google.cloud.vision_v1p4beta1.types.FaceAnnotation.Landmark]): Detected face landmarks. roll_angle (float): Roll angle, which indicates the amount of @@ -229,21 +229,21 @@ class FaceAnnotation(proto.Message): Detection confidence. Range [0, 1]. landmarking_confidence (float): Face landmarking confidence. Range [0, 1]. - joy_likelihood (~.image_annotator.Likelihood): + joy_likelihood (google.cloud.vision_v1p4beta1.types.Likelihood): Joy likelihood. - sorrow_likelihood (~.image_annotator.Likelihood): + sorrow_likelihood (google.cloud.vision_v1p4beta1.types.Likelihood): Sorrow likelihood. - anger_likelihood (~.image_annotator.Likelihood): + anger_likelihood (google.cloud.vision_v1p4beta1.types.Likelihood): Anger likelihood. - surprise_likelihood (~.image_annotator.Likelihood): + surprise_likelihood (google.cloud.vision_v1p4beta1.types.Likelihood): Surprise likelihood. - under_exposed_likelihood (~.image_annotator.Likelihood): + under_exposed_likelihood (google.cloud.vision_v1p4beta1.types.Likelihood): Under-exposed likelihood. - blurred_likelihood (~.image_annotator.Likelihood): + blurred_likelihood (google.cloud.vision_v1p4beta1.types.Likelihood): Blurred likelihood. - headwear_likelihood (~.image_annotator.Likelihood): + headwear_likelihood (google.cloud.vision_v1p4beta1.types.Likelihood): Headwear likelihood. - recognition_result (Sequence[~.face.FaceRecognitionResult]): + recognition_result (Sequence[google.cloud.vision_v1p4beta1.types.FaceRecognitionResult]): Additional recognition information. Only computed if image_context.face_recognition_params is provided, **and** a match is found to a @@ -258,9 +258,9 @@ class Landmark(proto.Message): r"""A face-specific landmark (for example, a face feature). Attributes: - type_ (~.image_annotator.FaceAnnotation.Landmark.Type): + type_ (google.cloud.vision_v1p4beta1.types.FaceAnnotation.Landmark.Type): Face landmark type. - position (~.geometry.Position): + position (google.cloud.vision_v1p4beta1.types.Position): Face landmark position. """ @@ -351,7 +351,7 @@ class LocationInfo(proto.Message): r"""Detected entity location information. Attributes: - lat_lng (~.latlng.LatLng): + lat_lng (google.type.latlng_pb2.LatLng): lat/long location coordinates. """ @@ -406,17 +406,17 @@ class EntityAnnotation(proto.Message): than to an image containing a detected distant towering building, even though the confidence that there is a tower in each image may be the same. Range [0, 1]. - bounding_poly (~.geometry.BoundingPoly): + bounding_poly (google.cloud.vision_v1p4beta1.types.BoundingPoly): Image region to which this entity belongs. Not produced for ``LABEL_DETECTION`` features. - locations (Sequence[~.image_annotator.LocationInfo]): + locations (Sequence[google.cloud.vision_v1p4beta1.types.LocationInfo]): The location information for the detected entity. Multiple ``LocationInfo`` elements can be present because one location may indicate the location of the scene in the image, and another location may indicate the location of the place where the image was taken. Location information is usually present for landmarks. - properties (Sequence[~.image_annotator.Property]): + properties (Sequence[google.cloud.vision_v1p4beta1.types.Property]): Some entities may have optional user-supplied ``Property`` (name/value) fields, such a score or string that qualifies the entity. @@ -456,7 +456,7 @@ class LocalizedObjectAnnotation(proto.Message): Object name, expressed in its ``language_code`` language. score (float): Score of the result. Range [0, 1]. - bounding_poly (~.geometry.BoundingPoly): + bounding_poly (google.cloud.vision_v1p4beta1.types.BoundingPoly): Image region to which this object belongs. This must be populated. """ @@ -478,21 +478,21 @@ class SafeSearchAnnotation(proto.Message): spoof, medical, violence). Attributes: - adult (~.image_annotator.Likelihood): + adult (google.cloud.vision_v1p4beta1.types.Likelihood): Represents the adult content likelihood for the image. Adult content may contain elements such as nudity, pornographic images or cartoons, or sexual activities. - spoof (~.image_annotator.Likelihood): + spoof (google.cloud.vision_v1p4beta1.types.Likelihood): Spoof likelihood. The likelihood that an modification was made to the image's canonical version to make it appear funny or offensive. - medical (~.image_annotator.Likelihood): + medical (google.cloud.vision_v1p4beta1.types.Likelihood): Likelihood that this is a medical image. - violence (~.image_annotator.Likelihood): + violence (google.cloud.vision_v1p4beta1.types.Likelihood): Likelihood that this image contains violent content. - racy (~.image_annotator.Likelihood): + racy (google.cloud.vision_v1p4beta1.types.Likelihood): Likelihood that the request image contains racy content. Racy content may include (but is not limited to) skimpy or sheer clothing, @@ -516,9 +516,9 @@ class LatLongRect(proto.Message): r"""Rectangle determined by min and max ``LatLng`` pairs. Attributes: - min_lat_lng (~.latlng.LatLng): + min_lat_lng (google.type.latlng_pb2.LatLng): Min lat/long pair. - max_lat_lng (~.latlng.LatLng): + max_lat_lng (google.type.latlng_pb2.LatLng): Max lat/long pair. """ @@ -532,7 +532,7 @@ class ColorInfo(proto.Message): fraction of the image that the color occupies in the image. Attributes: - color (~.gt_color.Color): + color (google.type.color_pb2.Color): RGB components of the color. score (float): Image-specific score for this color. Value in range [0, 1]. @@ -552,7 +552,7 @@ class DominantColorsAnnotation(proto.Message): r"""Set of dominant colors and their corresponding scores. Attributes: - colors (Sequence[~.image_annotator.ColorInfo]): + colors (Sequence[google.cloud.vision_v1p4beta1.types.ColorInfo]): RGB color values with their score and pixel fraction. """ @@ -564,7 +564,7 @@ class ImageProperties(proto.Message): r"""Stores image properties, such as dominant colors. Attributes: - dominant_colors (~.image_annotator.DominantColorsAnnotation): + dominant_colors (google.cloud.vision_v1p4beta1.types.DominantColorsAnnotation): If present, dominant colors completed successfully. """ @@ -579,7 +579,7 @@ class CropHint(proto.Message): serving an image. Attributes: - bounding_poly (~.geometry.BoundingPoly): + bounding_poly (google.cloud.vision_v1p4beta1.types.BoundingPoly): The bounding polygon for the crop region. The coordinates of the bounding box are in the original image's scale. @@ -602,7 +602,7 @@ class CropHintsAnnotation(proto.Message): serving images. Attributes: - crop_hints (Sequence[~.image_annotator.CropHint]): + crop_hints (Sequence[google.cloud.vision_v1p4beta1.types.CropHint]): Crop hint results. """ @@ -657,7 +657,7 @@ class ImageContext(proto.Message): r"""Image context and/or feature-specific parameters. Attributes: - lat_long_rect (~.image_annotator.LatLongRect): + lat_long_rect (google.cloud.vision_v1p4beta1.types.LatLongRect): Not used. language_hints (Sequence[str]): List of languages to use for TEXT_DETECTION. In most cases, @@ -670,15 +670,15 @@ class ImageContext(proto.Message): Text detection returns an error if one or more of the specified languages is not one of the `supported languages `__. - crop_hints_params (~.image_annotator.CropHintsParams): + crop_hints_params (google.cloud.vision_v1p4beta1.types.CropHintsParams): Parameters for crop hints annotation request. - face_recognition_params (~.face.FaceRecognitionParams): + face_recognition_params (google.cloud.vision_v1p4beta1.types.FaceRecognitionParams): Parameters for face recognition. - product_search_params (~.product_search.ProductSearchParams): + product_search_params (google.cloud.vision_v1p4beta1.types.ProductSearchParams): Parameters for product search. - web_detection_params (~.image_annotator.WebDetectionParams): + web_detection_params (google.cloud.vision_v1p4beta1.types.WebDetectionParams): Parameters for web detection. - text_detection_params (~.image_annotator.TextDetectionParams): + text_detection_params (google.cloud.vision_v1p4beta1.types.TextDetectionParams): Parameters for text detection and document text detection. """ @@ -712,11 +712,11 @@ class AnnotateImageRequest(proto.Message): context information. Attributes: - image (~.image_annotator.Image): + image (google.cloud.vision_v1p4beta1.types.Image): The image to be processed. - features (Sequence[~.image_annotator.Feature]): + features (Sequence[google.cloud.vision_v1p4beta1.types.Feature]): Requested features. - image_context (~.image_annotator.ImageContext): + image_context (google.cloud.vision_v1p4beta1.types.ImageContext): Additional context that may accompany the image. """ @@ -751,50 +751,50 @@ class AnnotateImageResponse(proto.Message): r"""Response to an image annotation request. Attributes: - face_annotations (Sequence[~.image_annotator.FaceAnnotation]): + face_annotations (Sequence[google.cloud.vision_v1p4beta1.types.FaceAnnotation]): If present, face detection has completed successfully. - landmark_annotations (Sequence[~.image_annotator.EntityAnnotation]): + landmark_annotations (Sequence[google.cloud.vision_v1p4beta1.types.EntityAnnotation]): If present, landmark detection has completed successfully. - logo_annotations (Sequence[~.image_annotator.EntityAnnotation]): + logo_annotations (Sequence[google.cloud.vision_v1p4beta1.types.EntityAnnotation]): If present, logo detection has completed successfully. - label_annotations (Sequence[~.image_annotator.EntityAnnotation]): + label_annotations (Sequence[google.cloud.vision_v1p4beta1.types.EntityAnnotation]): If present, label detection has completed successfully. - localized_object_annotations (Sequence[~.image_annotator.LocalizedObjectAnnotation]): + localized_object_annotations (Sequence[google.cloud.vision_v1p4beta1.types.LocalizedObjectAnnotation]): If present, localized object detection has completed successfully. This will be sorted descending by confidence score. - text_annotations (Sequence[~.image_annotator.EntityAnnotation]): + text_annotations (Sequence[google.cloud.vision_v1p4beta1.types.EntityAnnotation]): If present, text (OCR) detection has completed successfully. - full_text_annotation (~.text_annotation.TextAnnotation): + full_text_annotation (google.cloud.vision_v1p4beta1.types.TextAnnotation): If present, text (OCR) detection or document (OCR) text detection has completed successfully. This annotation provides the structural hierarchy for the OCR detected text. - safe_search_annotation (~.image_annotator.SafeSearchAnnotation): + safe_search_annotation (google.cloud.vision_v1p4beta1.types.SafeSearchAnnotation): If present, safe-search annotation has completed successfully. - image_properties_annotation (~.image_annotator.ImageProperties): + image_properties_annotation (google.cloud.vision_v1p4beta1.types.ImageProperties): If present, image properties were extracted successfully. - crop_hints_annotation (~.image_annotator.CropHintsAnnotation): + crop_hints_annotation (google.cloud.vision_v1p4beta1.types.CropHintsAnnotation): If present, crop hints have completed successfully. - web_detection (~.gcv_web_detection.WebDetection): + web_detection (google.cloud.vision_v1p4beta1.types.WebDetection): If present, web detection has completed successfully. - product_search_results (~.product_search.ProductSearchResults): + product_search_results (google.cloud.vision_v1p4beta1.types.ProductSearchResults): If present, product search has completed successfully. - error (~.status.Status): + error (google.rpc.status_pb2.Status): If set, represents the error message for the operation. Note that filled-in image annotations are guaranteed to be correct, even when ``error`` is set. - context (~.image_annotator.ImageAnnotationContext): + context (google.cloud.vision_v1p4beta1.types.ImageAnnotationContext): If present, contextual information is needed to understand where this image comes from. """ @@ -857,7 +857,7 @@ class BatchAnnotateImagesRequest(proto.Message): service call. Attributes: - requests (Sequence[~.image_annotator.AnnotateImageRequest]): + requests (Sequence[google.cloud.vision_v1p4beta1.types.AnnotateImageRequest]): Required. Individual image annotation requests for this batch. """ @@ -871,7 +871,7 @@ class BatchAnnotateImagesResponse(proto.Message): r"""Response to a batch image annotation request. Attributes: - responses (Sequence[~.image_annotator.AnnotateImageResponse]): + responses (Sequence[google.cloud.vision_v1p4beta1.types.AnnotateImageResponse]): Individual responses to image annotation requests within the batch. """ @@ -886,11 +886,11 @@ class AnnotateFileRequest(proto.Message): GIF file. Attributes: - input_config (~.image_annotator.InputConfig): + input_config (google.cloud.vision_v1p4beta1.types.InputConfig): Required. Information about the input file. - features (Sequence[~.image_annotator.Feature]): + features (Sequence[google.cloud.vision_v1p4beta1.types.Feature]): Required. Requested features. - image_context (~.image_annotator.ImageContext): + image_context (google.cloud.vision_v1p4beta1.types.ImageContext): Additional context that may accompany the image(s) in the file. pages (Sequence[int]): @@ -926,16 +926,16 @@ class AnnotateFileResponse(proto.Message): responses. Attributes: - input_config (~.image_annotator.InputConfig): + input_config (google.cloud.vision_v1p4beta1.types.InputConfig): Information about the file for which this response is generated. - responses (Sequence[~.image_annotator.AnnotateImageResponse]): + responses (Sequence[google.cloud.vision_v1p4beta1.types.AnnotateImageResponse]): Individual responses to images found within the file. This field will be empty if the ``error`` field is set. total_pages (int): This field gives the total number of pages in the file. - error (~.status.Status): + error (google.rpc.status_pb2.Status): If set, represents the error message for the failed request. The ``responses`` field will not be set in this case. """ @@ -956,7 +956,7 @@ class BatchAnnotateFilesRequest(proto.Message): BatchAnnotateFiles API. Attributes: - requests (Sequence[~.image_annotator.AnnotateFileRequest]): + requests (Sequence[google.cloud.vision_v1p4beta1.types.AnnotateFileRequest]): Required. The list of file annotation requests. Right now we support only one AnnotateFileRequest in @@ -972,7 +972,7 @@ class BatchAnnotateFilesResponse(proto.Message): r"""A list of file annotation responses. Attributes: - responses (Sequence[~.image_annotator.AnnotateFileResponse]): + responses (Sequence[google.cloud.vision_v1p4beta1.types.AnnotateFileResponse]): The list of file annotation responses, each response corresponding to each AnnotateFileRequest in @@ -988,14 +988,14 @@ class AsyncAnnotateFileRequest(proto.Message): r"""An offline file annotation request. Attributes: - input_config (~.image_annotator.InputConfig): + input_config (google.cloud.vision_v1p4beta1.types.InputConfig): Required. Information about the input file. - features (Sequence[~.image_annotator.Feature]): + features (Sequence[google.cloud.vision_v1p4beta1.types.Feature]): Required. Requested features. - image_context (~.image_annotator.ImageContext): + image_context (google.cloud.vision_v1p4beta1.types.ImageContext): Additional context that may accompany the image(s) in the file. - output_config (~.image_annotator.OutputConfig): + output_config (google.cloud.vision_v1p4beta1.types.OutputConfig): Required. The desired output location and metadata (e.g. format). """ @@ -1013,7 +1013,7 @@ class AsyncAnnotateFileResponse(proto.Message): r"""The response for a single offline file annotation request. Attributes: - output_config (~.image_annotator.OutputConfig): + output_config (google.cloud.vision_v1p4beta1.types.OutputConfig): The output location and metadata from AsyncAnnotateFileRequest. """ @@ -1025,10 +1025,10 @@ class AsyncBatchAnnotateImagesRequest(proto.Message): r"""Request for async image annotation for a list of images. Attributes: - requests (Sequence[~.image_annotator.AnnotateImageRequest]): + requests (Sequence[google.cloud.vision_v1p4beta1.types.AnnotateImageRequest]): Required. Individual image annotation requests for this batch. - output_config (~.image_annotator.OutputConfig): + output_config (google.cloud.vision_v1p4beta1.types.OutputConfig): Required. The desired output location and metadata (e.g. format). """ @@ -1044,7 +1044,7 @@ class AsyncBatchAnnotateImagesResponse(proto.Message): r"""Response to an async batch image annotation request. Attributes: - output_config (~.image_annotator.OutputConfig): + output_config (google.cloud.vision_v1p4beta1.types.OutputConfig): The output location and metadata from AsyncBatchAnnotateImagesRequest. """ @@ -1057,7 +1057,7 @@ class AsyncBatchAnnotateFilesRequest(proto.Message): single service call. Attributes: - requests (Sequence[~.image_annotator.AsyncAnnotateFileRequest]): + requests (Sequence[google.cloud.vision_v1p4beta1.types.AsyncAnnotateFileRequest]): Required. Individual async file annotation requests for this batch. """ @@ -1071,7 +1071,7 @@ class AsyncBatchAnnotateFilesResponse(proto.Message): r"""Response to an async batch file annotation request. Attributes: - responses (Sequence[~.image_annotator.AsyncAnnotateFileResponse]): + responses (Sequence[google.cloud.vision_v1p4beta1.types.AsyncAnnotateFileResponse]): The list of file annotation responses, one for each request in AsyncBatchAnnotateFilesRequest. @@ -1086,7 +1086,7 @@ class InputConfig(proto.Message): r"""The desired input location and metadata. Attributes: - gcs_source (~.image_annotator.GcsSource): + gcs_source (google.cloud.vision_v1p4beta1.types.GcsSource): The Google Cloud Storage location to read the input from. content (bytes): @@ -1114,7 +1114,7 @@ class OutputConfig(proto.Message): r"""The desired output location and metadata. Attributes: - gcs_destination (~.image_annotator.GcsDestination): + gcs_destination (google.cloud.vision_v1p4beta1.types.GcsDestination): The Google Cloud Storage location to write the output(s) to. batch_size (int): @@ -1191,11 +1191,11 @@ class OperationMetadata(proto.Message): r"""Contains metadata for the BatchAnnotateImages operation. Attributes: - state (~.image_annotator.OperationMetadata.State): + state (google.cloud.vision_v1p4beta1.types.OperationMetadata.State): Current state of the batch operation. - create_time (~.timestamp.Timestamp): + create_time (google.protobuf.timestamp_pb2.Timestamp): The time when the batch request was received. - update_time (~.timestamp.Timestamp): + update_time (google.protobuf.timestamp_pb2.Timestamp): The time when the operation result was last updated. """ diff --git a/google/cloud/vision_v1p4beta1/types/product_search.py b/google/cloud/vision_v1p4beta1/types/product_search.py index e16037c9..f0aa53b8 100644 --- a/google/cloud/vision_v1p4beta1/types/product_search.py +++ b/google/cloud/vision_v1p4beta1/types/product_search.py @@ -33,7 +33,7 @@ class ProductSearchParams(proto.Message): r"""Parameters for a product search request. Attributes: - bounding_poly (~.geometry.BoundingPoly): + bounding_poly (google.cloud.vision_v1p4beta1.types.BoundingPoly): The bounding polygon around the area of interest in the image. If it is not specified, system discretion will be applied. @@ -83,14 +83,14 @@ class ProductSearchResults(proto.Message): r"""Results for a product search request. Attributes: - index_time (~.timestamp.Timestamp): + index_time (google.protobuf.timestamp_pb2.Timestamp): Timestamp of the index which provided these results. Products added to the product set and products removed from the product set after this time are not reflected in the current results. - results (Sequence[~.product_search.ProductSearchResults.Result]): + results (Sequence[google.cloud.vision_v1p4beta1.types.ProductSearchResults.Result]): List of results, one for each product match. - product_grouped_results (Sequence[~.product_search.ProductSearchResults.GroupedResult]): + product_grouped_results (Sequence[google.cloud.vision_v1p4beta1.types.ProductSearchResults.GroupedResult]): List of results grouped by products detected in the query image. Each entry corresponds to one bounding polygon in the query image, and @@ -103,7 +103,7 @@ class Result(proto.Message): r"""Information about a product. Attributes: - product (~.product_search_service.Product): + product (google.cloud.vision_v1p4beta1.types.Product): The Product. score (float): A confidence level on the match, ranging from @@ -151,12 +151,12 @@ class GroupedResult(proto.Message): a query image. Attributes: - bounding_poly (~.geometry.BoundingPoly): + bounding_poly (google.cloud.vision_v1p4beta1.types.BoundingPoly): The bounding polygon around the product detected in the query image. - results (Sequence[~.product_search.ProductSearchResults.Result]): + results (Sequence[google.cloud.vision_v1p4beta1.types.ProductSearchResults.Result]): List of results, one for each product match. - object_annotations (Sequence[~.product_search.ProductSearchResults.ObjectAnnotation]): + object_annotations (Sequence[google.cloud.vision_v1p4beta1.types.ProductSearchResults.ObjectAnnotation]): List of generic predictions for the object in the bounding box. """ diff --git a/google/cloud/vision_v1p4beta1/types/product_search_service.py b/google/cloud/vision_v1p4beta1/types/product_search_service.py index 598c868d..25df6719 100644 --- a/google/cloud/vision_v1p4beta1/types/product_search_service.py +++ b/google/cloud/vision_v1p4beta1/types/product_search_service.py @@ -87,7 +87,7 @@ class Product(proto.Message): "toys-v2". The legacy categories "homegoods", "apparel", and "toys" are still supported, but these should not be used for new products. - product_labels (Sequence[~.product_search_service.Product.KeyValue]): + product_labels (Sequence[google.cloud.vision_v1p4beta1.types.Product.KeyValue]): Key-value pairs that can be attached to a product. At query time, constraints can be specified based on the product_labels. @@ -150,7 +150,7 @@ class ProductSet(proto.Message): The user-provided name for this ProductSet. Must not be empty. Must be at most 4096 characters long. - index_time (~.timestamp.Timestamp): + index_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The time at which this ProductSet was last indexed. Query results will reflect all updates before this time. If this @@ -160,7 +160,7 @@ class ProductSet(proto.Message): This field is ignored when creating a ProductSet. - index_error (~.status.Status): + index_error (google.rpc.status_pb2.Status): Output only. If there was an error with indexing the product set, the field is populated. @@ -195,7 +195,7 @@ class ReferenceImage(proto.Message): image. The URI must start with ``gs://``. - bounding_polys (Sequence[~.geometry.BoundingPoly]): + bounding_polys (Sequence[google.cloud.vision_v1p4beta1.types.BoundingPoly]): Optional. Bounding polygons around the areas of interest in the reference image. If this field is empty, the system will try to detect @@ -226,7 +226,7 @@ class CreateProductRequest(proto.Message): created. Format is ``projects/PROJECT_ID/locations/LOC_ID``. - product (~.product_search_service.Product): + product (google.cloud.vision_v1p4beta1.types.Product): Required. The product to create. product_id (str): A user-supplied resource id for this Product. If set, the @@ -271,7 +271,7 @@ class ListProductsResponse(proto.Message): r"""Response message for the ``ListProducts`` method. Attributes: - products (Sequence[~.product_search_service.Product]): + products (Sequence[google.cloud.vision_v1p4beta1.types.Product]): List of products. next_page_token (str): Token to retrieve the next page of results, @@ -306,11 +306,11 @@ class UpdateProductRequest(proto.Message): r"""Request message for the ``UpdateProduct`` method. Attributes: - product (~.product_search_service.Product): + product (google.cloud.vision_v1p4beta1.types.Product): Required. The Product resource which replaces the one on the server. product.name is immutable. - update_mask (~.field_mask.FieldMask): + update_mask (google.protobuf.field_mask_pb2.FieldMask): The [FieldMask][google.protobuf.FieldMask] that specifies which fields to update. If update_mask isn't specified, all mutable fields are to be updated. Valid mask paths include @@ -345,7 +345,7 @@ class CreateProductSetRequest(proto.Message): created. Format is ``projects/PROJECT_ID/locations/LOC_ID``. - product_set (~.product_search_service.ProductSet): + product_set (google.cloud.vision_v1p4beta1.types.ProductSet): Required. The ProductSet to create. product_set_id (str): A user-supplied resource id for this ProductSet. If set, the @@ -390,7 +390,7 @@ class ListProductSetsResponse(proto.Message): r"""Response message for the ``ListProductSets`` method. Attributes: - product_sets (Sequence[~.product_search_service.ProductSet]): + product_sets (Sequence[google.cloud.vision_v1p4beta1.types.ProductSet]): List of ProductSets. next_page_token (str): Token to retrieve the next page of results, @@ -425,10 +425,10 @@ class UpdateProductSetRequest(proto.Message): r"""Request message for the ``UpdateProductSet`` method. Attributes: - product_set (~.product_search_service.ProductSet): + product_set (google.cloud.vision_v1p4beta1.types.ProductSet): Required. The ProductSet resource which replaces the one on the server. - update_mask (~.field_mask.FieldMask): + update_mask (google.protobuf.field_mask_pb2.FieldMask): The [FieldMask][google.protobuf.FieldMask] that specifies which fields to update. If update_mask isn't specified, all mutable fields are to be updated. Valid mask path is @@ -464,7 +464,7 @@ class CreateReferenceImageRequest(proto.Message): Format is ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. - reference_image (~.product_search_service.ReferenceImage): + reference_image (google.cloud.vision_v1p4beta1.types.ReferenceImage): Required. The reference image to create. If an image ID is specified, it is ignored. reference_image_id (str): @@ -514,7 +514,7 @@ class ListReferenceImagesResponse(proto.Message): r"""Response message for the ``ListReferenceImages`` method. Attributes: - reference_images (Sequence[~.product_search_service.ReferenceImage]): + reference_images (Sequence[google.cloud.vision_v1p4beta1.types.ReferenceImage]): The list of reference images. page_size (int): The maximum number of items to return. @@ -641,7 +641,7 @@ class ListProductsInProductSetResponse(proto.Message): r"""Response message for the ``ListProductsInProductSet`` method. Attributes: - products (Sequence[~.product_search_service.Product]): + products (Sequence[google.cloud.vision_v1p4beta1.types.Product]): The list of Products. next_page_token (str): Token to retrieve the next page of results, @@ -746,7 +746,7 @@ class ImportProductSetsInputConfig(proto.Message): r"""The input content for the ``ImportProductSets`` method. Attributes: - gcs_source (~.product_search_service.ImportProductSetsGcsSource): + gcs_source (google.cloud.vision_v1p4beta1.types.ImportProductSetsGcsSource): The Google Cloud Storage location for a csv file which preserves a list of ImportProductSetRequests in each line. @@ -766,7 +766,7 @@ class ImportProductSetsRequest(proto.Message): imported. Format is ``projects/PROJECT_ID/locations/LOC_ID``. - input_config (~.product_search_service.ImportProductSetsInputConfig): + input_config (google.cloud.vision_v1p4beta1.types.ImportProductSetsInputConfig): Required. The input content for the list of requests. """ @@ -788,9 +788,9 @@ class ImportProductSetsResponse(proto.Message): field. Attributes: - reference_images (Sequence[~.product_search_service.ReferenceImage]): + reference_images (Sequence[google.cloud.vision_v1p4beta1.types.ReferenceImage]): The list of reference_images that are imported successfully. - statuses (Sequence[~.status.Status]): + statuses (Sequence[google.rpc.status_pb2.Status]): The rpc status for each ImportProductSet request, including both successes and errors. @@ -815,12 +815,12 @@ class BatchOperationMetadata(proto.Message): ``google::longrunning::Operations`` service. Attributes: - state (~.product_search_service.BatchOperationMetadata.State): + state (google.cloud.vision_v1p4beta1.types.BatchOperationMetadata.State): The current state of the batch operation. - submit_time (~.timestamp.Timestamp): + submit_time (google.protobuf.timestamp_pb2.Timestamp): The time when the batch request was submitted to the server. - end_time (~.timestamp.Timestamp): + end_time (google.protobuf.timestamp_pb2.Timestamp): The time when the batch request is finished and [google.longrunning.Operation.done][google.longrunning.Operation.done] is set to true. @@ -861,7 +861,7 @@ class PurgeProductsRequest(proto.Message): r"""Request message for the ``PurgeProducts`` method. Attributes: - product_set_purge_config (~.product_search_service.ProductSetPurgeConfig): + product_set_purge_config (google.cloud.vision_v1p4beta1.types.ProductSetPurgeConfig): Specify which ProductSet contains the Products to be deleted. delete_orphan_products (bool): diff --git a/google/cloud/vision_v1p4beta1/types/text_annotation.py b/google/cloud/vision_v1p4beta1/types/text_annotation.py index 25c4f0c9..ee384d68 100644 --- a/google/cloud/vision_v1p4beta1/types/text_annotation.py +++ b/google/cloud/vision_v1p4beta1/types/text_annotation.py @@ -38,7 +38,7 @@ class TextAnnotation(proto.Message): message definition below for more detail. Attributes: - pages (Sequence[~.text_annotation.Page]): + pages (Sequence[google.cloud.vision_v1p4beta1.types.Page]): List of pages detected by OCR. text (str): UTF-8 text detected on the pages. @@ -64,7 +64,7 @@ class DetectedBreak(proto.Message): r"""Detected start or end of a structural component. Attributes: - type_ (~.text_annotation.TextAnnotation.DetectedBreak.BreakType): + type_ (google.cloud.vision_v1p4beta1.types.TextAnnotation.DetectedBreak.BreakType): Detected break type. is_prefix (bool): True if break prepends the element. @@ -89,10 +89,10 @@ class TextProperty(proto.Message): r"""Additional information detected on the structural component. Attributes: - detected_languages (Sequence[~.text_annotation.TextAnnotation.DetectedLanguage]): + detected_languages (Sequence[google.cloud.vision_v1p4beta1.types.TextAnnotation.DetectedLanguage]): A list of detected languages together with confidence. - detected_break (~.text_annotation.TextAnnotation.DetectedBreak): + detected_break (google.cloud.vision_v1p4beta1.types.TextAnnotation.DetectedBreak): Detected start or end of a text segment. """ @@ -113,7 +113,7 @@ class Page(proto.Message): r"""Detected page from OCR. Attributes: - property (~.text_annotation.TextAnnotation.TextProperty): + property (google.cloud.vision_v1p4beta1.types.TextAnnotation.TextProperty): Additional information detected on the page. width (int): Page width. For PDFs the unit is points. For @@ -121,7 +121,7 @@ class Page(proto.Message): height (int): Page height. For PDFs the unit is points. For images (including TIFFs) the unit is pixels. - blocks (Sequence[~.text_annotation.Block]): + blocks (Sequence[google.cloud.vision_v1p4beta1.types.Block]): List of blocks of text, images etc on this page. confidence (float): @@ -145,10 +145,10 @@ class Block(proto.Message): r"""Logical element on the page. Attributes: - property (~.text_annotation.TextAnnotation.TextProperty): + property (google.cloud.vision_v1p4beta1.types.TextAnnotation.TextProperty): Additional information detected for the block. - bounding_box (~.geometry.BoundingPoly): + bounding_box (google.cloud.vision_v1p4beta1.types.BoundingPoly): The bounding box for the block. The vertices are in the order of top-left, top-right, bottom-right, bottom-left. When a rotation of the bounding box is detected the rotation @@ -173,10 +173,10 @@ class Block(proto.Message): 1----0 and the vertex order will still be (0, 1, 2, 3). - paragraphs (Sequence[~.text_annotation.Paragraph]): + paragraphs (Sequence[google.cloud.vision_v1p4beta1.types.Paragraph]): List of paragraphs in this block (if this blocks is of type text). - block_type (~.text_annotation.Block.BlockType): + block_type (google.cloud.vision_v1p4beta1.types.Block.BlockType): Detected block type (text, image etc) for this block. confidence (float): @@ -210,10 +210,10 @@ class Paragraph(proto.Message): certain order. Attributes: - property (~.text_annotation.TextAnnotation.TextProperty): + property (google.cloud.vision_v1p4beta1.types.TextAnnotation.TextProperty): Additional information detected for the paragraph. - bounding_box (~.geometry.BoundingPoly): + bounding_box (google.cloud.vision_v1p4beta1.types.BoundingPoly): The bounding box for the paragraph. The vertices are in the order of top-left, top-right, bottom-right, bottom-left. When a rotation of the bounding box is detected the rotation @@ -225,7 +225,7 @@ class Paragraph(proto.Message): - when it's rotated 180 degrees around the top-left corner it becomes: 2----3 \| \| 1----0 and the vertex order will still be (0, 1, 2, 3). - words (Sequence[~.text_annotation.Word]): + words (Sequence[google.cloud.vision_v1p4beta1.types.Word]): List of all words in this paragraph. confidence (float): Confidence of the OCR results for the paragraph. Range [0, @@ -247,9 +247,9 @@ class Word(proto.Message): r"""A word representation. Attributes: - property (~.text_annotation.TextAnnotation.TextProperty): + property (google.cloud.vision_v1p4beta1.types.TextAnnotation.TextProperty): Additional information detected for the word. - bounding_box (~.geometry.BoundingPoly): + bounding_box (google.cloud.vision_v1p4beta1.types.BoundingPoly): The bounding box for the word. The vertices are in the order of top-left, top-right, bottom-right, bottom-left. When a rotation of the bounding box is detected the rotation is @@ -261,7 +261,7 @@ class Word(proto.Message): - when it's rotated 180 degrees around the top-left corner it becomes: 2----3 \| \| 1----0 and the vertex order will still be (0, 1, 2, 3). - symbols (Sequence[~.text_annotation.Symbol]): + symbols (Sequence[google.cloud.vision_v1p4beta1.types.Symbol]): List of symbols in the word. The order of the symbols follows the natural reading order. @@ -284,10 +284,10 @@ class Symbol(proto.Message): r"""A single symbol representation. Attributes: - property (~.text_annotation.TextAnnotation.TextProperty): + property (google.cloud.vision_v1p4beta1.types.TextAnnotation.TextProperty): Additional information detected for the symbol. - bounding_box (~.geometry.BoundingPoly): + bounding_box (google.cloud.vision_v1p4beta1.types.BoundingPoly): The bounding box for the symbol. The vertices are in the order of top-left, top-right, bottom-right, bottom-left. When a rotation of the bounding box is detected the rotation diff --git a/google/cloud/vision_v1p4beta1/types/web_detection.py b/google/cloud/vision_v1p4beta1/types/web_detection.py index 344fd0b0..c9efe25e 100644 --- a/google/cloud/vision_v1p4beta1/types/web_detection.py +++ b/google/cloud/vision_v1p4beta1/types/web_detection.py @@ -27,24 +27,24 @@ class WebDetection(proto.Message): r"""Relevant information for the image from the Internet. Attributes: - web_entities (Sequence[~.web_detection.WebDetection.WebEntity]): + web_entities (Sequence[google.cloud.vision_v1p4beta1.types.WebDetection.WebEntity]): Deduced entities from similar images on the Internet. - full_matching_images (Sequence[~.web_detection.WebDetection.WebImage]): + full_matching_images (Sequence[google.cloud.vision_v1p4beta1.types.WebDetection.WebImage]): Fully matching images from the Internet. Can include resized copies of the query image. - partial_matching_images (Sequence[~.web_detection.WebDetection.WebImage]): + partial_matching_images (Sequence[google.cloud.vision_v1p4beta1.types.WebDetection.WebImage]): Partial matching images from the Internet. Those images are similar enough to share some key-point features. For example an original image will likely have partial matching for its crops. - pages_with_matching_images (Sequence[~.web_detection.WebDetection.WebPage]): + pages_with_matching_images (Sequence[google.cloud.vision_v1p4beta1.types.WebDetection.WebPage]): Web pages containing the matching images from the Internet. - visually_similar_images (Sequence[~.web_detection.WebDetection.WebImage]): + visually_similar_images (Sequence[google.cloud.vision_v1p4beta1.types.WebDetection.WebImage]): The visually similar image results. - best_guess_labels (Sequence[~.web_detection.WebDetection.WebLabel]): + best_guess_labels (Sequence[google.cloud.vision_v1p4beta1.types.WebDetection.WebLabel]): The service's best guess as to the topic of the request image. Inferred from similar images on the open web. @@ -98,10 +98,10 @@ class WebPage(proto.Message): page_title (str): Title for the web page, may contain HTML markups. - full_matching_images (Sequence[~.web_detection.WebDetection.WebImage]): + full_matching_images (Sequence[google.cloud.vision_v1p4beta1.types.WebDetection.WebImage]): Fully matching images on the page. Can include resized copies of the query image. - partial_matching_images (Sequence[~.web_detection.WebDetection.WebImage]): + partial_matching_images (Sequence[google.cloud.vision_v1p4beta1.types.WebDetection.WebImage]): Partial matching images on the page. Those images are similar enough to share some key-point features. For example an original diff --git a/synth.metadata b/synth.metadata index a706fe1a..d168bcaa 100644 --- a/synth.metadata +++ b/synth.metadata @@ -4,15 +4,15 @@ "git": { "name": ".", "remote": "https://github.com/googleapis/python-vision.git", - "sha": "62f5df93426f6d7fd796a470c2fa049f90dd56ed" + "sha": "2fa6dcd06b59debf1dba80e7061c83e3e3f972a9" } }, { "git": { "name": "googleapis", "remote": "https://github.com/googleapis/googleapis.git", - "sha": "dd372aa22ded7a8ba6f0e03a80e06358a3fa0907", - "internalRef": "347055288" + "sha": "e28aa8570dc86136fe677202c976f4ee00d77f61", + "internalRef": "356624136" } }, { @@ -131,12 +131,19 @@ "docs/_templates/layout.html", "docs/conf.py", "docs/multiprocessing.rst", + "docs/vision_v1/image_annotator.rst", + "docs/vision_v1/product_search.rst", "docs/vision_v1/services.rst", "docs/vision_v1/types.rst", + "docs/vision_v1p2beta1/image_annotator.rst", "docs/vision_v1p2beta1/services.rst", "docs/vision_v1p2beta1/types.rst", + "docs/vision_v1p3beta1/image_annotator.rst", + "docs/vision_v1p3beta1/product_search.rst", "docs/vision_v1p3beta1/services.rst", "docs/vision_v1p3beta1/types.rst", + "docs/vision_v1p4beta1/image_annotator.rst", + "docs/vision_v1p4beta1/product_search.rst", "docs/vision_v1p4beta1/services.rst", "docs/vision_v1p4beta1/types.rst", "google/cloud/vision/__init__.py", diff --git a/tests/unit/gapic/vision_v1/test_image_annotator.py b/tests/unit/gapic/vision_v1/test_image_annotator.py index 7e39be07..a14cf483 100644 --- a/tests/unit/gapic/vision_v1/test_image_annotator.py +++ b/tests/unit/gapic/vision_v1/test_image_annotator.py @@ -90,8 +90,21 @@ def test__get_default_mtls_endpoint(): ) +def test_image_annotator_client_from_service_account_info(): + creds = credentials.AnonymousCredentials() + with mock.patch.object( + service_account.Credentials, "from_service_account_info" + ) as factory: + factory.return_value = creds + info = {"valid": True} + client = ImageAnnotatorClient.from_service_account_info(info) + assert client.transport._credentials == creds + + assert client.transport._host == "vision.googleapis.com:443" + + @pytest.mark.parametrize( - "client_class", [ImageAnnotatorClient, ImageAnnotatorAsyncClient] + "client_class", [ImageAnnotatorClient, ImageAnnotatorAsyncClient,] ) def test_image_annotator_client_from_service_account_file(client_class): creds = credentials.AnonymousCredentials() @@ -110,7 +123,10 @@ def test_image_annotator_client_from_service_account_file(client_class): def test_image_annotator_client_get_transport_class(): transport = ImageAnnotatorClient.get_transport_class() - assert transport == transports.ImageAnnotatorGrpcTransport + available_transports = [ + transports.ImageAnnotatorGrpcTransport, + ] + assert transport in available_transports transport = ImageAnnotatorClient.get_transport_class("grpc") assert transport == transports.ImageAnnotatorGrpcTransport @@ -161,7 +177,7 @@ def test_image_annotator_client_client_options( credentials_file=None, host="squid.clam.whelk", scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -177,7 +193,7 @@ def test_image_annotator_client_client_options( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -193,7 +209,7 @@ def test_image_annotator_client_client_options( credentials_file=None, host=client.DEFAULT_MTLS_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -221,7 +237,7 @@ def test_image_annotator_client_client_options( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -272,29 +288,25 @@ def test_image_annotator_client_mtls_env_auto( client_cert_source=client_cert_source_callback ) with mock.patch.object(transport_class, "__init__") as patched: - ssl_channel_creds = mock.Mock() - with mock.patch( - "grpc.ssl_channel_credentials", return_value=ssl_channel_creds - ): - patched.return_value = None - client = client_class(client_options=options) + patched.return_value = None + client = client_class(client_options=options) - if use_client_cert_env == "false": - expected_ssl_channel_creds = None - expected_host = client.DEFAULT_ENDPOINT - else: - expected_ssl_channel_creds = ssl_channel_creds - expected_host = client.DEFAULT_MTLS_ENDPOINT + if use_client_cert_env == "false": + expected_client_cert_source = None + expected_host = client.DEFAULT_ENDPOINT + else: + expected_client_cert_source = client_cert_source_callback + expected_host = client.DEFAULT_MTLS_ENDPOINT - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - ssl_channel_credentials=expected_ssl_channel_creds, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) # Check the case ADC client cert is provided. Whether client cert is used depends on # GOOGLE_API_USE_CLIENT_CERTIFICATE value. @@ -303,66 +315,53 @@ def test_image_annotator_client_mtls_env_auto( ): with mock.patch.object(transport_class, "__init__") as patched: with mock.patch( - "google.auth.transport.grpc.SslCredentials.__init__", return_value=None + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, ): with mock.patch( - "google.auth.transport.grpc.SslCredentials.is_mtls", - new_callable=mock.PropertyMock, - ) as is_mtls_mock: - with mock.patch( - "google.auth.transport.grpc.SslCredentials.ssl_credentials", - new_callable=mock.PropertyMock, - ) as ssl_credentials_mock: - if use_client_cert_env == "false": - is_mtls_mock.return_value = False - ssl_credentials_mock.return_value = None - expected_host = client.DEFAULT_ENDPOINT - expected_ssl_channel_creds = None - else: - is_mtls_mock.return_value = True - ssl_credentials_mock.return_value = mock.Mock() - expected_host = client.DEFAULT_MTLS_ENDPOINT - expected_ssl_channel_creds = ( - ssl_credentials_mock.return_value - ) - - patched.return_value = None - client = client_class() - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - ssl_channel_credentials=expected_ssl_channel_creds, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) + "google.auth.transport.mtls.default_client_cert_source", + return_value=client_cert_source_callback, + ): + if use_client_cert_env == "false": + expected_host = client.DEFAULT_ENDPOINT + expected_client_cert_source = None + else: + expected_host = client.DEFAULT_MTLS_ENDPOINT + expected_client_cert_source = client_cert_source_callback - # Check the case client_cert_source and ADC client cert are not provided. - with mock.patch.dict( - os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} - ): - with mock.patch.object(transport_class, "__init__") as patched: - with mock.patch( - "google.auth.transport.grpc.SslCredentials.__init__", return_value=None - ): - with mock.patch( - "google.auth.transport.grpc.SslCredentials.is_mtls", - new_callable=mock.PropertyMock, - ) as is_mtls_mock: - is_mtls_mock.return_value = False patched.return_value = None client = client_class() patched.assert_called_once_with( credentials=None, credentials_file=None, - host=client.DEFAULT_ENDPOINT, + host=expected_host, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) + # Check the case client_cert_source and ADC client cert are not provided. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + with mock.patch.object(transport_class, "__init__") as patched: + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -388,7 +387,7 @@ def test_image_annotator_client_client_options_scopes( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=["1", "2"], - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -418,7 +417,7 @@ def test_image_annotator_client_client_options_credentials_file( credentials_file="credentials.json", host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -437,7 +436,7 @@ def test_image_annotator_client_client_options_from_dict(): credentials_file=None, host="squid.clam.whelk", scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -1362,6 +1361,54 @@ def test_image_annotator_transport_auth_adc(): ) +@pytest.mark.parametrize( + "transport_class", + [ + transports.ImageAnnotatorGrpcTransport, + transports.ImageAnnotatorGrpcAsyncIOTransport, + ], +) +def test_image_annotator_grpc_transport_client_cert_source_for_mtls(transport_class): + cred = credentials.AnonymousCredentials() + + # Check ssl_channel_credentials is used if provided. + with mock.patch.object(transport_class, "create_channel") as mock_create_channel: + mock_ssl_channel_creds = mock.Mock() + transport_class( + host="squid.clam.whelk", + credentials=cred, + ssl_channel_credentials=mock_ssl_channel_creds, + ) + mock_create_channel.assert_called_once_with( + "squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=( + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/cloud-vision", + ), + ssl_credentials=mock_ssl_channel_creds, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls + # is used. + with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): + with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: + transport_class( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback, + ) + expected_cert, expected_key = client_cert_source_callback() + mock_ssl_cred.assert_called_once_with( + certificate_chain=expected_cert, private_key=expected_key + ) + + def test_image_annotator_host_no_port(): client = ImageAnnotatorClient( credentials=credentials.AnonymousCredentials(), @@ -1383,7 +1430,7 @@ def test_image_annotator_host_with_port(): def test_image_annotator_grpc_transport_channel(): - channel = grpc.insecure_channel("http://localhost/") + channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.ImageAnnotatorGrpcTransport( @@ -1395,7 +1442,7 @@ def test_image_annotator_grpc_transport_channel(): def test_image_annotator_grpc_asyncio_transport_channel(): - channel = aio.insecure_channel("http://localhost/") + channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.ImageAnnotatorGrpcAsyncIOTransport( @@ -1406,6 +1453,8 @@ def test_image_annotator_grpc_asyncio_transport_channel(): assert transport._ssl_channel_credentials == None +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. @pytest.mark.parametrize( "transport_class", [ @@ -1420,7 +1469,7 @@ def test_image_annotator_transport_channel_mtls_with_client_cert_source( "grpc.ssl_channel_credentials", autospec=True ) as grpc_ssl_channel_cred: with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_ssl_cred = mock.Mock() grpc_ssl_channel_cred.return_value = mock_ssl_cred @@ -1461,6 +1510,8 @@ def test_image_annotator_transport_channel_mtls_with_client_cert_source( assert transport._ssl_channel_credentials == mock_ssl_cred +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. @pytest.mark.parametrize( "transport_class", [ @@ -1476,7 +1527,7 @@ def test_image_annotator_transport_channel_mtls_with_adc(transport_class): ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), ): with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel diff --git a/tests/unit/gapic/vision_v1/test_product_search.py b/tests/unit/gapic/vision_v1/test_product_search.py index 52c594c3..2081be13 100644 --- a/tests/unit/gapic/vision_v1/test_product_search.py +++ b/tests/unit/gapic/vision_v1/test_product_search.py @@ -93,8 +93,21 @@ def test__get_default_mtls_endpoint(): ) +def test_product_search_client_from_service_account_info(): + creds = credentials.AnonymousCredentials() + with mock.patch.object( + service_account.Credentials, "from_service_account_info" + ) as factory: + factory.return_value = creds + info = {"valid": True} + client = ProductSearchClient.from_service_account_info(info) + assert client.transport._credentials == creds + + assert client.transport._host == "vision.googleapis.com:443" + + @pytest.mark.parametrize( - "client_class", [ProductSearchClient, ProductSearchAsyncClient] + "client_class", [ProductSearchClient, ProductSearchAsyncClient,] ) def test_product_search_client_from_service_account_file(client_class): creds = credentials.AnonymousCredentials() @@ -113,7 +126,10 @@ def test_product_search_client_from_service_account_file(client_class): def test_product_search_client_get_transport_class(): transport = ProductSearchClient.get_transport_class() - assert transport == transports.ProductSearchGrpcTransport + available_transports = [ + transports.ProductSearchGrpcTransport, + ] + assert transport in available_transports transport = ProductSearchClient.get_transport_class("grpc") assert transport == transports.ProductSearchGrpcTransport @@ -164,7 +180,7 @@ def test_product_search_client_client_options( credentials_file=None, host="squid.clam.whelk", scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -180,7 +196,7 @@ def test_product_search_client_client_options( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -196,7 +212,7 @@ def test_product_search_client_client_options( credentials_file=None, host=client.DEFAULT_MTLS_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -224,7 +240,7 @@ def test_product_search_client_client_options( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -275,29 +291,25 @@ def test_product_search_client_mtls_env_auto( client_cert_source=client_cert_source_callback ) with mock.patch.object(transport_class, "__init__") as patched: - ssl_channel_creds = mock.Mock() - with mock.patch( - "grpc.ssl_channel_credentials", return_value=ssl_channel_creds - ): - patched.return_value = None - client = client_class(client_options=options) + patched.return_value = None + client = client_class(client_options=options) - if use_client_cert_env == "false": - expected_ssl_channel_creds = None - expected_host = client.DEFAULT_ENDPOINT - else: - expected_ssl_channel_creds = ssl_channel_creds - expected_host = client.DEFAULT_MTLS_ENDPOINT + if use_client_cert_env == "false": + expected_client_cert_source = None + expected_host = client.DEFAULT_ENDPOINT + else: + expected_client_cert_source = client_cert_source_callback + expected_host = client.DEFAULT_MTLS_ENDPOINT - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - ssl_channel_credentials=expected_ssl_channel_creds, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) # Check the case ADC client cert is provided. Whether client cert is used depends on # GOOGLE_API_USE_CLIENT_CERTIFICATE value. @@ -306,66 +318,53 @@ def test_product_search_client_mtls_env_auto( ): with mock.patch.object(transport_class, "__init__") as patched: with mock.patch( - "google.auth.transport.grpc.SslCredentials.__init__", return_value=None + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, ): with mock.patch( - "google.auth.transport.grpc.SslCredentials.is_mtls", - new_callable=mock.PropertyMock, - ) as is_mtls_mock: - with mock.patch( - "google.auth.transport.grpc.SslCredentials.ssl_credentials", - new_callable=mock.PropertyMock, - ) as ssl_credentials_mock: - if use_client_cert_env == "false": - is_mtls_mock.return_value = False - ssl_credentials_mock.return_value = None - expected_host = client.DEFAULT_ENDPOINT - expected_ssl_channel_creds = None - else: - is_mtls_mock.return_value = True - ssl_credentials_mock.return_value = mock.Mock() - expected_host = client.DEFAULT_MTLS_ENDPOINT - expected_ssl_channel_creds = ( - ssl_credentials_mock.return_value - ) - - patched.return_value = None - client = client_class() - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - ssl_channel_credentials=expected_ssl_channel_creds, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) + "google.auth.transport.mtls.default_client_cert_source", + return_value=client_cert_source_callback, + ): + if use_client_cert_env == "false": + expected_host = client.DEFAULT_ENDPOINT + expected_client_cert_source = None + else: + expected_host = client.DEFAULT_MTLS_ENDPOINT + expected_client_cert_source = client_cert_source_callback - # Check the case client_cert_source and ADC client cert are not provided. - with mock.patch.dict( - os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} - ): - with mock.patch.object(transport_class, "__init__") as patched: - with mock.patch( - "google.auth.transport.grpc.SslCredentials.__init__", return_value=None - ): - with mock.patch( - "google.auth.transport.grpc.SslCredentials.is_mtls", - new_callable=mock.PropertyMock, - ) as is_mtls_mock: - is_mtls_mock.return_value = False patched.return_value = None client = client_class() patched.assert_called_once_with( credentials=None, credentials_file=None, - host=client.DEFAULT_ENDPOINT, + host=expected_host, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) + # Check the case client_cert_source and ADC client cert are not provided. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + with mock.patch.object(transport_class, "__init__") as patched: + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -391,7 +390,7 @@ def test_product_search_client_client_options_scopes( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=["1", "2"], - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -421,7 +420,7 @@ def test_product_search_client_client_options_credentials_file( credentials_file="credentials.json", host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -440,7 +439,7 @@ def test_product_search_client_client_options_from_dict(): credentials_file=None, host="squid.clam.whelk", scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -5344,6 +5343,54 @@ def test_product_search_transport_auth_adc(): ) +@pytest.mark.parametrize( + "transport_class", + [ + transports.ProductSearchGrpcTransport, + transports.ProductSearchGrpcAsyncIOTransport, + ], +) +def test_product_search_grpc_transport_client_cert_source_for_mtls(transport_class): + cred = credentials.AnonymousCredentials() + + # Check ssl_channel_credentials is used if provided. + with mock.patch.object(transport_class, "create_channel") as mock_create_channel: + mock_ssl_channel_creds = mock.Mock() + transport_class( + host="squid.clam.whelk", + credentials=cred, + ssl_channel_credentials=mock_ssl_channel_creds, + ) + mock_create_channel.assert_called_once_with( + "squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=( + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/cloud-vision", + ), + ssl_credentials=mock_ssl_channel_creds, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls + # is used. + with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): + with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: + transport_class( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback, + ) + expected_cert, expected_key = client_cert_source_callback() + mock_ssl_cred.assert_called_once_with( + certificate_chain=expected_cert, private_key=expected_key + ) + + def test_product_search_host_no_port(): client = ProductSearchClient( credentials=credentials.AnonymousCredentials(), @@ -5365,7 +5412,7 @@ def test_product_search_host_with_port(): def test_product_search_grpc_transport_channel(): - channel = grpc.insecure_channel("http://localhost/") + channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.ProductSearchGrpcTransport( @@ -5377,7 +5424,7 @@ def test_product_search_grpc_transport_channel(): def test_product_search_grpc_asyncio_transport_channel(): - channel = aio.insecure_channel("http://localhost/") + channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.ProductSearchGrpcAsyncIOTransport( @@ -5388,6 +5435,8 @@ def test_product_search_grpc_asyncio_transport_channel(): assert transport._ssl_channel_credentials == None +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. @pytest.mark.parametrize( "transport_class", [ @@ -5400,7 +5449,7 @@ def test_product_search_transport_channel_mtls_with_client_cert_source(transport "grpc.ssl_channel_credentials", autospec=True ) as grpc_ssl_channel_cred: with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_ssl_cred = mock.Mock() grpc_ssl_channel_cred.return_value = mock_ssl_cred @@ -5441,6 +5490,8 @@ def test_product_search_transport_channel_mtls_with_client_cert_source(transport assert transport._ssl_channel_credentials == mock_ssl_cred +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. @pytest.mark.parametrize( "transport_class", [ @@ -5456,7 +5507,7 @@ def test_product_search_transport_channel_mtls_with_adc(transport_class): ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), ): with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel diff --git a/tests/unit/gapic/vision_v1p1beta1/test_image_annotator.py b/tests/unit/gapic/vision_v1p1beta1/test_image_annotator.py index 4ee68cf4..d121bd2b 100644 --- a/tests/unit/gapic/vision_v1p1beta1/test_image_annotator.py +++ b/tests/unit/gapic/vision_v1p1beta1/test_image_annotator.py @@ -86,8 +86,21 @@ def test__get_default_mtls_endpoint(): ) +def test_image_annotator_client_from_service_account_info(): + creds = credentials.AnonymousCredentials() + with mock.patch.object( + service_account.Credentials, "from_service_account_info" + ) as factory: + factory.return_value = creds + info = {"valid": True} + client = ImageAnnotatorClient.from_service_account_info(info) + assert client.transport._credentials == creds + + assert client.transport._host == "vision.googleapis.com:443" + + @pytest.mark.parametrize( - "client_class", [ImageAnnotatorClient, ImageAnnotatorAsyncClient] + "client_class", [ImageAnnotatorClient, ImageAnnotatorAsyncClient,] ) def test_image_annotator_client_from_service_account_file(client_class): creds = credentials.AnonymousCredentials() @@ -106,7 +119,10 @@ def test_image_annotator_client_from_service_account_file(client_class): def test_image_annotator_client_get_transport_class(): transport = ImageAnnotatorClient.get_transport_class() - assert transport == transports.ImageAnnotatorGrpcTransport + available_transports = [ + transports.ImageAnnotatorGrpcTransport, + ] + assert transport in available_transports transport = ImageAnnotatorClient.get_transport_class("grpc") assert transport == transports.ImageAnnotatorGrpcTransport @@ -157,7 +173,7 @@ def test_image_annotator_client_client_options( credentials_file=None, host="squid.clam.whelk", scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -173,7 +189,7 @@ def test_image_annotator_client_client_options( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -189,7 +205,7 @@ def test_image_annotator_client_client_options( credentials_file=None, host=client.DEFAULT_MTLS_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -217,7 +233,7 @@ def test_image_annotator_client_client_options( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -268,29 +284,25 @@ def test_image_annotator_client_mtls_env_auto( client_cert_source=client_cert_source_callback ) with mock.patch.object(transport_class, "__init__") as patched: - ssl_channel_creds = mock.Mock() - with mock.patch( - "grpc.ssl_channel_credentials", return_value=ssl_channel_creds - ): - patched.return_value = None - client = client_class(client_options=options) + patched.return_value = None + client = client_class(client_options=options) - if use_client_cert_env == "false": - expected_ssl_channel_creds = None - expected_host = client.DEFAULT_ENDPOINT - else: - expected_ssl_channel_creds = ssl_channel_creds - expected_host = client.DEFAULT_MTLS_ENDPOINT + if use_client_cert_env == "false": + expected_client_cert_source = None + expected_host = client.DEFAULT_ENDPOINT + else: + expected_client_cert_source = client_cert_source_callback + expected_host = client.DEFAULT_MTLS_ENDPOINT - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - ssl_channel_credentials=expected_ssl_channel_creds, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) # Check the case ADC client cert is provided. Whether client cert is used depends on # GOOGLE_API_USE_CLIENT_CERTIFICATE value. @@ -299,66 +311,53 @@ def test_image_annotator_client_mtls_env_auto( ): with mock.patch.object(transport_class, "__init__") as patched: with mock.patch( - "google.auth.transport.grpc.SslCredentials.__init__", return_value=None + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, ): with mock.patch( - "google.auth.transport.grpc.SslCredentials.is_mtls", - new_callable=mock.PropertyMock, - ) as is_mtls_mock: - with mock.patch( - "google.auth.transport.grpc.SslCredentials.ssl_credentials", - new_callable=mock.PropertyMock, - ) as ssl_credentials_mock: - if use_client_cert_env == "false": - is_mtls_mock.return_value = False - ssl_credentials_mock.return_value = None - expected_host = client.DEFAULT_ENDPOINT - expected_ssl_channel_creds = None - else: - is_mtls_mock.return_value = True - ssl_credentials_mock.return_value = mock.Mock() - expected_host = client.DEFAULT_MTLS_ENDPOINT - expected_ssl_channel_creds = ( - ssl_credentials_mock.return_value - ) - - patched.return_value = None - client = client_class() - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - ssl_channel_credentials=expected_ssl_channel_creds, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) + "google.auth.transport.mtls.default_client_cert_source", + return_value=client_cert_source_callback, + ): + if use_client_cert_env == "false": + expected_host = client.DEFAULT_ENDPOINT + expected_client_cert_source = None + else: + expected_host = client.DEFAULT_MTLS_ENDPOINT + expected_client_cert_source = client_cert_source_callback - # Check the case client_cert_source and ADC client cert are not provided. - with mock.patch.dict( - os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} - ): - with mock.patch.object(transport_class, "__init__") as patched: - with mock.patch( - "google.auth.transport.grpc.SslCredentials.__init__", return_value=None - ): - with mock.patch( - "google.auth.transport.grpc.SslCredentials.is_mtls", - new_callable=mock.PropertyMock, - ) as is_mtls_mock: - is_mtls_mock.return_value = False patched.return_value = None client = client_class() patched.assert_called_once_with( credentials=None, credentials_file=None, - host=client.DEFAULT_ENDPOINT, + host=expected_host, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) + # Check the case client_cert_source and ADC client cert are not provided. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + with mock.patch.object(transport_class, "__init__") as patched: + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -384,7 +383,7 @@ def test_image_annotator_client_client_options_scopes( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=["1", "2"], - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -414,7 +413,7 @@ def test_image_annotator_client_client_options_credentials_file( credentials_file="credentials.json", host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -433,7 +432,7 @@ def test_image_annotator_client_client_options_from_dict(): credentials_file=None, host="squid.clam.whelk", scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -780,6 +779,54 @@ def test_image_annotator_transport_auth_adc(): ) +@pytest.mark.parametrize( + "transport_class", + [ + transports.ImageAnnotatorGrpcTransport, + transports.ImageAnnotatorGrpcAsyncIOTransport, + ], +) +def test_image_annotator_grpc_transport_client_cert_source_for_mtls(transport_class): + cred = credentials.AnonymousCredentials() + + # Check ssl_channel_credentials is used if provided. + with mock.patch.object(transport_class, "create_channel") as mock_create_channel: + mock_ssl_channel_creds = mock.Mock() + transport_class( + host="squid.clam.whelk", + credentials=cred, + ssl_channel_credentials=mock_ssl_channel_creds, + ) + mock_create_channel.assert_called_once_with( + "squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=( + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/cloud-vision", + ), + ssl_credentials=mock_ssl_channel_creds, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls + # is used. + with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): + with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: + transport_class( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback, + ) + expected_cert, expected_key = client_cert_source_callback() + mock_ssl_cred.assert_called_once_with( + certificate_chain=expected_cert, private_key=expected_key + ) + + def test_image_annotator_host_no_port(): client = ImageAnnotatorClient( credentials=credentials.AnonymousCredentials(), @@ -801,7 +848,7 @@ def test_image_annotator_host_with_port(): def test_image_annotator_grpc_transport_channel(): - channel = grpc.insecure_channel("http://localhost/") + channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.ImageAnnotatorGrpcTransport( @@ -813,7 +860,7 @@ def test_image_annotator_grpc_transport_channel(): def test_image_annotator_grpc_asyncio_transport_channel(): - channel = aio.insecure_channel("http://localhost/") + channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.ImageAnnotatorGrpcAsyncIOTransport( @@ -824,6 +871,8 @@ def test_image_annotator_grpc_asyncio_transport_channel(): assert transport._ssl_channel_credentials == None +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. @pytest.mark.parametrize( "transport_class", [ @@ -838,7 +887,7 @@ def test_image_annotator_transport_channel_mtls_with_client_cert_source( "grpc.ssl_channel_credentials", autospec=True ) as grpc_ssl_channel_cred: with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_ssl_cred = mock.Mock() grpc_ssl_channel_cred.return_value = mock_ssl_cred @@ -879,6 +928,8 @@ def test_image_annotator_transport_channel_mtls_with_client_cert_source( assert transport._ssl_channel_credentials == mock_ssl_cred +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. @pytest.mark.parametrize( "transport_class", [ @@ -894,7 +945,7 @@ def test_image_annotator_transport_channel_mtls_with_adc(transport_class): ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), ): with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel diff --git a/tests/unit/gapic/vision_v1p2beta1/test_image_annotator.py b/tests/unit/gapic/vision_v1p2beta1/test_image_annotator.py index 3527d957..b3a8b01b 100644 --- a/tests/unit/gapic/vision_v1p2beta1/test_image_annotator.py +++ b/tests/unit/gapic/vision_v1p2beta1/test_image_annotator.py @@ -90,8 +90,21 @@ def test__get_default_mtls_endpoint(): ) +def test_image_annotator_client_from_service_account_info(): + creds = credentials.AnonymousCredentials() + with mock.patch.object( + service_account.Credentials, "from_service_account_info" + ) as factory: + factory.return_value = creds + info = {"valid": True} + client = ImageAnnotatorClient.from_service_account_info(info) + assert client.transport._credentials == creds + + assert client.transport._host == "vision.googleapis.com:443" + + @pytest.mark.parametrize( - "client_class", [ImageAnnotatorClient, ImageAnnotatorAsyncClient] + "client_class", [ImageAnnotatorClient, ImageAnnotatorAsyncClient,] ) def test_image_annotator_client_from_service_account_file(client_class): creds = credentials.AnonymousCredentials() @@ -110,7 +123,10 @@ def test_image_annotator_client_from_service_account_file(client_class): def test_image_annotator_client_get_transport_class(): transport = ImageAnnotatorClient.get_transport_class() - assert transport == transports.ImageAnnotatorGrpcTransport + available_transports = [ + transports.ImageAnnotatorGrpcTransport, + ] + assert transport in available_transports transport = ImageAnnotatorClient.get_transport_class("grpc") assert transport == transports.ImageAnnotatorGrpcTransport @@ -161,7 +177,7 @@ def test_image_annotator_client_client_options( credentials_file=None, host="squid.clam.whelk", scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -177,7 +193,7 @@ def test_image_annotator_client_client_options( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -193,7 +209,7 @@ def test_image_annotator_client_client_options( credentials_file=None, host=client.DEFAULT_MTLS_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -221,7 +237,7 @@ def test_image_annotator_client_client_options( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -272,29 +288,25 @@ def test_image_annotator_client_mtls_env_auto( client_cert_source=client_cert_source_callback ) with mock.patch.object(transport_class, "__init__") as patched: - ssl_channel_creds = mock.Mock() - with mock.patch( - "grpc.ssl_channel_credentials", return_value=ssl_channel_creds - ): - patched.return_value = None - client = client_class(client_options=options) + patched.return_value = None + client = client_class(client_options=options) - if use_client_cert_env == "false": - expected_ssl_channel_creds = None - expected_host = client.DEFAULT_ENDPOINT - else: - expected_ssl_channel_creds = ssl_channel_creds - expected_host = client.DEFAULT_MTLS_ENDPOINT + if use_client_cert_env == "false": + expected_client_cert_source = None + expected_host = client.DEFAULT_ENDPOINT + else: + expected_client_cert_source = client_cert_source_callback + expected_host = client.DEFAULT_MTLS_ENDPOINT - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - ssl_channel_credentials=expected_ssl_channel_creds, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) # Check the case ADC client cert is provided. Whether client cert is used depends on # GOOGLE_API_USE_CLIENT_CERTIFICATE value. @@ -303,66 +315,53 @@ def test_image_annotator_client_mtls_env_auto( ): with mock.patch.object(transport_class, "__init__") as patched: with mock.patch( - "google.auth.transport.grpc.SslCredentials.__init__", return_value=None + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, ): with mock.patch( - "google.auth.transport.grpc.SslCredentials.is_mtls", - new_callable=mock.PropertyMock, - ) as is_mtls_mock: - with mock.patch( - "google.auth.transport.grpc.SslCredentials.ssl_credentials", - new_callable=mock.PropertyMock, - ) as ssl_credentials_mock: - if use_client_cert_env == "false": - is_mtls_mock.return_value = False - ssl_credentials_mock.return_value = None - expected_host = client.DEFAULT_ENDPOINT - expected_ssl_channel_creds = None - else: - is_mtls_mock.return_value = True - ssl_credentials_mock.return_value = mock.Mock() - expected_host = client.DEFAULT_MTLS_ENDPOINT - expected_ssl_channel_creds = ( - ssl_credentials_mock.return_value - ) - - patched.return_value = None - client = client_class() - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - ssl_channel_credentials=expected_ssl_channel_creds, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) + "google.auth.transport.mtls.default_client_cert_source", + return_value=client_cert_source_callback, + ): + if use_client_cert_env == "false": + expected_host = client.DEFAULT_ENDPOINT + expected_client_cert_source = None + else: + expected_host = client.DEFAULT_MTLS_ENDPOINT + expected_client_cert_source = client_cert_source_callback - # Check the case client_cert_source and ADC client cert are not provided. - with mock.patch.dict( - os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} - ): - with mock.patch.object(transport_class, "__init__") as patched: - with mock.patch( - "google.auth.transport.grpc.SslCredentials.__init__", return_value=None - ): - with mock.patch( - "google.auth.transport.grpc.SslCredentials.is_mtls", - new_callable=mock.PropertyMock, - ) as is_mtls_mock: - is_mtls_mock.return_value = False patched.return_value = None client = client_class() patched.assert_called_once_with( credentials=None, credentials_file=None, - host=client.DEFAULT_ENDPOINT, + host=expected_host, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) + # Check the case client_cert_source and ADC client cert are not provided. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + with mock.patch.object(transport_class, "__init__") as patched: + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -388,7 +387,7 @@ def test_image_annotator_client_client_options_scopes( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=["1", "2"], - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -418,7 +417,7 @@ def test_image_annotator_client_client_options_credentials_file( credentials_file="credentials.json", host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -437,7 +436,7 @@ def test_image_annotator_client_client_options_from_dict(): credentials_file=None, host="squid.clam.whelk", scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -978,6 +977,54 @@ def test_image_annotator_transport_auth_adc(): ) +@pytest.mark.parametrize( + "transport_class", + [ + transports.ImageAnnotatorGrpcTransport, + transports.ImageAnnotatorGrpcAsyncIOTransport, + ], +) +def test_image_annotator_grpc_transport_client_cert_source_for_mtls(transport_class): + cred = credentials.AnonymousCredentials() + + # Check ssl_channel_credentials is used if provided. + with mock.patch.object(transport_class, "create_channel") as mock_create_channel: + mock_ssl_channel_creds = mock.Mock() + transport_class( + host="squid.clam.whelk", + credentials=cred, + ssl_channel_credentials=mock_ssl_channel_creds, + ) + mock_create_channel.assert_called_once_with( + "squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=( + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/cloud-vision", + ), + ssl_credentials=mock_ssl_channel_creds, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls + # is used. + with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): + with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: + transport_class( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback, + ) + expected_cert, expected_key = client_cert_source_callback() + mock_ssl_cred.assert_called_once_with( + certificate_chain=expected_cert, private_key=expected_key + ) + + def test_image_annotator_host_no_port(): client = ImageAnnotatorClient( credentials=credentials.AnonymousCredentials(), @@ -999,7 +1046,7 @@ def test_image_annotator_host_with_port(): def test_image_annotator_grpc_transport_channel(): - channel = grpc.insecure_channel("http://localhost/") + channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.ImageAnnotatorGrpcTransport( @@ -1011,7 +1058,7 @@ def test_image_annotator_grpc_transport_channel(): def test_image_annotator_grpc_asyncio_transport_channel(): - channel = aio.insecure_channel("http://localhost/") + channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.ImageAnnotatorGrpcAsyncIOTransport( @@ -1022,6 +1069,8 @@ def test_image_annotator_grpc_asyncio_transport_channel(): assert transport._ssl_channel_credentials == None +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. @pytest.mark.parametrize( "transport_class", [ @@ -1036,7 +1085,7 @@ def test_image_annotator_transport_channel_mtls_with_client_cert_source( "grpc.ssl_channel_credentials", autospec=True ) as grpc_ssl_channel_cred: with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_ssl_cred = mock.Mock() grpc_ssl_channel_cred.return_value = mock_ssl_cred @@ -1077,6 +1126,8 @@ def test_image_annotator_transport_channel_mtls_with_client_cert_source( assert transport._ssl_channel_credentials == mock_ssl_cred +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. @pytest.mark.parametrize( "transport_class", [ @@ -1092,7 +1143,7 @@ def test_image_annotator_transport_channel_mtls_with_adc(transport_class): ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), ): with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel diff --git a/tests/unit/gapic/vision_v1p3beta1/test_image_annotator.py b/tests/unit/gapic/vision_v1p3beta1/test_image_annotator.py index a2afe4ad..522d9cdf 100644 --- a/tests/unit/gapic/vision_v1p3beta1/test_image_annotator.py +++ b/tests/unit/gapic/vision_v1p3beta1/test_image_annotator.py @@ -92,8 +92,21 @@ def test__get_default_mtls_endpoint(): ) +def test_image_annotator_client_from_service_account_info(): + creds = credentials.AnonymousCredentials() + with mock.patch.object( + service_account.Credentials, "from_service_account_info" + ) as factory: + factory.return_value = creds + info = {"valid": True} + client = ImageAnnotatorClient.from_service_account_info(info) + assert client.transport._credentials == creds + + assert client.transport._host == "vision.googleapis.com:443" + + @pytest.mark.parametrize( - "client_class", [ImageAnnotatorClient, ImageAnnotatorAsyncClient] + "client_class", [ImageAnnotatorClient, ImageAnnotatorAsyncClient,] ) def test_image_annotator_client_from_service_account_file(client_class): creds = credentials.AnonymousCredentials() @@ -112,7 +125,10 @@ def test_image_annotator_client_from_service_account_file(client_class): def test_image_annotator_client_get_transport_class(): transport = ImageAnnotatorClient.get_transport_class() - assert transport == transports.ImageAnnotatorGrpcTransport + available_transports = [ + transports.ImageAnnotatorGrpcTransport, + ] + assert transport in available_transports transport = ImageAnnotatorClient.get_transport_class("grpc") assert transport == transports.ImageAnnotatorGrpcTransport @@ -163,7 +179,7 @@ def test_image_annotator_client_client_options( credentials_file=None, host="squid.clam.whelk", scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -179,7 +195,7 @@ def test_image_annotator_client_client_options( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -195,7 +211,7 @@ def test_image_annotator_client_client_options( credentials_file=None, host=client.DEFAULT_MTLS_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -223,7 +239,7 @@ def test_image_annotator_client_client_options( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -274,29 +290,25 @@ def test_image_annotator_client_mtls_env_auto( client_cert_source=client_cert_source_callback ) with mock.patch.object(transport_class, "__init__") as patched: - ssl_channel_creds = mock.Mock() - with mock.patch( - "grpc.ssl_channel_credentials", return_value=ssl_channel_creds - ): - patched.return_value = None - client = client_class(client_options=options) + patched.return_value = None + client = client_class(client_options=options) - if use_client_cert_env == "false": - expected_ssl_channel_creds = None - expected_host = client.DEFAULT_ENDPOINT - else: - expected_ssl_channel_creds = ssl_channel_creds - expected_host = client.DEFAULT_MTLS_ENDPOINT + if use_client_cert_env == "false": + expected_client_cert_source = None + expected_host = client.DEFAULT_ENDPOINT + else: + expected_client_cert_source = client_cert_source_callback + expected_host = client.DEFAULT_MTLS_ENDPOINT - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - ssl_channel_credentials=expected_ssl_channel_creds, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) # Check the case ADC client cert is provided. Whether client cert is used depends on # GOOGLE_API_USE_CLIENT_CERTIFICATE value. @@ -305,66 +317,53 @@ def test_image_annotator_client_mtls_env_auto( ): with mock.patch.object(transport_class, "__init__") as patched: with mock.patch( - "google.auth.transport.grpc.SslCredentials.__init__", return_value=None + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, ): with mock.patch( - "google.auth.transport.grpc.SslCredentials.is_mtls", - new_callable=mock.PropertyMock, - ) as is_mtls_mock: - with mock.patch( - "google.auth.transport.grpc.SslCredentials.ssl_credentials", - new_callable=mock.PropertyMock, - ) as ssl_credentials_mock: - if use_client_cert_env == "false": - is_mtls_mock.return_value = False - ssl_credentials_mock.return_value = None - expected_host = client.DEFAULT_ENDPOINT - expected_ssl_channel_creds = None - else: - is_mtls_mock.return_value = True - ssl_credentials_mock.return_value = mock.Mock() - expected_host = client.DEFAULT_MTLS_ENDPOINT - expected_ssl_channel_creds = ( - ssl_credentials_mock.return_value - ) - - patched.return_value = None - client = client_class() - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - ssl_channel_credentials=expected_ssl_channel_creds, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) + "google.auth.transport.mtls.default_client_cert_source", + return_value=client_cert_source_callback, + ): + if use_client_cert_env == "false": + expected_host = client.DEFAULT_ENDPOINT + expected_client_cert_source = None + else: + expected_host = client.DEFAULT_MTLS_ENDPOINT + expected_client_cert_source = client_cert_source_callback - # Check the case client_cert_source and ADC client cert are not provided. - with mock.patch.dict( - os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} - ): - with mock.patch.object(transport_class, "__init__") as patched: - with mock.patch( - "google.auth.transport.grpc.SslCredentials.__init__", return_value=None - ): - with mock.patch( - "google.auth.transport.grpc.SslCredentials.is_mtls", - new_callable=mock.PropertyMock, - ) as is_mtls_mock: - is_mtls_mock.return_value = False patched.return_value = None client = client_class() patched.assert_called_once_with( credentials=None, credentials_file=None, - host=client.DEFAULT_ENDPOINT, + host=expected_host, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) + # Check the case client_cert_source and ADC client cert are not provided. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + with mock.patch.object(transport_class, "__init__") as patched: + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -390,7 +389,7 @@ def test_image_annotator_client_client_options_scopes( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=["1", "2"], - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -420,7 +419,7 @@ def test_image_annotator_client_client_options_credentials_file( credentials_file="credentials.json", host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -439,7 +438,7 @@ def test_image_annotator_client_client_options_from_dict(): credentials_file=None, host="squid.clam.whelk", scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -980,6 +979,54 @@ def test_image_annotator_transport_auth_adc(): ) +@pytest.mark.parametrize( + "transport_class", + [ + transports.ImageAnnotatorGrpcTransport, + transports.ImageAnnotatorGrpcAsyncIOTransport, + ], +) +def test_image_annotator_grpc_transport_client_cert_source_for_mtls(transport_class): + cred = credentials.AnonymousCredentials() + + # Check ssl_channel_credentials is used if provided. + with mock.patch.object(transport_class, "create_channel") as mock_create_channel: + mock_ssl_channel_creds = mock.Mock() + transport_class( + host="squid.clam.whelk", + credentials=cred, + ssl_channel_credentials=mock_ssl_channel_creds, + ) + mock_create_channel.assert_called_once_with( + "squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=( + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/cloud-vision", + ), + ssl_credentials=mock_ssl_channel_creds, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls + # is used. + with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): + with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: + transport_class( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback, + ) + expected_cert, expected_key = client_cert_source_callback() + mock_ssl_cred.assert_called_once_with( + certificate_chain=expected_cert, private_key=expected_key + ) + + def test_image_annotator_host_no_port(): client = ImageAnnotatorClient( credentials=credentials.AnonymousCredentials(), @@ -1001,7 +1048,7 @@ def test_image_annotator_host_with_port(): def test_image_annotator_grpc_transport_channel(): - channel = grpc.insecure_channel("http://localhost/") + channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.ImageAnnotatorGrpcTransport( @@ -1013,7 +1060,7 @@ def test_image_annotator_grpc_transport_channel(): def test_image_annotator_grpc_asyncio_transport_channel(): - channel = aio.insecure_channel("http://localhost/") + channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.ImageAnnotatorGrpcAsyncIOTransport( @@ -1024,6 +1071,8 @@ def test_image_annotator_grpc_asyncio_transport_channel(): assert transport._ssl_channel_credentials == None +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. @pytest.mark.parametrize( "transport_class", [ @@ -1038,7 +1087,7 @@ def test_image_annotator_transport_channel_mtls_with_client_cert_source( "grpc.ssl_channel_credentials", autospec=True ) as grpc_ssl_channel_cred: with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_ssl_cred = mock.Mock() grpc_ssl_channel_cred.return_value = mock_ssl_cred @@ -1079,6 +1128,8 @@ def test_image_annotator_transport_channel_mtls_with_client_cert_source( assert transport._ssl_channel_credentials == mock_ssl_cred +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. @pytest.mark.parametrize( "transport_class", [ @@ -1094,7 +1145,7 @@ def test_image_annotator_transport_channel_mtls_with_adc(transport_class): ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), ): with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel diff --git a/tests/unit/gapic/vision_v1p3beta1/test_product_search.py b/tests/unit/gapic/vision_v1p3beta1/test_product_search.py index af66ff8b..a6f4a49a 100644 --- a/tests/unit/gapic/vision_v1p3beta1/test_product_search.py +++ b/tests/unit/gapic/vision_v1p3beta1/test_product_search.py @@ -95,8 +95,21 @@ def test__get_default_mtls_endpoint(): ) +def test_product_search_client_from_service_account_info(): + creds = credentials.AnonymousCredentials() + with mock.patch.object( + service_account.Credentials, "from_service_account_info" + ) as factory: + factory.return_value = creds + info = {"valid": True} + client = ProductSearchClient.from_service_account_info(info) + assert client.transport._credentials == creds + + assert client.transport._host == "vision.googleapis.com:443" + + @pytest.mark.parametrize( - "client_class", [ProductSearchClient, ProductSearchAsyncClient] + "client_class", [ProductSearchClient, ProductSearchAsyncClient,] ) def test_product_search_client_from_service_account_file(client_class): creds = credentials.AnonymousCredentials() @@ -115,7 +128,10 @@ def test_product_search_client_from_service_account_file(client_class): def test_product_search_client_get_transport_class(): transport = ProductSearchClient.get_transport_class() - assert transport == transports.ProductSearchGrpcTransport + available_transports = [ + transports.ProductSearchGrpcTransport, + ] + assert transport in available_transports transport = ProductSearchClient.get_transport_class("grpc") assert transport == transports.ProductSearchGrpcTransport @@ -166,7 +182,7 @@ def test_product_search_client_client_options( credentials_file=None, host="squid.clam.whelk", scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -182,7 +198,7 @@ def test_product_search_client_client_options( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -198,7 +214,7 @@ def test_product_search_client_client_options( credentials_file=None, host=client.DEFAULT_MTLS_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -226,7 +242,7 @@ def test_product_search_client_client_options( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -277,29 +293,25 @@ def test_product_search_client_mtls_env_auto( client_cert_source=client_cert_source_callback ) with mock.patch.object(transport_class, "__init__") as patched: - ssl_channel_creds = mock.Mock() - with mock.patch( - "grpc.ssl_channel_credentials", return_value=ssl_channel_creds - ): - patched.return_value = None - client = client_class(client_options=options) + patched.return_value = None + client = client_class(client_options=options) - if use_client_cert_env == "false": - expected_ssl_channel_creds = None - expected_host = client.DEFAULT_ENDPOINT - else: - expected_ssl_channel_creds = ssl_channel_creds - expected_host = client.DEFAULT_MTLS_ENDPOINT + if use_client_cert_env == "false": + expected_client_cert_source = None + expected_host = client.DEFAULT_ENDPOINT + else: + expected_client_cert_source = client_cert_source_callback + expected_host = client.DEFAULT_MTLS_ENDPOINT - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - ssl_channel_credentials=expected_ssl_channel_creds, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) # Check the case ADC client cert is provided. Whether client cert is used depends on # GOOGLE_API_USE_CLIENT_CERTIFICATE value. @@ -308,66 +320,53 @@ def test_product_search_client_mtls_env_auto( ): with mock.patch.object(transport_class, "__init__") as patched: with mock.patch( - "google.auth.transport.grpc.SslCredentials.__init__", return_value=None + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, ): with mock.patch( - "google.auth.transport.grpc.SslCredentials.is_mtls", - new_callable=mock.PropertyMock, - ) as is_mtls_mock: - with mock.patch( - "google.auth.transport.grpc.SslCredentials.ssl_credentials", - new_callable=mock.PropertyMock, - ) as ssl_credentials_mock: - if use_client_cert_env == "false": - is_mtls_mock.return_value = False - ssl_credentials_mock.return_value = None - expected_host = client.DEFAULT_ENDPOINT - expected_ssl_channel_creds = None - else: - is_mtls_mock.return_value = True - ssl_credentials_mock.return_value = mock.Mock() - expected_host = client.DEFAULT_MTLS_ENDPOINT - expected_ssl_channel_creds = ( - ssl_credentials_mock.return_value - ) - - patched.return_value = None - client = client_class() - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - ssl_channel_credentials=expected_ssl_channel_creds, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) + "google.auth.transport.mtls.default_client_cert_source", + return_value=client_cert_source_callback, + ): + if use_client_cert_env == "false": + expected_host = client.DEFAULT_ENDPOINT + expected_client_cert_source = None + else: + expected_host = client.DEFAULT_MTLS_ENDPOINT + expected_client_cert_source = client_cert_source_callback - # Check the case client_cert_source and ADC client cert are not provided. - with mock.patch.dict( - os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} - ): - with mock.patch.object(transport_class, "__init__") as patched: - with mock.patch( - "google.auth.transport.grpc.SslCredentials.__init__", return_value=None - ): - with mock.patch( - "google.auth.transport.grpc.SslCredentials.is_mtls", - new_callable=mock.PropertyMock, - ) as is_mtls_mock: - is_mtls_mock.return_value = False patched.return_value = None client = client_class() patched.assert_called_once_with( credentials=None, credentials_file=None, - host=client.DEFAULT_ENDPOINT, + host=expected_host, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) + # Check the case client_cert_source and ADC client cert are not provided. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + with mock.patch.object(transport_class, "__init__") as patched: + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -393,7 +392,7 @@ def test_product_search_client_client_options_scopes( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=["1", "2"], - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -423,7 +422,7 @@ def test_product_search_client_client_options_credentials_file( credentials_file="credentials.json", host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -442,7 +441,7 @@ def test_product_search_client_client_options_from_dict(): credentials_file=None, host="squid.clam.whelk", scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -5158,6 +5157,54 @@ def test_product_search_transport_auth_adc(): ) +@pytest.mark.parametrize( + "transport_class", + [ + transports.ProductSearchGrpcTransport, + transports.ProductSearchGrpcAsyncIOTransport, + ], +) +def test_product_search_grpc_transport_client_cert_source_for_mtls(transport_class): + cred = credentials.AnonymousCredentials() + + # Check ssl_channel_credentials is used if provided. + with mock.patch.object(transport_class, "create_channel") as mock_create_channel: + mock_ssl_channel_creds = mock.Mock() + transport_class( + host="squid.clam.whelk", + credentials=cred, + ssl_channel_credentials=mock_ssl_channel_creds, + ) + mock_create_channel.assert_called_once_with( + "squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=( + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/cloud-vision", + ), + ssl_credentials=mock_ssl_channel_creds, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls + # is used. + with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): + with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: + transport_class( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback, + ) + expected_cert, expected_key = client_cert_source_callback() + mock_ssl_cred.assert_called_once_with( + certificate_chain=expected_cert, private_key=expected_key + ) + + def test_product_search_host_no_port(): client = ProductSearchClient( credentials=credentials.AnonymousCredentials(), @@ -5179,7 +5226,7 @@ def test_product_search_host_with_port(): def test_product_search_grpc_transport_channel(): - channel = grpc.insecure_channel("http://localhost/") + channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.ProductSearchGrpcTransport( @@ -5191,7 +5238,7 @@ def test_product_search_grpc_transport_channel(): def test_product_search_grpc_asyncio_transport_channel(): - channel = aio.insecure_channel("http://localhost/") + channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.ProductSearchGrpcAsyncIOTransport( @@ -5202,6 +5249,8 @@ def test_product_search_grpc_asyncio_transport_channel(): assert transport._ssl_channel_credentials == None +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. @pytest.mark.parametrize( "transport_class", [ @@ -5214,7 +5263,7 @@ def test_product_search_transport_channel_mtls_with_client_cert_source(transport "grpc.ssl_channel_credentials", autospec=True ) as grpc_ssl_channel_cred: with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_ssl_cred = mock.Mock() grpc_ssl_channel_cred.return_value = mock_ssl_cred @@ -5255,6 +5304,8 @@ def test_product_search_transport_channel_mtls_with_client_cert_source(transport assert transport._ssl_channel_credentials == mock_ssl_cred +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. @pytest.mark.parametrize( "transport_class", [ @@ -5270,7 +5321,7 @@ def test_product_search_transport_channel_mtls_with_adc(transport_class): ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), ): with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel diff --git a/tests/unit/gapic/vision_v1p4beta1/test_image_annotator.py b/tests/unit/gapic/vision_v1p4beta1/test_image_annotator.py index 2a8d5072..0582f419 100644 --- a/tests/unit/gapic/vision_v1p4beta1/test_image_annotator.py +++ b/tests/unit/gapic/vision_v1p4beta1/test_image_annotator.py @@ -93,8 +93,21 @@ def test__get_default_mtls_endpoint(): ) +def test_image_annotator_client_from_service_account_info(): + creds = credentials.AnonymousCredentials() + with mock.patch.object( + service_account.Credentials, "from_service_account_info" + ) as factory: + factory.return_value = creds + info = {"valid": True} + client = ImageAnnotatorClient.from_service_account_info(info) + assert client.transport._credentials == creds + + assert client.transport._host == "vision.googleapis.com:443" + + @pytest.mark.parametrize( - "client_class", [ImageAnnotatorClient, ImageAnnotatorAsyncClient] + "client_class", [ImageAnnotatorClient, ImageAnnotatorAsyncClient,] ) def test_image_annotator_client_from_service_account_file(client_class): creds = credentials.AnonymousCredentials() @@ -113,7 +126,10 @@ def test_image_annotator_client_from_service_account_file(client_class): def test_image_annotator_client_get_transport_class(): transport = ImageAnnotatorClient.get_transport_class() - assert transport == transports.ImageAnnotatorGrpcTransport + available_transports = [ + transports.ImageAnnotatorGrpcTransport, + ] + assert transport in available_transports transport = ImageAnnotatorClient.get_transport_class("grpc") assert transport == transports.ImageAnnotatorGrpcTransport @@ -164,7 +180,7 @@ def test_image_annotator_client_client_options( credentials_file=None, host="squid.clam.whelk", scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -180,7 +196,7 @@ def test_image_annotator_client_client_options( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -196,7 +212,7 @@ def test_image_annotator_client_client_options( credentials_file=None, host=client.DEFAULT_MTLS_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -224,7 +240,7 @@ def test_image_annotator_client_client_options( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -275,29 +291,25 @@ def test_image_annotator_client_mtls_env_auto( client_cert_source=client_cert_source_callback ) with mock.patch.object(transport_class, "__init__") as patched: - ssl_channel_creds = mock.Mock() - with mock.patch( - "grpc.ssl_channel_credentials", return_value=ssl_channel_creds - ): - patched.return_value = None - client = client_class(client_options=options) + patched.return_value = None + client = client_class(client_options=options) - if use_client_cert_env == "false": - expected_ssl_channel_creds = None - expected_host = client.DEFAULT_ENDPOINT - else: - expected_ssl_channel_creds = ssl_channel_creds - expected_host = client.DEFAULT_MTLS_ENDPOINT + if use_client_cert_env == "false": + expected_client_cert_source = None + expected_host = client.DEFAULT_ENDPOINT + else: + expected_client_cert_source = client_cert_source_callback + expected_host = client.DEFAULT_MTLS_ENDPOINT - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - ssl_channel_credentials=expected_ssl_channel_creds, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) # Check the case ADC client cert is provided. Whether client cert is used depends on # GOOGLE_API_USE_CLIENT_CERTIFICATE value. @@ -306,66 +318,53 @@ def test_image_annotator_client_mtls_env_auto( ): with mock.patch.object(transport_class, "__init__") as patched: with mock.patch( - "google.auth.transport.grpc.SslCredentials.__init__", return_value=None + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, ): with mock.patch( - "google.auth.transport.grpc.SslCredentials.is_mtls", - new_callable=mock.PropertyMock, - ) as is_mtls_mock: - with mock.patch( - "google.auth.transport.grpc.SslCredentials.ssl_credentials", - new_callable=mock.PropertyMock, - ) as ssl_credentials_mock: - if use_client_cert_env == "false": - is_mtls_mock.return_value = False - ssl_credentials_mock.return_value = None - expected_host = client.DEFAULT_ENDPOINT - expected_ssl_channel_creds = None - else: - is_mtls_mock.return_value = True - ssl_credentials_mock.return_value = mock.Mock() - expected_host = client.DEFAULT_MTLS_ENDPOINT - expected_ssl_channel_creds = ( - ssl_credentials_mock.return_value - ) - - patched.return_value = None - client = client_class() - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - ssl_channel_credentials=expected_ssl_channel_creds, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) + "google.auth.transport.mtls.default_client_cert_source", + return_value=client_cert_source_callback, + ): + if use_client_cert_env == "false": + expected_host = client.DEFAULT_ENDPOINT + expected_client_cert_source = None + else: + expected_host = client.DEFAULT_MTLS_ENDPOINT + expected_client_cert_source = client_cert_source_callback - # Check the case client_cert_source and ADC client cert are not provided. - with mock.patch.dict( - os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} - ): - with mock.patch.object(transport_class, "__init__") as patched: - with mock.patch( - "google.auth.transport.grpc.SslCredentials.__init__", return_value=None - ): - with mock.patch( - "google.auth.transport.grpc.SslCredentials.is_mtls", - new_callable=mock.PropertyMock, - ) as is_mtls_mock: - is_mtls_mock.return_value = False patched.return_value = None client = client_class() patched.assert_called_once_with( credentials=None, credentials_file=None, - host=client.DEFAULT_ENDPOINT, + host=expected_host, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) + # Check the case client_cert_source and ADC client cert are not provided. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + with mock.patch.object(transport_class, "__init__") as patched: + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -391,7 +390,7 @@ def test_image_annotator_client_client_options_scopes( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=["1", "2"], - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -421,7 +420,7 @@ def test_image_annotator_client_client_options_credentials_file( credentials_file="credentials.json", host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -440,7 +439,7 @@ def test_image_annotator_client_client_options_from_dict(): credentials_file=None, host="squid.clam.whelk", scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -1365,6 +1364,54 @@ def test_image_annotator_transport_auth_adc(): ) +@pytest.mark.parametrize( + "transport_class", + [ + transports.ImageAnnotatorGrpcTransport, + transports.ImageAnnotatorGrpcAsyncIOTransport, + ], +) +def test_image_annotator_grpc_transport_client_cert_source_for_mtls(transport_class): + cred = credentials.AnonymousCredentials() + + # Check ssl_channel_credentials is used if provided. + with mock.patch.object(transport_class, "create_channel") as mock_create_channel: + mock_ssl_channel_creds = mock.Mock() + transport_class( + host="squid.clam.whelk", + credentials=cred, + ssl_channel_credentials=mock_ssl_channel_creds, + ) + mock_create_channel.assert_called_once_with( + "squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=( + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/cloud-vision", + ), + ssl_credentials=mock_ssl_channel_creds, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls + # is used. + with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): + with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: + transport_class( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback, + ) + expected_cert, expected_key = client_cert_source_callback() + mock_ssl_cred.assert_called_once_with( + certificate_chain=expected_cert, private_key=expected_key + ) + + def test_image_annotator_host_no_port(): client = ImageAnnotatorClient( credentials=credentials.AnonymousCredentials(), @@ -1386,7 +1433,7 @@ def test_image_annotator_host_with_port(): def test_image_annotator_grpc_transport_channel(): - channel = grpc.insecure_channel("http://localhost/") + channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.ImageAnnotatorGrpcTransport( @@ -1398,7 +1445,7 @@ def test_image_annotator_grpc_transport_channel(): def test_image_annotator_grpc_asyncio_transport_channel(): - channel = aio.insecure_channel("http://localhost/") + channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.ImageAnnotatorGrpcAsyncIOTransport( @@ -1409,6 +1456,8 @@ def test_image_annotator_grpc_asyncio_transport_channel(): assert transport._ssl_channel_credentials == None +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. @pytest.mark.parametrize( "transport_class", [ @@ -1423,7 +1472,7 @@ def test_image_annotator_transport_channel_mtls_with_client_cert_source( "grpc.ssl_channel_credentials", autospec=True ) as grpc_ssl_channel_cred: with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_ssl_cred = mock.Mock() grpc_ssl_channel_cred.return_value = mock_ssl_cred @@ -1464,6 +1513,8 @@ def test_image_annotator_transport_channel_mtls_with_client_cert_source( assert transport._ssl_channel_credentials == mock_ssl_cred +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. @pytest.mark.parametrize( "transport_class", [ @@ -1479,7 +1530,7 @@ def test_image_annotator_transport_channel_mtls_with_adc(transport_class): ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), ): with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel diff --git a/tests/unit/gapic/vision_v1p4beta1/test_product_search.py b/tests/unit/gapic/vision_v1p4beta1/test_product_search.py index 0ad20e9a..0b4abd53 100644 --- a/tests/unit/gapic/vision_v1p4beta1/test_product_search.py +++ b/tests/unit/gapic/vision_v1p4beta1/test_product_search.py @@ -95,8 +95,21 @@ def test__get_default_mtls_endpoint(): ) +def test_product_search_client_from_service_account_info(): + creds = credentials.AnonymousCredentials() + with mock.patch.object( + service_account.Credentials, "from_service_account_info" + ) as factory: + factory.return_value = creds + info = {"valid": True} + client = ProductSearchClient.from_service_account_info(info) + assert client.transport._credentials == creds + + assert client.transport._host == "vision.googleapis.com:443" + + @pytest.mark.parametrize( - "client_class", [ProductSearchClient, ProductSearchAsyncClient] + "client_class", [ProductSearchClient, ProductSearchAsyncClient,] ) def test_product_search_client_from_service_account_file(client_class): creds = credentials.AnonymousCredentials() @@ -115,7 +128,10 @@ def test_product_search_client_from_service_account_file(client_class): def test_product_search_client_get_transport_class(): transport = ProductSearchClient.get_transport_class() - assert transport == transports.ProductSearchGrpcTransport + available_transports = [ + transports.ProductSearchGrpcTransport, + ] + assert transport in available_transports transport = ProductSearchClient.get_transport_class("grpc") assert transport == transports.ProductSearchGrpcTransport @@ -166,7 +182,7 @@ def test_product_search_client_client_options( credentials_file=None, host="squid.clam.whelk", scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -182,7 +198,7 @@ def test_product_search_client_client_options( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -198,7 +214,7 @@ def test_product_search_client_client_options( credentials_file=None, host=client.DEFAULT_MTLS_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -226,7 +242,7 @@ def test_product_search_client_client_options( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -277,29 +293,25 @@ def test_product_search_client_mtls_env_auto( client_cert_source=client_cert_source_callback ) with mock.patch.object(transport_class, "__init__") as patched: - ssl_channel_creds = mock.Mock() - with mock.patch( - "grpc.ssl_channel_credentials", return_value=ssl_channel_creds - ): - patched.return_value = None - client = client_class(client_options=options) + patched.return_value = None + client = client_class(client_options=options) - if use_client_cert_env == "false": - expected_ssl_channel_creds = None - expected_host = client.DEFAULT_ENDPOINT - else: - expected_ssl_channel_creds = ssl_channel_creds - expected_host = client.DEFAULT_MTLS_ENDPOINT + if use_client_cert_env == "false": + expected_client_cert_source = None + expected_host = client.DEFAULT_ENDPOINT + else: + expected_client_cert_source = client_cert_source_callback + expected_host = client.DEFAULT_MTLS_ENDPOINT - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - ssl_channel_credentials=expected_ssl_channel_creds, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) # Check the case ADC client cert is provided. Whether client cert is used depends on # GOOGLE_API_USE_CLIENT_CERTIFICATE value. @@ -308,66 +320,53 @@ def test_product_search_client_mtls_env_auto( ): with mock.patch.object(transport_class, "__init__") as patched: with mock.patch( - "google.auth.transport.grpc.SslCredentials.__init__", return_value=None + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, ): with mock.patch( - "google.auth.transport.grpc.SslCredentials.is_mtls", - new_callable=mock.PropertyMock, - ) as is_mtls_mock: - with mock.patch( - "google.auth.transport.grpc.SslCredentials.ssl_credentials", - new_callable=mock.PropertyMock, - ) as ssl_credentials_mock: - if use_client_cert_env == "false": - is_mtls_mock.return_value = False - ssl_credentials_mock.return_value = None - expected_host = client.DEFAULT_ENDPOINT - expected_ssl_channel_creds = None - else: - is_mtls_mock.return_value = True - ssl_credentials_mock.return_value = mock.Mock() - expected_host = client.DEFAULT_MTLS_ENDPOINT - expected_ssl_channel_creds = ( - ssl_credentials_mock.return_value - ) - - patched.return_value = None - client = client_class() - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - ssl_channel_credentials=expected_ssl_channel_creds, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) + "google.auth.transport.mtls.default_client_cert_source", + return_value=client_cert_source_callback, + ): + if use_client_cert_env == "false": + expected_host = client.DEFAULT_ENDPOINT + expected_client_cert_source = None + else: + expected_host = client.DEFAULT_MTLS_ENDPOINT + expected_client_cert_source = client_cert_source_callback - # Check the case client_cert_source and ADC client cert are not provided. - with mock.patch.dict( - os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} - ): - with mock.patch.object(transport_class, "__init__") as patched: - with mock.patch( - "google.auth.transport.grpc.SslCredentials.__init__", return_value=None - ): - with mock.patch( - "google.auth.transport.grpc.SslCredentials.is_mtls", - new_callable=mock.PropertyMock, - ) as is_mtls_mock: - is_mtls_mock.return_value = False patched.return_value = None client = client_class() patched.assert_called_once_with( credentials=None, credentials_file=None, - host=client.DEFAULT_ENDPOINT, + host=expected_host, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) + # Check the case client_cert_source and ADC client cert are not provided. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + with mock.patch.object(transport_class, "__init__") as patched: + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -393,7 +392,7 @@ def test_product_search_client_client_options_scopes( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=["1", "2"], - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -423,7 +422,7 @@ def test_product_search_client_client_options_credentials_file( credentials_file="credentials.json", host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -442,7 +441,7 @@ def test_product_search_client_client_options_from_dict(): credentials_file=None, host="squid.clam.whelk", scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -5346,6 +5345,54 @@ def test_product_search_transport_auth_adc(): ) +@pytest.mark.parametrize( + "transport_class", + [ + transports.ProductSearchGrpcTransport, + transports.ProductSearchGrpcAsyncIOTransport, + ], +) +def test_product_search_grpc_transport_client_cert_source_for_mtls(transport_class): + cred = credentials.AnonymousCredentials() + + # Check ssl_channel_credentials is used if provided. + with mock.patch.object(transport_class, "create_channel") as mock_create_channel: + mock_ssl_channel_creds = mock.Mock() + transport_class( + host="squid.clam.whelk", + credentials=cred, + ssl_channel_credentials=mock_ssl_channel_creds, + ) + mock_create_channel.assert_called_once_with( + "squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=( + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/cloud-vision", + ), + ssl_credentials=mock_ssl_channel_creds, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls + # is used. + with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): + with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: + transport_class( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback, + ) + expected_cert, expected_key = client_cert_source_callback() + mock_ssl_cred.assert_called_once_with( + certificate_chain=expected_cert, private_key=expected_key + ) + + def test_product_search_host_no_port(): client = ProductSearchClient( credentials=credentials.AnonymousCredentials(), @@ -5367,7 +5414,7 @@ def test_product_search_host_with_port(): def test_product_search_grpc_transport_channel(): - channel = grpc.insecure_channel("http://localhost/") + channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.ProductSearchGrpcTransport( @@ -5379,7 +5426,7 @@ def test_product_search_grpc_transport_channel(): def test_product_search_grpc_asyncio_transport_channel(): - channel = aio.insecure_channel("http://localhost/") + channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.ProductSearchGrpcAsyncIOTransport( @@ -5390,6 +5437,8 @@ def test_product_search_grpc_asyncio_transport_channel(): assert transport._ssl_channel_credentials == None +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. @pytest.mark.parametrize( "transport_class", [ @@ -5402,7 +5451,7 @@ def test_product_search_transport_channel_mtls_with_client_cert_source(transport "grpc.ssl_channel_credentials", autospec=True ) as grpc_ssl_channel_cred: with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_ssl_cred = mock.Mock() grpc_ssl_channel_cred.return_value = mock_ssl_cred @@ -5443,6 +5492,8 @@ def test_product_search_transport_channel_mtls_with_client_cert_source(transport assert transport._ssl_channel_credentials == mock_ssl_cred +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. @pytest.mark.parametrize( "transport_class", [ @@ -5458,7 +5509,7 @@ def test_product_search_transport_channel_mtls_with_adc(transport_class): ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), ): with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel