Skip to content

Commit

Permalink
allow multiple elements in impersonation chain (#35694)
Browse files Browse the repository at this point in the history
  • Loading branch information
melugoyal authored and ephraimbuddy committed Nov 26, 2023
1 parent efc9459 commit 4375ac6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions airflow/providers/google/common/hooks/base_google.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ def get_credentials_and_project_id(self) -> tuple[google.auth.credentials.Creden

if not self.impersonation_chain:
self.impersonation_chain = self._get_field("impersonation_chain", None)
if isinstance(self.impersonation_chain, str) and "," in self.impersonation_chain:
self.impersonation_chain = [s.strip() for s in self.impersonation_chain.split(",")]

target_principal, delegates = _get_target_principal_and_delegates(self.impersonation_chain)

Expand Down
2 changes: 1 addition & 1 deletion docs/apache-airflow-providers-google/connections/gcp.rst
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ Impersonation Chain
of the last account in the list, which will be impersonated in all requests leveraging this connection.
If set as a string, the account must grant the originating account
the Service Account Token Creator IAM role.
If set as a sequence, the identities from the list must grant
If set as a comma-separated list, the identities from the list must grant
Service Account Token Creator IAM role to the directly preceding identity, with first
account from the list granting this role to the originating account.

Expand Down
14 changes: 14 additions & 0 deletions tests/providers/google/common/hooks/test_base_google.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,20 @@ def test_authorize_assert_http_timeout_is_present(self, mock_get_credentials):
["ACCOUNT_2", "ACCOUNT_3"],
id="multiple_elements_list_with_override",
),
pytest.param(
None,
"ACCOUNT_1,ACCOUNT_2,ACCOUNT_3",
"ACCOUNT_3",
["ACCOUNT_1", "ACCOUNT_2"],
id="multiple_elements_list_as_string",
),
pytest.param(
None,
"ACCOUNT_1, ACCOUNT_2, ACCOUNT_3",
"ACCOUNT_3",
["ACCOUNT_1", "ACCOUNT_2"],
id="multiple_elements_list_as_string_with_space",
),
],
)
@mock.patch(MODULE_NAME + ".get_credentials_and_project_id")
Expand Down

0 comments on commit 4375ac6

Please sign in to comment.