Skip to content
This repository has been archived by the owner on Dec 31, 2023. It is now read-only.

feat: add text extraction health care option in create model #86

Merged
merged 25 commits into from Oct 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a636c05
changes without context
yoshi-automation Oct 23, 2020
f9cd96e
chore(java_templates): stop running pmd/spotbugs checks for samples
yoshi-automation Oct 23, 2020
804cc66
chore: upgrade gapic-generator-python to 0.32.2
yoshi-automation Oct 23, 2020
aa27d82
feat: added google.cloud.assuredworkloads.v1beta1.AssuredWorkloadsSer…
yoshi-automation Oct 23, 2020
972edb5
feat!: Updated third_party Cloud Build clients with new Build message…
yoshi-automation Oct 23, 2020
397c3bb
chore: update python microgen version to 0.33.0
yoshi-automation Oct 23, 2020
e097aa7
migrate secret manager BUILD file python part to use microgen
yoshi-automation Oct 23, 2020
819f65d
feat: Add Java microgen rules to imports
yoshi-automation Oct 23, 2020
4696421
Publish SLM logging proto for documentation
yoshi-automation Oct 23, 2020
d70ff4b
docs: update OPTIONAL annotations for some fields.
yoshi-automation Oct 23, 2020
c194d32
Update gapic-generator-python pin to 0.33.4
yoshi-automation Oct 23, 2020
21b454c
chore: use Python microgenerator rules for aiplatform
yoshi-automation Oct 23, 2020
f5a7fb7
chore: use gapic-generator-python 0.33.6
yoshi-automation Oct 23, 2020
ba7ba07
fix: naming style updates
yoshi-automation Oct 23, 2020
2dd7651
Add Service Direcotry v1 protos and configs
yoshi-automation Oct 23, 2020
04574f6
fix: switch pubsub/v1 retry config to grpc_service_config
yoshi-automation Oct 23, 2020
b41b0a0
feat: Added text extraction health care option in create model.
yoshi-automation Oct 23, 2020
4e751e9
docs: fixed link from SentimentAnalysisResult
yoshi-automation Oct 23, 2020
1abfc87
chore: upgrade to gapic-generator-python 0.35.6
yoshi-automation Oct 23, 2020
b83d2c7
chore: upgrade to gapic-generator-python 0.35.6
yoshi-automation Oct 23, 2020
465e034
chore: update grpc dependency to v1.33.1
yoshi-automation Oct 23, 2020
63e814f
chore: update proto-plus, undo docs removal
busunkim96 Oct 27, 2020
aabb68b
fix: fix imports
busunkim96 Oct 27, 2020
31da1a9
fix: fix __init__.py again
busunkim96 Oct 27, 2020
d348416
fix: fix for real
busunkim96 Oct 27, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/automl_v1beta1/services.rst
Expand Up @@ -7,6 +7,6 @@ Services for Google Cloud Automl v1beta1 API
.. automodule:: google.cloud.automl_v1beta1.services.prediction_service
:members:
:inherited-members:
.. automodule:: google.cloud.automl_v1beta1.services.tables
:members:
.. automodule:: google.cloud.automl_v1beta1.services.tables
:members:
:inherited-members:
4 changes: 2 additions & 2 deletions google/cloud/automl_v1/__init__.py
Expand Up @@ -104,6 +104,7 @@
__all__ = (
"AnnotationPayload",
"AnnotationSpec",
"AutoMlClient",
"BatchPredictInputConfig",
"BatchPredictOperationMetadata",
"BatchPredictOutputConfig",
Expand Down Expand Up @@ -164,7 +165,6 @@
"OutputConfig",
"PredictRequest",
"PredictResponse",
"PredictionServiceClient",
"TextClassificationDatasetMetadata",
"TextClassificationModelMetadata",
"TextExtractionAnnotation",
Expand All @@ -185,5 +185,5 @@
"UndeployModelRequest",
"UpdateDatasetRequest",
"UpdateModelRequest",
"AutoMlClient",
"PredictionServiceClient",
)
28 changes: 16 additions & 12 deletions google/cloud/automl_v1/services/auto_ml/async_client.py
Expand Up @@ -28,8 +28,8 @@
from google.auth import credentials # type: ignore
from google.oauth2 import service_account # type: ignore

from google.api_core import operation
from google.api_core import operation_async
from google.api_core import operation # type: ignore
from google.api_core import operation_async # type: ignore
from google.cloud.automl_v1.services.auto_ml import pagers
from google.cloud.automl_v1.types import annotation_spec
from google.cloud.automl_v1.types import classification
Expand Down Expand Up @@ -79,9 +79,10 @@ class AutoMlAsyncClient:
DEFAULT_ENDPOINT = AutoMlClient.DEFAULT_ENDPOINT
DEFAULT_MTLS_ENDPOINT = AutoMlClient.DEFAULT_MTLS_ENDPOINT

model_path = staticmethod(AutoMlClient.model_path)

