Skip to content

Commit

Permalink
fix: fix credentials typing issue in transport layer (#2043)
Browse files Browse the repository at this point in the history
  • Loading branch information
parthea authored Jun 20, 2024
1 parent 44e9b30 commit 205fe5e
Show file tree
Hide file tree
Showing 34 changed files with 78 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ class {{ service.name }}Transport(abc.ABC):
# Save the scopes.
self._scopes = scopes

if not hasattr(self, "_ignore_credentials"):
self._ignore_credentials: bool = False

# If no credentials are provided, then determine the appropriate
# defaults.
if credentials and credentials_file:
Expand All @@ -114,7 +117,7 @@ class {{ service.name }}Transport(abc.ABC):
**scopes_kwargs,
quota_project_id=quota_project_id
)
elif credentials is None:
elif credentials is None and not self._ignore_credentials:
credentials, _ = google.auth.default(**scopes_kwargs, quota_project_id=quota_project_id)

# If the credentials are service account credentials, then always try to use self signed JWT.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ class {{ service.name }}GrpcTransport({{ service.name }}Transport):

if channel:
# Ignore credentials if a channel was passed.
credentials = False
credentials = None
self._ignore_credentials = True
# If a channel was explicitly provided, set it.
self._grpc_channel = channel
self._ssl_channel_credentials = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ class {{ service.name }}Transport(abc.ABC):

# Save the scopes.
self._scopes = scopes
if not hasattr(self, "_ignore_credentials"):
self._ignore_credentials: bool = False

# If no credentials are provided, then determine the appropriate
# defaults.
Expand All @@ -119,7 +121,7 @@ class {{ service.name }}Transport(abc.ABC):
**scopes_kwargs,
quota_project_id=quota_project_id
)
elif credentials is None:
elif credentials is None and not self._ignore_credentials:
credentials, _ = google.auth.default(**scopes_kwargs, quota_project_id=quota_project_id)
# Don't apply audience if the credentials file passed from user.
if hasattr(credentials, "with_gdch_audience"):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ class {{ service.name }}GrpcTransport({{ service.name }}Transport):

if isinstance(channel, grpc.Channel):
# Ignore credentials if a channel was passed.
credentials = False
credentials = None
self._ignore_credentials = True
# If a channel was explicitly provided, set it.
self._grpc_channel = channel
self._ssl_channel_credentials = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ class {{ service.grpc_asyncio_transport_name }}({{ service.name }}Transport):

