Skip to content

Commit 62c0fc8

Browse files
fix: Read scopes from ADC json for impersoanted cred (#1820)
* fix: Read scopes from ADC json for impersoanted cred * secret * secret update * secret update * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 36ecb1d commit 62c0fc8

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

google/auth/impersonated_credentials.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@ def from_impersonated_service_account_info(cls, info, scopes=None):
526526
target_principal = impersonation_url[start_index + 1 : end_index]
527527
delegates = info.get("delegates")
528528
quota_project_id = info.get("quota_project_id")
529+
scopes = scopes or info.get("scopes")
529530
trust_boundary = info.get("trust_boundary")
530531

531532
return cls(

system_tests/secrets.tar.enc

0 Bytes
Binary file not shown.

tests/test_impersonated_credentials.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,23 @@ def test_from_impersonated_service_account_info_with_invalid_impersonation_url(
213213
)
214214
assert excinfo.match(r"Cannot extract target principal from")
215215

216+
def test_from_impersonated_service_account_info_with_scopes(self):
217+
info = copy.deepcopy(IMPERSONATED_SERVICE_ACCOUNT_AUTHORIZED_USER_SOURCE_INFO)
218+
info["scopes"] = ["scope1", "scope2"]
219+
credentials = impersonated_credentials.Credentials.from_impersonated_service_account_info(
220+
info
221+
)
222+
assert credentials._target_scopes == ["scope1", "scope2"]
223+
224+
def test_from_impersonated_service_account_info_with_scopes_param(self):
225+
info = copy.deepcopy(IMPERSONATED_SERVICE_ACCOUNT_AUTHORIZED_USER_SOURCE_INFO)
226+
info["scopes"] = ["scope_from_info_1", "scope_from_info_2"]
227+
scopes_param = ["scope_from_param_1", "scope_from_param_2"]
228+
credentials = impersonated_credentials.Credentials.from_impersonated_service_account_info(
229+
info, scopes=scopes_param
230+
)
231+
assert credentials._target_scopes == scopes_param
232+
216233
def test_get_cred_info(self):
217234
credentials = self.make_credentials()
218235
assert not credentials.get_cred_info()

0 commit comments

Comments
 (0)