Skip to content

Commit

Permalink
fix: disable always_use_jwt_access (#395)
Browse files Browse the repository at this point in the history
fix: disable always_use_jwt_access

Committer: @busunkim96
PiperOrigin-RevId: 382142900

Source-Link: googleapis/googleapis@513440f

Source-Link: googleapis/googleapis-gen@7b1e2c3
  • Loading branch information
gcf-owl-bot[bot] committed Jul 5, 2021
1 parent aaf154b commit c37bf21
Show file tree
Hide file tree
Showing 16 changed files with 120 additions and 51 deletions.
Expand Up @@ -108,7 +108,7 @@ def __init__(
scopes_kwargs = self._get_scopes_kwargs(self._host, scopes)

# Save the scopes.
self._scopes = scopes or self.AUTH_SCOPES
self._scopes = scopes

# If no credentials are provided, then determine the appropriate
# defaults.
Expand Down
Expand Up @@ -69,6 +69,7 @@ def __init__(
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,
always_use_jwt_access: Optional[bool] = False,
) -> None:
"""Instantiate the transport.
Expand Down Expand Up @@ -109,6 +110,8 @@ def __init__(
API requests. If ``None``, then default info will be used.
Generally, you only need to set this if you're developing
your own client library.
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
be used for service account credentials.
Raises:
google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
Expand Down Expand Up @@ -162,7 +165,7 @@ def __init__(
scopes=scopes,
quota_project_id=quota_project_id,
client_info=client_info,
always_use_jwt_access=True,
always_use_jwt_access=always_use_jwt_access,
)

if not self._grpc_channel:
Expand Down
Expand Up @@ -115,6 +115,7 @@ def __init__(
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
quota_project_id=None,
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
always_use_jwt_access: Optional[bool] = False,
) -> None:
"""Instantiate the transport.
Expand Down Expand Up @@ -156,6 +157,8 @@ def __init__(
API requests. If ``None``, then default info will be used.
Generally, you only need to set this if you're developing
your own client library.
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
be used for service account credentials.
Raises:
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
Expand Down Expand Up @@ -208,7 +211,7 @@ def __init__(
scopes=scopes,
quota_project_id=quota_project_id,
client_info=client_info,
always_use_jwt_access=True,
always_use_jwt_access=always_use_jwt_access,
)

if not self._grpc_channel:
Expand Down
Expand Up @@ -121,6 +121,14 @@ class Database(proto.Message):
sure to account for the time from the moment
when the value is queried to the moment when you
initiate the recovery.
default_leader (str):
Output only. The read-write region which contains the
database's leader replicas.
This is the same as the value of default_leader database
option set using DatabaseAdmin.CreateDatabase or
DatabaseAdmin.UpdateDatabaseDdl. If not explicitly set, this
is empty.
"""

class State(proto.Enum):
Expand All @@ -144,6 +152,7 @@ class State(proto.Enum):
earliest_version_time = proto.Field(
proto.MESSAGE, number=7, message=timestamp_pb2.Timestamp,
)
default_leader = proto.Field(proto.STRING, number=9,)


class ListDatabasesRequest(proto.Message):
Expand Down
Expand Up @@ -106,7 +106,7 @@ def __init__(
scopes_kwargs = self._get_scopes_kwargs(self._host, scopes)

# Save the scopes.
self._scopes = scopes or self.AUTH_SCOPES
self._scopes = scopes

# If no credentials are provided, then determine the appropriate
# defaults.
Expand Down
Expand Up @@ -82,6 +82,7 @@ def __init__(
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,
always_use_jwt_access: Optional[bool] = False,
) -> None:
"""Instantiate the transport.
Expand Down Expand Up @@ -122,6 +123,8 @@ def __init__(
API requests. If ``None``, then default info will be used.
Generally, you only need to set this if you're developing
your own client library.
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
be used for service account credentials.
Raises:
google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
Expand Down Expand Up @@ -175,7 +178,7 @@ def __init__(
scopes=scopes,
quota_project_id=quota_project_id,
client_info=client_info,
always_use_jwt_access=True,
always_use_jwt_access=always_use_jwt_access,
)

if not self._grpc_channel:
Expand Down
Expand Up @@ -128,6 +128,7 @@ def __init__(
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
quota_project_id=None,
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
always_use_jwt_access: Optional[bool] = False,
) -> None:
"""Instantiate the transport.
Expand Down Expand Up @@ -169,6 +170,8 @@ def __init__(
API requests. If ``None``, then default info will be used.
Generally, you only need to set this if you're developing
your own client library.
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
be used for service account credentials.
Raises:
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
Expand Down Expand Up @@ -221,7 +224,7 @@ def __init__(
scopes=scopes,
quota_project_id=quota_project_id,
client_info=client_info,
always_use_jwt_access=True,
always_use_jwt_access=always_use_jwt_access,
)

if not self._grpc_channel:
Expand Down
Expand Up @@ -88,11 +88,15 @@ class InstanceConfig(proto.Message):
The geographic placement of nodes in this
instance configuration and their replication
properties.
leader_options (Sequence[str]):
Allowed values of the “default_leader” schema option for
databases in instances that use this instance configuration.
"""

name = proto.Field(proto.STRING, number=1,)
display_name = proto.Field(proto.STRING, number=2,)
replicas = proto.RepeatedField(proto.MESSAGE, number=3, message="ReplicaInfo",)
leader_options = proto.RepeatedField(proto.STRING, number=4,)


class Instance(proto.Message):
Expand Down
Expand Up @@ -103,7 +103,7 @@ def __init__(
scopes_kwargs = self._get_scopes_kwargs(self._host, scopes)

# Save the scopes.
self._scopes = scopes or self.AUTH_SCOPES
self._scopes = scopes

# If no credentials are provided, then determine the appropriate
# defaults.
Expand Down
5 changes: 4 additions & 1 deletion google/cloud/spanner_v1/services/spanner/transports/grpc.py
Expand Up @@ -63,6 +63,7 @@ def __init__(
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,
always_use_jwt_access: Optional[bool] = False,
) -> None:
"""Instantiate the transport.
Expand Down Expand Up @@ -103,6 +104,8 @@ def __init__(
API requests. If ``None``, then default info will be used.
Generally, you only need to set this if you're developing
your own client library.
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
be used for service account credentials.
Raises:
google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
Expand Down Expand Up @@ -155,7 +158,7 @@ def __init__(
scopes=scopes,
quota_project_id=quota_project_id,
client_info=client_info,
always_use_jwt_access=True,
always_use_jwt_access=always_use_jwt_access,
)

if not self._grpc_channel:
Expand Down
Expand Up @@ -109,6 +109,7 @@ def __init__(
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
quota_project_id=None,
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
always_use_jwt_access: Optional[bool] = False,
) -> None:
"""Instantiate the transport.
Expand Down Expand Up @@ -150,6 +151,8 @@ def __init__(
API requests. If ``None``, then default info will be used.
Generally, you only need to set this if you're developing
your own client library.
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
be used for service account credentials.
Raises:
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
Expand Down Expand Up @@ -201,7 +204,7 @@ def __init__(
scopes=scopes,
quota_project_id=quota_project_id,
client_info=client_info,
always_use_jwt_access=True,
always_use_jwt_access=always_use_jwt_access,
)

if not self._grpc_channel:
Expand Down
1 change: 1 addition & 0 deletions google/cloud/spanner_v1/types/type.py
Expand Up @@ -41,6 +41,7 @@ class TypeCode(proto.Enum):
ARRAY = 8
STRUCT = 9
NUMERIC = 10
JSON = 11


class Type(proto.Message):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -30,7 +30,7 @@
release_status = "Development Status :: 5 - Production/Stable"
dependencies = [
"google-api-core[grpc] >= 1.26.0, <2.0.0dev",
"" "google-cloud-core >= 1.4.1, < 2.0dev",
"google-cloud-core >= 1.4.1, < 2.0dev",
"grpc-google-iam-v1 >= 0.12.3, < 0.13dev",
"proto-plus >= 1.11.0",
"sqlparse >= 0.3.0",
Expand Down
39 changes: 26 additions & 13 deletions tests/unit/gapic/spanner_admin_database_v1/test_database_admin.py
Expand Up @@ -147,7 +147,25 @@ def test_database_admin_client_service_account_always_use_jwt(client_class):
) as use_jwt:
creds = service_account.Credentials(None, None, None)
client = client_class(credentials=creds)
use_jwt.assert_called_with(True)
use_jwt.assert_not_called()


@pytest.mark.parametrize(
"transport_class,transport_name",
[
(transports.DatabaseAdminGrpcTransport, "grpc"),
(transports.DatabaseAdminGrpcAsyncIOTransport, "grpc_asyncio"),
],
)
def test_database_admin_client_service_account_always_use_jwt_true(
transport_class, transport_name
):
with mock.patch.object(
service_account.Credentials, "with_always_use_jwt_access", create=True
) as use_jwt:
creds = service_account.Credentials(None, None, None)
transport = transport_class(credentials=creds, always_use_jwt_access=True)
use_jwt.assert_called_once_with(True)


@pytest.mark.parametrize(
Expand Down Expand Up @@ -1085,6 +1103,7 @@ def test_get_database(
name="name_value",
state=spanner_database_admin.Database.State.CREATING,
version_retention_period="version_retention_period_value",
default_leader="default_leader_value",
)
response = client.get_database(request)

Expand All @@ -1098,6 +1117,7 @@ def test_get_database(
assert response.name == "name_value"
assert response.state == spanner_database_admin.Database.State.CREATING
assert response.version_retention_period == "version_retention_period_value"
assert response.default_leader == "default_leader_value"


def test_get_database_from_dict():
Expand Down Expand Up @@ -1140,6 +1160,7 @@ async def test_get_database_async(
name="name_value",
state=spanner_database_admin.Database.State.CREATING,
version_retention_period="version_retention_period_value",
default_leader="default_leader_value",
)
)
response = await client.get_database(request)
Expand All @@ -1154,6 +1175,7 @@ async def test_get_database_async(
assert response.name == "name_value"
assert response.state == spanner_database_admin.Database.State.CREATING
assert response.version_retention_period == "version_retention_period_value"
assert response.default_leader == "default_leader_value"


@pytest.mark.asyncio
Expand Down Expand Up @@ -5046,10 +5068,7 @@ def test_database_admin_grpc_transport_client_cert_source_for_mtls(transport_cla
"squid.clam.whelk:443",
credentials=cred,
credentials_file=None,
scopes=(
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/spanner.admin",
),
scopes=None,
ssl_credentials=mock_ssl_channel_creds,
quota_project_id=None,
options=[
Expand Down Expand Up @@ -5156,10 +5175,7 @@ def test_database_admin_transport_channel_mtls_with_client_cert_source(transport
"mtls.squid.clam.whelk:443",
credentials=cred,
credentials_file=None,
scopes=(
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/spanner.admin",
),
scopes=None,
ssl_credentials=mock_ssl_cred,
quota_project_id=None,
options=[
Expand Down Expand Up @@ -5206,10 +5222,7 @@ def test_database_admin_transport_channel_mtls_with_adc(transport_class):
"mtls.squid.clam.whelk:443",
credentials=mock_cred,
credentials_file=None,
scopes=(
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/spanner.admin",
),
scopes=None,
ssl_credentials=mock_ssl_cred,
quota_project_id=None,
options=[
Expand Down

0 comments on commit c37bf21

Please sign in to comment.