if isinstance(channel, aio.Channel):
# Ignore credentials if a channel was passed.
credentials = False
credentials = None
self._ignore_credentials = True
# If a channel was explicitly provided, set it.
self._grpc_channel = channel
self._ssl_channel_credentials = None
Expand Down
2 changes: 2 additions & 0 deletions gapic/templates/noxfile.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ def mypy(session):
'types-protobuf'
)
session.install('.')
# Remove once https://github.com/googleapis/python-api-core/pull/650 is merged
session.install("google-api-core>=2.19.1rc0")
session.run(
'mypy',
'-p',
Expand Down
2 changes: 1 addition & 1 deletion gapic/utils/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def wrap(text: str, width: int, *, offset: Optional[int] = None, indent: int = 0
break_long_words=False,
initial_indent=' ' * indent,
# ensure that subsequent lines for lists are indented 2 spaces
subsequent_indent=' ' * indent + \
subsequent_indent=' ' * indent +
' ' * get_subsequent_line_indentation_level(token.strip()),
text=token,
width=width,
Expand Down
3 changes: 3 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ def showcase_library(
# See https://github.com/googleapis/gapic-generator-python/issues/1788
# Install the library without a constraints file.
session.install("-e", tmp_dir)

# Remove once https://github.com/googleapis/python-api-core/pull/650 is merged
session.install("google-api-core>=2.19.1rc0")
yield tmp_dir


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ def __init__(

# Save the scopes.
self._scopes = scopes
if not hasattr(self, "_ignore_credentials"):
self._ignore_credentials: bool = False

# If no credentials are provided, then determine the appropriate
# defaults.
Expand All @@ -95,7 +97,7 @@ def __init__(
**scopes_kwargs,
quota_project_id=quota_project_id
)
elif credentials is None:
elif credentials is None and not self._ignore_credentials:
credentials, _ = google.auth.default(**scopes_kwargs, quota_project_id=quota_project_id)
# Don't apply audience if the credentials file passed from user.
if hasattr(credentials, "with_gdch_audience"):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ def __init__(self, *,

if isinstance(channel, grpc.Channel):
# Ignore credentials if a channel was passed.
credentials = False
credentials = None
self._ignore_credentials = True
# If a channel was explicitly provided, set it.
self._grpc_channel = channel
self._ssl_channel_credentials = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ def __init__(self, *,

if isinstance(channel, aio.Channel):
# Ignore credentials if a channel was passed.
credentials = False
credentials = None
self._ignore_credentials = True
# If a channel was explicitly provided, set it.
self._grpc_channel = channel
self._ssl_channel_credentials = None
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/goldens/asset/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ def mypy(session):
'types-protobuf'
)
session.install('.')
# Remove once https://github.com/googleapis/python-api-core/pull/650 is merged
session.install("google-api-core>=2.19.1rc0")
session.run(
'mypy',
'-p',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ def __init__(

# Save the scopes.
self._scopes = scopes
if not hasattr(self, "_ignore_credentials"):
self._ignore_credentials: bool = False

# If no credentials are provided, then determine the appropriate
# defaults.
Expand All @@ -92,7 +94,7 @@ def __init__(
**scopes_kwargs,
quota_project_id=quota_project_id
)
elif credentials is None:
elif credentials is None and not self._ignore_credentials:
credentials, _ = google.auth.default(**scopes_kwargs, quota_project_id=quota_project_id)
# Don't apply audience if the credentials file passed from user.
if hasattr(credentials, "with_gdch_audience"):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ def __init__(self, *,

if isinstance(channel, grpc.Channel):
# Ignore credentials if a channel was passed.
credentials = False
credentials = None
self._ignore_credentials = True
# If a channel was explicitly provided, set it.
self._grpc_channel = channel
self._ssl_channel_credentials = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ def __init__(self, *,

if isinstance(channel, aio.Channel):
# Ignore credentials if a channel was passed.
credentials = False
credentials = None
self._ignore_credentials = True
# If a channel was explicitly provided, set it.
self._grpc_channel = channel
self._ssl_channel_credentials = None
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/goldens/credentials/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ def mypy(session):
'types-protobuf'
)
session.install('.')
# Remove once https://github.com/googleapis/python-api-core/pull/650 is merged
session.install("google-api-core>=2.19.1rc0")
session.run(
'mypy',
'-p',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ def __init__(

# Save the scopes.
self._scopes = scopes
if not hasattr(self, "_ignore_credentials"):
self._ignore_credentials: bool = False

# If no credentials are provided, then determine the appropriate
# defaults.
Expand All @@ -103,7 +105,7 @@ def __init__(
**scopes_kwargs,
quota_project_id=quota_project_id
)
elif credentials is None:
elif credentials is None and not self._ignore_credentials:
credentials, _ = google.auth.default(**scopes_kwargs, quota_project_id=quota_project_id)
# Don't apply audience if the credentials file passed from user.
if hasattr(credentials, "with_gdch_audience"):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ def __init__(self, *,

if isinstance(channel, grpc.Channel):
# Ignore credentials if a channel was passed.
credentials = False
credentials = None
self._ignore_credentials = True
# If a channel was explicitly provided, set it.
self._grpc_channel = channel
self._ssl_channel_credentials = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ def __init__(self, *,

if isinstance(channel, aio.Channel):
# Ignore credentials if a channel was passed.
credentials = False
credentials = None
self._ignore_credentials = True
# If a channel was explicitly provided, set it.
self._grpc_channel = channel
self._ssl_channel_credentials = None
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/goldens/eventarc/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ def mypy(session):
'types-protobuf'
)
session.install('.')
# Remove once https://github.com/googleapis/python-api-core/pull/650 is merged
session.install("google-api-core>=2.19.1rc0")
session.run(
'mypy',
'-p',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ def __init__(

# Save the scopes.
self._scopes = scopes
if not hasattr(self, "_ignore_credentials"):
self._ignore_credentials: bool = False

# If no credentials are provided, then determine the appropriate
# defaults.
Expand All @@ -98,7 +100,7 @@ def __init__(
**scopes_kwargs,
quota_project_id=quota_project_id
)
elif credentials is None:
elif credentials is None and not self._ignore_credentials:
credentials, _ = google.auth.default(**scopes_kwargs, quota_project_id=quota_project_id)
# Don't apply audience if the credentials file passed from user.
if hasattr(credentials, "with_gdch_audience"):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ def __init__(self, *,

if isinstance(channel, grpc.Channel):
# Ignore credentials if a channel was passed.
credentials = False
credentials = None
self._ignore_credentials = True
# If a channel was explicitly provided, set it.
self._grpc_channel = channel
self._ssl_channel_credentials = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ def __init__(self, *,

if isinstance(channel, aio.Channel):
# Ignore credentials if a channel was passed.
credentials = False
credentials = None
self._ignore_credentials = True
# If a channel was explicitly provided, set it.
self._grpc_channel = channel
self._ssl_channel_credentials = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ def __init__(

# Save the scopes.
self._scopes = scopes
if not hasattr(self, "_ignore_credentials"):
self._ignore_credentials: bool = False

# If no credentials are provided, then determine the appropriate
# defaults.
Expand All @@ -98,7 +100,7 @@ def __init__(
**scopes_kwargs,
quota_project_id=quota_project_id
)
elif credentials is None:
elif credentials is None and not self._ignore_credentials:
credentials, _ = google.auth.default(**scopes_kwargs, quota_project_id=quota_project_id)
# Don't apply audience if the credentials file passed from user.
if hasattr(credentials, "with_gdch_audience"):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ def __init__(self, *,

if isinstance(channel, grpc.Channel):
# Ignore credentials if a channel was passed.
credentials = False
credentials = None
self._ignore_credentials = True
# If a channel was explicitly provided, set it.
self._grpc_channel = channel
self._ssl_channel_credentials = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ def __init__(self, *,

if isinstance(channel, aio.Channel):
# Ignore credentials if a channel was passed.
credentials = False
credentials = None
self._ignore_credentials = True
# If a channel was explicitly provided, set it.
self._grpc_channel = channel
self._ssl_channel_credentials = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ def __init__(

# Save the scopes.
self._scopes = scopes
if not hasattr(self, "_ignore_credentials"):
self._ignore_credentials: bool = False

# If no credentials are provided, then determine the appropriate
# defaults.
Expand All @@ -98,7 +100,7 @@ def __init__(
**scopes_kwargs,
quota_project_id=quota_project_id
)
elif credentials is None:
elif credentials is None and not self._ignore_credentials:
credentials, _ = google.auth.default(**scopes_kwargs, quota_project_id=quota_project_id)
# Don't apply audience if the credentials file passed from user.
if hasattr(credentials, "with_gdch_audience"):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ def __init__(self, *,

if isinstance(channel, grpc.Channel):
# Ignore credentials if a channel was passed.
credentials = False
credentials = None
self._ignore_credentials = True
# If a channel was explicitly provided, set it.
self._grpc_channel = channel
self._ssl_channel_credentials = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ def __init__(self, *,

if isinstance(channel, aio.Channel):
# Ignore credentials if a channel was passed.
credentials = False
credentials = None
self._ignore_credentials = True
# If a channel was explicitly provided, set it.
self._grpc_channel = channel
self._ssl_channel_credentials = None
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/goldens/logging/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ def mypy(session):
'types-protobuf'
)
session.install('.')
# Remove once https://github.com/googleapis/python-api-core/pull/650 is merged
session.install("google-api-core>=2.19.1rc0")
session.run(
'mypy',
'-p',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ def __init__(

# Save the scopes.
self._scopes = scopes
if not hasattr(self, "_ignore_credentials"):
self._ignore_credentials: bool = False

# If no credentials are provided, then determine the appropriate
# defaults.
Expand All @@ -95,7 +97,7 @@ def __init__(
**scopes_kwargs,
quota_project_id=quota_project_id
)
elif credentials is None:
elif credentials is None and not self._ignore_credentials:
credentials, _ = google.auth.default(**scopes_kwargs, quota_project_id=quota_project_id)
# Don't apply audience if the credentials file passed from user.
if hasattr(credentials, "with_gdch_audience"):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ def __init__(self, *,

if isinstance(channel, grpc.Channel):
# Ignore credentials if a channel was passed.
credentials = False
credentials = None
self._ignore_credentials = True
# If a channel was explicitly provided, set it.
self._grpc_channel = channel
self._ssl_channel_credentials = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ def __init__(self, *,

if isinstance(channel, aio.Channel):
# Ignore credentials if a channel was passed.
credentials = False
credentials = None
self._ignore_credentials = True
# If a channel was explicitly provided, set it.
self._grpc_channel = channel
self._ssl_channel_credentials = None
Expand Down
Loading

0 comments on commit 205fe5e

Please sign in to comment.