Skip to content

Commit

Permalink
fix: allow get_project_id to take a request (#1203)
Browse files Browse the repository at this point in the history
* fix: allow get_project_id to take a request

* Adding Args/Return

* Updating documentation

Co-authored-by: Jin <qinjin@google.com>
Co-authored-by: arithmetic1728 <58957152+arithmetic1728@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 9, 2023
1 parent 9e584e5 commit 9a4d23a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 8 additions & 1 deletion google/auth/external_account_authorized_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,19 @@ def can_refresh(self):
(self._refresh_token, self._token_url, self._client_id, self._client_secret)
)

def get_project_id(self):
def get_project_id(self, request=None):
"""Retrieves the project ID corresponding to the workload identity or workforce pool.
For workforce pool credentials, it returns the project ID corresponding to
the workforce_pool_user_project.
When not determinable, None is returned.
Args:
request (google.auth.transport.requests.Request): Request object.
Unused here, but passed from _default.default().
Return:
str: project ID is not determinable for this credential type so it returns None
"""

return None
Expand Down
5 changes: 4 additions & 1 deletion tests/test_external_account_authorized_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,10 @@ def test_to_json_full_with_strip(self):

def test_get_project_id(self):
creds = self.make_credentials()
assert creds.get_project_id() is None
request = mock.create_autospec(transport.Request)

assert creds.get_project_id(request) is None
request.assert_not_called()

def test_with_quota_project(self):
creds = self.make_credentials(
Expand Down

0 comments on commit 9a4d23a

Please sign in to comment.