GeezerVison is showing github.com — Revert "feat: add always_use_jwt_access (#498)" (#552) · RCLDevelopers/python-aiplatform@fdeb51b
File treeExpand file treeCollapse file tree Open diff view settings aiplatform_v1beta1/services dataset_service/transports endpoint_service/transports featurestore_online_serving_service/transports featurestore_service/transports index_endpoint_service/transports metadata_service/transports migration_service/transports pipeline_service/transports prediction_service/transports specialist_pool_service/transports tensorboard_service/transports vizier_service/transports
dataset_service/transports endpoint_service/transports migration_service/transports pipeline_service/transports prediction_service/transports specialist_pool_service/transports
Some content is hiddenLarge Commits have some content hidden by default. Use the searchbox below for content that may be hidden. Dismiss bannerExpand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: google/cloud/aiplatform_v1/services/dataset_service/transports/base.py +27-15Lines changed: 27 additions & 15 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 25 | 25 | from google.api_core import retry as retries # type: ignore | 26 | 26 | from google.api_core import operations_v1 # type: ignore | 27 | 27 | from google.auth import credentials as ga_credentials # type: ignore | 28 | | -from google.oauth2 import service_account # type: ignore | 29 | 28 |
| 30 | 29 | from google.cloud.aiplatform_v1.types import annotation_spec | 31 | 30 | from google.cloud.aiplatform_v1.types import dataset | | 51 | 50 | except pkg_resources.DistributionNotFound: # pragma: NO COVER | 52 | 51 | _GOOGLE_AUTH_VERSION = None | 53 | 52 |
| | 53 | +_API_CORE_VERSION = google.api_core.__version__ | | 54 | + | 54 | 55 |
| 55 | 56 | class DatasetServiceTransport(abc.ABC): | 56 | 57 | """Abstract transport class for DatasetService.""" | @@ -68,7 +69,6 @@ def __init__( | 68 | 69 | scopes: Optional[Sequence[str]] = None, | 69 | 70 | quota_project_id: Optional[str] = None, | 70 | 71 | client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, | 71 | | - always_use_jwt_access: Optional[bool] = False, | 72 | 72 | **kwargs, | 73 | 73 | ) -> None: | 74 | 74 | """Instantiate the transport. | @@ -92,8 +92,6 @@ def __init__( | 92 | 92 | API requests. If ``None``, then default info will be used. | 93 | 93 | Generally, you only need to set this if you're developing | 94 | 94 | your own client library. | 95 | | - always_use_jwt_access (Optional[bool]): Whether self signed JWT should | 96 | | - be used for service account credentials. | 97 | 95 | """ | 98 | 96 | # Save the hostname. Default to port 443 (HTTPS) if none is specified. | 99 | 97 | if ":" not in host: | @@ -103,7 +101,7 @@ def __init__( | 103 | 101 | scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) | 104 | 102 |
| 105 | 103 | # Save the scopes. | 106 | | - self._scopes = scopes | | 104 | + self._scopes = scopes or self.AUTH_SCOPES | 107 | 105 |
| 108 | 106 | # If no credentials are provided, then determine the appropriate | 109 | 107 | # defaults. | @@ -122,20 +120,13 @@ def __init__( | 122 | 120 | **scopes_kwargs, quota_project_id=quota_project_id | 123 | 121 | ) | 124 | 122 |
| 125 | | - # If the credentials is service account credentials, then always try to use self signed JWT. | 126 | | - if ( | 127 | | - always_use_jwt_access | 128 | | - and isinstance(credentials, service_account.Credentials) | 129 | | - and hasattr(service_account.Credentials, "with_always_use_jwt_access") | 130 | | - ): | 131 | | - credentials = credentials.with_always_use_jwt_access(True) | 132 | | - | 133 | 123 | # Save the credentials. | 134 | 124 | self._credentials = credentials | 135 | 125 |
| 136 | | - # TODO(busunkim): This method is in the base transport | | 126 | + # TODO(busunkim): These two class methods are in the base transport | 137 | 127 | # to avoid duplicating code across the transport classes. These functions | 138 | | - # should be deleted once the minimum required versions of google-auth is increased. | | 128 | + # should be deleted once the minimum required versions of google-api-core | | 129 | + # and google-auth are increased. | 139 | 130 |
| 140 | 131 | # TODO: Remove this function once google-auth >= 1.25.0 is required | 141 | 132 | @classmethod | @@ -156,6 +147,27 @@ def _get_scopes_kwargs( | 156 | 147 |
| 157 | 148 | return scopes_kwargs | 158 | 149 |
| | 150 | + # TODO: Remove this function once google-api-core >= 1.26.0 is required | | 151 | + @classmethod | | 152 | + def _get_self_signed_jwt_kwargs( | | 153 | + cls, host: str, scopes: Optional[Sequence[str]] | | 154 | + ) -> Dict[str, Union[Optional[Sequence[str]], str]]: | | 155 | + """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" | | 156 | + | | 157 | + self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} | | 158 | + | | 159 | + if _API_CORE_VERSION and ( | | 160 | + packaging.version.parse(_API_CORE_VERSION) | | 161 | + >= packaging.version.parse("1.26.0") | | 162 | + ): | | 163 | + self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES | | 164 | + self_signed_jwt_kwargs["scopes"] = scopes | | 165 | + self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST | | 166 | + else: | | 167 | + self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES | | 168 | + | | 169 | + return self_signed_jwt_kwargs | | 170 | + | 159 | 171 | def _prep_wrapped_messages(self, client_info): | 160 | 172 | # Precompute the wrapped methods. | 161 | 173 | self._wrapped_methods = { | |
Collapse file Copy file name to clipboardExpand all lines: google/cloud/aiplatform_v1/services/dataset_service/transports/grpc.py +3-7Lines changed: 3 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -60,7 +60,6 @@ def __init__( | 60 | 60 | client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, | 61 | 61 | quota_project_id: Optional[str] = None, | 62 | 62 | client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, | 63 | | - always_use_jwt_access: Optional[bool] = False, | 64 | 63 | ) -> None: | 65 | 64 | """Instantiate the transport. | 66 | 65 |
| @@ -101,8 +100,6 @@ def __init__( | 101 | 100 | API requests. If ``None``, then default info will be used. | 102 | 101 | Generally, you only need to set this if you're developing | 103 | 102 | your own client library. | 104 | | - always_use_jwt_access (Optional[bool]): Whether self signed JWT should | 105 | | - be used for service account credentials. | 106 | 103 |
| 107 | 104 | Raises: | 108 | 105 | google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport | @@ -156,7 +153,6 @@ def __init__( | 156 | 153 | scopes=scopes, | 157 | 154 | quota_project_id=quota_project_id, | 158 | 155 | client_info=client_info, | 159 | | - always_use_jwt_access=always_use_jwt_access, | 160 | 156 | ) | 161 | 157 |
| 162 | 158 | if not self._grpc_channel: | @@ -212,14 +208,14 @@ def create_channel( | 212 | 208 | and ``credentials_file`` are passed. | 213 | 209 | """ | 214 | 210 |
| | 211 | + self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) | | 212 | + | 215 | 213 | return grpc_helpers.create_channel( | 216 | 214 | host, | 217 | 215 | credentials=credentials, | 218 | 216 | credentials_file=credentials_file, | 219 | 217 | quota_project_id=quota_project_id, | 220 | | - default_scopes=cls.AUTH_SCOPES, | 221 | | - scopes=scopes, | 222 | | - default_host=cls.DEFAULT_HOST, | | 218 | + **self_signed_jwt_kwargs, | 223 | 219 | **kwargs, | 224 | 220 | ) | 225 | 221 |
| |
Collapse file Copy file name to clipboardExpand all lines: google/cloud/aiplatform_v1/services/dataset_service/transports/grpc_asyncio.py +3-7Lines changed: 3 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -81,14 +81,14 @@ def create_channel( | 81 | 81 | aio.Channel: A gRPC AsyncIO channel object. | 82 | 82 | """ | 83 | 83 |
| | 84 | + self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) | | 85 | + | 84 | 86 | return grpc_helpers_async.create_channel( | 85 | 87 | host, | 86 | 88 | credentials=credentials, | 87 | 89 | credentials_file=credentials_file, | 88 | 90 | quota_project_id=quota_project_id, | 89 | | - default_scopes=cls.AUTH_SCOPES, | 90 | | - scopes=scopes, | 91 | | - default_host=cls.DEFAULT_HOST, | | 91 | + **self_signed_jwt_kwargs, | 92 | 92 | **kwargs, | 93 | 93 | ) | 94 | 94 |
| @@ -106,7 +106,6 @@ def __init__( | 106 | 106 | client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, | 107 | 107 | quota_project_id=None, | 108 | 108 | client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, | 109 | | - always_use_jwt_access: Optional[bool] = False, | 110 | 109 | ) -> None: | 111 | 110 | """Instantiate the transport. | 112 | 111 |
| @@ -148,8 +147,6 @@ def __init__( | 148 | 147 | API requests. If ``None``, then default info will be used. | 149 | 148 | Generally, you only need to set this if you're developing | 150 | 149 | your own client library. | 151 | | - always_use_jwt_access (Optional[bool]): Whether self signed JWT should | 152 | | - be used for service account credentials. | 153 | 150 |
| 154 | 151 | Raises: | 155 | 152 | google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport | @@ -202,7 +199,6 @@ def __init__( | 202 | 199 | scopes=scopes, | 203 | 200 | quota_project_id=quota_project_id, | 204 | 201 | client_info=client_info, | 205 | | - always_use_jwt_access=always_use_jwt_access, | 206 | 202 | ) | 207 | 203 |
| 208 | 204 | if not self._grpc_channel: | |
Collapse file Copy file name to clipboardExpand all lines: google/cloud/aiplatform_v1/services/endpoint_service/transports/base.py +27-15Lines changed: 27 additions & 15 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 25 | 25 | from google.api_core import retry as retries # type: ignore | 26 | 26 | from google.api_core import operations_v1 # type: ignore | 27 | 27 | from google.auth import credentials as ga_credentials # type: ignore | 28 | | -from google.oauth2 import service_account # type: ignore | 29 | 28 |
| 30 | 29 | from google.cloud.aiplatform_v1.types import endpoint | 31 | 30 | from google.cloud.aiplatform_v1.types import endpoint as gca_endpoint | | 50 | 49 | except pkg_resources.DistributionNotFound: # pragma: NO COVER | 51 | 50 | _GOOGLE_AUTH_VERSION = None | 52 | 51 |
| | 52 | +_API_CORE_VERSION = google.api_core.__version__ | | 53 | + | 53 | 54 |
| 54 | 55 | class EndpointServiceTransport(abc.ABC): | 55 | 56 | """Abstract transport class for EndpointService.""" | @@ -67,7 +68,6 @@ def __init__( | 67 | 68 | scopes: Optional[Sequence[str]] = None, | 68 | 69 | quota_project_id: Optional[str] = None, | 69 | 70 | client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, | 70 | | - always_use_jwt_access: Optional[bool] = False, | 71 | 71 | **kwargs, | 72 | 72 | ) -> None: | 73 | 73 | """Instantiate the transport. | @@ -91,8 +91,6 @@ def __init__( | 91 | 91 | API requests. If ``None``, then default info will be used. | 92 | 92 | Generally, you only need to set this if you're developing | 93 | 93 | your own client library. | 94 | | - always_use_jwt_access (Optional[bool]): Whether self signed JWT should | 95 | | - be used for service account credentials. | 96 | 94 | """ | 97 | 95 | # Save the hostname. Default to port 443 (HTTPS) if none is specified. | 98 | 96 | if ":" not in host: | @@ -102,7 +100,7 @@ def __init__( | 102 | 100 | scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) | 103 | 101 |
| 104 | 102 | # Save the scopes. | 105 | | - self._scopes = scopes | | 103 | + self._scopes = scopes or self.AUTH_SCOPES | 106 | 104 |
| 107 | 105 | # If no credentials are provided, then determine the appropriate | 108 | 106 | # defaults. | @@ -121,20 +119,13 @@ def __init__( | 121 | 119 | **scopes_kwargs, quota_project_id=quota_project_id | 122 | 120 | ) | 123 | 121 |
| 124 | | - # If the credentials is service account credentials, then always try to use self signed JWT. | 125 | | - if ( | 126 | | - always_use_jwt_access | 127 | | - and isinstance(credentials, service_account.Credentials) | 128 | | - and hasattr(service_account.Credentials, "with_always_use_jwt_access") | 129 | | - ): | 130 | | - credentials = credentials.with_always_use_jwt_access(True) | 131 | | - | 132 | 122 | # Save the credentials. | 133 | 123 | self._credentials = credentials | 134 | 124 |
| 135 | | - # TODO(busunkim): This method is in the base transport | | 125 | + # TODO(busunkim): These two class methods are in the base transport | 136 | 126 | # to avoid duplicating code across the transport classes. These functions | 137 | | - # should be deleted once the minimum required versions of google-auth is increased. | | 127 | + # should be deleted once the minimum required versions of google-api-core | | 128 | + # and google-auth are increased. | 138 | 129 |
| 139 | 130 | # TODO: Remove this function once google-auth >= 1.25.0 is required | 140 | 131 | @classmethod | @@ -155,6 +146,27 @@ def _get_scopes_kwargs( | 155 | 146 |
| 156 | 147 | return scopes_kwargs | 157 | 148 |
| | 149 | + # TODO: Remove this function once google-api-core >= 1.26.0 is required | | 150 | + @classmethod | | 151 | + def _get_self_signed_jwt_kwargs( | | 152 | + cls, host: str, scopes: Optional[Sequence[str]] | | 153 | + ) -> Dict[str, Union[Optional[Sequence[str]], str]]: | | 154 | + """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" | | 155 | + | | 156 | + self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} | | 157 | + | | 158 | + if _API_CORE_VERSION and ( | | 159 | + packaging.version.parse(_API_CORE_VERSION) | | 160 | + >= packaging.version.parse("1.26.0") | | 161 | + ): | | 162 | + self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES | | 163 | + self_signed_jwt_kwargs["scopes"] = scopes | | 164 | + self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST | | 165 | + else: | | 166 | + self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES | | 167 | + | | 168 | + return self_signed_jwt_kwargs | | 169 | + | 158 | 170 | def _prep_wrapped_messages(self, client_info): | 159 | 171 | # Precompute the wrapped methods. | 160 | 172 | self._wrapped_methods = { | |
Collapse file Copy file name to clipboardExpand all lines: google/cloud/aiplatform_v1/services/endpoint_service/transports/grpc.py +3-7Lines changed: 3 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -59,7 +59,6 @@ def __init__( | 59 | 59 | client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, | 60 | 60 | quota_project_id: Optional[str] = None, | 61 | 61 | client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, | 62 | | - always_use_jwt_access: Optional[bool] = False, | 63 | 62 | ) -> None: | 64 | 63 | """Instantiate the transport. | 65 | 64 |
| @@ -100,8 +99,6 @@ def __init__( | 100 | 99 | API requests. If ``None``, then default info will be used. | 101 | 100 | Generally, you only need to set this if you're developing | 102 | 101 | your own client library. | 103 | | - always_use_jwt_access (Optional[bool]): Whether self signed JWT should | 104 | | - be used for service account credentials. | 105 | 102 |
| 106 | 103 | Raises: | 107 | 104 | google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport | @@ -155,7 +152,6 @@ def __init__( | 155 | 152 | scopes=scopes, | 156 | 153 | quota_project_id=quota_project_id, | 157 | 154 | client_info=client_info, | 158 | | - always_use_jwt_access=always_use_jwt_access, | 159 | 155 | ) | 160 | 156 |
| 161 | 157 | if not self._grpc_channel: | @@ -211,14 +207,14 @@ def create_channel( | 211 | 207 | and ``credentials_file`` are passed. | 212 | 208 | """ | 213 | 209 |
| | 210 | + self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) | | 211 | + | 214 | 212 | return grpc_helpers.create_channel( | 215 | 213 | host, | 216 | 214 | credentials=credentials, | 217 | 215 | credentials_file=credentials_file, | 218 | 216 | quota_project_id=quota_project_id, | 219 | | - default_scopes=cls.AUTH_SCOPES, | 220 | | - scopes=scopes, | 221 | | - default_host=cls.DEFAULT_HOST, | | 217 | + **self_signed_jwt_kwargs, | 222 | 218 | **kwargs, | 223 | 219 | ) | 224 | 220 |
| |
Collapse file Copy file name to clipboardExpand all lines: google/cloud/aiplatform_v1/services/endpoint_service/transports/grpc_asyncio.py +3-7Lines changed: 3 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -80,14 +80,14 @@ def create_channel( | 80 | 80 | aio.Channel: A gRPC AsyncIO channel object. | 81 | 81 | """ | 82 | 82 |
| | 83 | + self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) | | 84 | + | 83 | 85 | return grpc_helpers_async.create_channel( | 84 | 86 | host, | 85 | 87 | credentials=credentials, | 86 | 88 | credentials_file=credentials_file, | 87 | 89 | quota_project_id=quota_project_id, | 88 | | - default_scopes=cls.AUTH_SCOPES, | 89 | | - scopes=scopes, | 90 | | - default_host=cls.DEFAULT_HOST, | | 90 | + **self_signed_jwt_kwargs, | 91 | 91 | **kwargs, | 92 | 92 | ) | 93 | 93 |
| @@ -105,7 +105,6 @@ def __init__( | 105 | 105 | client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, | 106 | 106 | quota_project_id=None, | 107 | 107 | client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, | 108 | | - always_use_jwt_access: Optional[bool] = False, | 109 | 108 | ) -> None: | 110 | 109 | """Instantiate the transport. | 111 | 110 |
| @@ -147,8 +146,6 @@ def __init__( | 147 | 146 | API requests. If ``None``, then default info will be used. | 148 | 147 | Generally, you only need to set this if you're developing | 149 | 148 | your own client library. | 150 | | - always_use_jwt_access (Optional[bool]): Whether self signed JWT should | 151 | | - be used for service account credentials. | 152 | 149 |
| 153 | 150 | Raises: | 154 | 151 | google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport | @@ -201,7 +198,6 @@ def __init__( | 201 | 198 | scopes=scopes, | 202 | 199 | quota_project_id=quota_project_id, | 203 | 200 | client_info=client_info, | 204 | | - always_use_jwt_access=always_use_jwt_access, | 205 | 201 | ) | 206 | 202 |
| 207 | 203 | if not self._grpc_channel: | |
|