dataset_path = staticmethod(AutoMlClient.dataset_path)
parse_dataset_path = staticmethod(AutoMlClient.parse_dataset_path)
model_path = staticmethod(AutoMlClient.model_path)
parse_model_path = staticmethod(AutoMlClient.parse_model_path)

from_service_account_file = AutoMlClient.from_service_account_file
from_service_account_json = from_service_account_file
Expand Down Expand Up @@ -112,16 +113,19 @@ def __init__(
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
default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT
environment variable can also be used to override the endpoint:
"always" (always use the default mTLS endpoint), "never" (always
use the default regular endpoint, this is the default value for
the environment variable) and "auto" (auto switch to the default
mTLS endpoint if client SSL credentials is present). However,
the ``api_endpoint`` property takes precedence if provided.
(2) The ``client_cert_source`` property is used to provide client
SSL credentials for mutual TLS transport. If not provided, the
default SSL credentials will be used if present.
use the default regular endpoint) and "auto" (auto switch to the
default mTLS endpoint if client certificate is present, this is
the default value). However, the ``api_endpoint`` property takes
precedence if provided.
(2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable
is "true", then the ``client_cert_source`` property can be used
to provide client certificate for mutual TLS transport. If
not provided, the default SSL client certificate will be used if
present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not
set, no client certificate will be used.

Raises:
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
Expand Down
92 changes: 57 additions & 35 deletions google/cloud/automl_v1/services/auto_ml/client.py
Expand Up @@ -16,22 +16,24 @@
#

from collections import OrderedDict
from distutils import util
import os
import re
from typing import Callable, Dict, Sequence, Tuple, Type, Union
from typing import Callable, Dict, Optional, Sequence, Tuple, Type, Union
import pkg_resources

import google.api_core.client_options as ClientOptions # type: ignore
from google.api_core import client_options as client_options_lib # type: ignore
from google.api_core import exceptions # type: ignore
from google.api_core import gapic_v1 # type: ignore
from google.api_core import retry as retries # type: ignore
from google.auth import credentials # type: ignore
from google.auth.transport import mtls # type: ignore
from google.auth.transport.grpc import SslCredentials # type: ignore
from google.auth.exceptions import MutualTLSChannelError # type: ignore
from google.oauth2 import service_account # type: ignore

from google.api_core import operation
from google.api_core import operation_async
from google.api_core import operation # type: ignore
from google.api_core import operation_async # type: ignore
from google.cloud.automl_v1.services.auto_ml import pagers
from google.cloud.automl_v1.types import annotation_spec
from google.cloud.automl_v1.types import classification
Expand Down Expand Up @@ -196,9 +198,9 @@ def parse_model_path(path: str) -> Dict[str, str]:
def __init__(
self,
*,
credentials: credentials.Credentials = None,
transport: Union[str, AutoMlTransport] = None,
client_options: ClientOptions = None,
credentials: Optional[credentials.Credentials] = None,
transport: Union[str, AutoMlTransport, None] = None,
client_options: Optional[client_options_lib.ClientOptions] = None,
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
) -> None:
"""Instantiate the auto ml client.
Expand All @@ -212,19 +214,22 @@ def __init__(
transport (Union[str, ~.AutoMlTransport]): The
transport to use. If set to None, a transport is chosen
automatically.
client_options (ClientOptions): Custom options for the client. It
won't take effect if a ``transport`` instance is provided.
client_options (client_options_lib.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
default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT
environment variable can also be used to override the endpoint:
"always" (always use the default mTLS endpoint), "never" (always
use the default regular endpoint, this is the default value for
the environment variable) and "auto" (auto switch to the default
mTLS endpoint if client SSL credentials is present). However,
the ``api_endpoint`` property takes precedence if provided.
(2) The ``client_cert_source`` property is used to provide client
SSL credentials for mutual TLS transport. If not provided, the
default SSL credentials will be used if present.
use the default regular endpoint) and "auto" (auto switch to the
default mTLS endpoint if client certificate is present, this is
the default value). However, the ``api_endpoint`` property takes
precedence if provided.
(2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable
is "true", then the ``client_cert_source`` property can be used
to provide client certificate for mutual TLS transport. If
not provided, the default SSL client certificate will be used if
present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not
set, no client certificate will be used.
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
The client info used to send a user-agent string along with
API requests. If ``None``, then default info will be used.
Expand All @@ -236,29 +241,47 @@ def __init__(
creation failed for any reason.
"""
if isinstance(client_options, dict):
client_options = ClientOptions.from_dict(client_options)
client_options = client_options_lib.from_dict(client_options)
if client_options is None:
client_options = ClientOptions.ClientOptions()
client_options = client_options_lib.ClientOptions()

if client_options.api_endpoint is None:
use_mtls_env = os.getenv("GOOGLE_API_USE_MTLS", "never")
# Create SSL credentials for mutual TLS if needed.
use_client_cert = bool(
util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"))
)

ssl_credentials = 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
else:
creds = SslCredentials()
is_mtls = creds.is_mtls
ssl_credentials = creds.ssl_credentials if is_mtls else None

# Figure out which api endpoint to use.
if client_options.api_endpoint is not None:
api_endpoint = client_options.api_endpoint
else:
use_mtls_env = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto")
if use_mtls_env == "never":
client_options.api_endpoint = self.DEFAULT_ENDPOINT
api_endpoint = self.DEFAULT_ENDPOINT
elif use_mtls_env == "always":
client_options.api_endpoint = self.DEFAULT_MTLS_ENDPOINT
api_endpoint = self.DEFAULT_MTLS_ENDPOINT
elif use_mtls_env == "auto":
has_client_cert_source = (
client_options.client_cert_source is not None
or mtls.has_default_client_cert_source()
)
client_options.api_endpoint = (
self.DEFAULT_MTLS_ENDPOINT
if has_client_cert_source
else self.DEFAULT_ENDPOINT
api_endpoint = (
self.DEFAULT_MTLS_ENDPOINT if is_mtls else self.DEFAULT_ENDPOINT
)
else:
raise MutualTLSChannelError(
"Unsupported GOOGLE_API_USE_MTLS value. Accepted values: never, auto, always"
"Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted values: never, auto, always"
)

# Save or instantiate the transport.
Expand All @@ -282,10 +305,9 @@ def __init__(
self._transport = Transport(
credentials=credentials,
credentials_file=client_options.credentials_file,
host=client_options.api_endpoint,
host=api_endpoint,
scopes=client_options.scopes,
api_mtls_endpoint=client_options.api_endpoint,
client_cert_source=client_options.client_cert_source,
ssl_channel_credentials=ssl_credentials,
quota_project_id=client_options.quota_project_id,
client_info=client_info,
)
Expand Down
2 changes: 1 addition & 1 deletion google/cloud/automl_v1/services/auto_ml/transports/base.py
Expand Up @@ -19,7 +19,7 @@
import typing
import pkg_resources

from google import auth
from google import auth # type: ignore
from google.api_core import exceptions # type: ignore
from google.api_core import gapic_v1 # type: ignore
from google.api_core import retry as retries # type: ignore
Expand Down
46 changes: 32 additions & 14 deletions google/cloud/automl_v1/services/auto_ml/transports/grpc.py
Expand Up @@ -15,6 +15,7 @@
# limitations under the License.
#

import warnings
from typing import Callable, Dict, Optional, Sequence, Tuple

from google.api_core import grpc_helpers # type: ignore
Expand All @@ -24,7 +25,6 @@
from google.auth import credentials # type: ignore
from google.auth.transport.grpc import SslCredentials # type: ignore


import grpc # type: ignore

from google.cloud.automl_v1.types import annotation_spec
Expand Down Expand Up @@ -78,6 +78,7 @@ def __init__(
channel: grpc.Channel = None,
api_mtls_endpoint: str = None,
client_cert_source: Callable[[], Tuple[bytes, bytes]] = None,
ssl_channel_credentials: grpc.ChannelCredentials = None,
quota_project_id: Optional[str] = None,
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
) -> None:
Expand All @@ -98,14 +99,16 @@ def __init__(
ignored if ``channel`` is provided.
channel (Optional[grpc.Channel]): A ``Channel`` instance through
which to make calls.
api_mtls_endpoint (Optional[str]): The mutual TLS endpoint. If
provided, it overrides the ``host`` argument and tries to create
api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint.
If provided, it overrides the ``host`` argument and tries to create
a mutual TLS channel with client SSL credentials from
``client_cert_source`` or applicatin default SSL credentials.
client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): A
callback to provide client SSL certificate bytes and private key
bytes, both in PEM format. It is ignored if ``api_mtls_endpoint``
is None.
client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]):
Deprecated. A callback to provide client SSL certificate bytes and
private key bytes, both in PEM format. It is ignored if
``api_mtls_endpoint`` is None.
ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials
for grpc channel. It is ignored if ``channel`` 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):
Expand All @@ -128,6 +131,11 @@ def __init__(
# If a channel was explicitly provided, set it.
self._grpc_channel = channel
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
Expand Down Expand Up @@ -158,6 +166,23 @@ def __init__(
scopes=scopes or self.AUTH_SCOPES,
quota_project_id=quota_project_id,
)
else:
host = host if ":" in host else host + ":443"

if credentials is None:
credentials, _ = auth.default(
scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id
)

# 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,
scopes=scopes or self.AUTH_SCOPES,
quota_project_id=quota_project_id,
)

self._stubs = {} # type: Dict[str, Callable]

Expand Down Expand Up @@ -223,13 +248,6 @@ def grpc_channel(self) -> grpc.Channel:
This property caches on the instance; repeated calls return
the same channel.
"""
# Sanity check: Only create a new channel if we do not already
# have one.
if not hasattr(self, "_grpc_channel"):
self._grpc_channel = self.create_channel(
self._host, credentials=self._credentials,
)

# Return the channel from cache.
return self._grpc_channel

Expand Down