[AIRFLOW-5303] Use project_id from GCP credentials#5907
[AIRFLOW-5303] Use project_id from GCP credentials#5907mik-laj merged 3 commits intoapache:masterfrom
Conversation
2466d16 to
abddb0b
Compare
There was a problem hiding this comment.
I wonder if this piece of code should not be transferred to the _get_credentials_and_project_id method. Then this method will never return an invalid value and it will be easier to use it.
kaxil
left a comment
There was a problem hiding this comment.
LGTM but would be good if we can add the test case mentioned in last comment
There was a problem hiding this comment.
Can we add a test case for this?
(1) Mock project_id as None from credential object & being overriden by project_id from connection?
There was a problem hiding this comment.
I added a 8 tests. I am testing a lot of different cases now.
|
|
||
| @mock.patch( # type: ignore | ||
| MODULE_NAME + '.google.oauth2.service_account.Credentials.from_service_account_file', | ||
| **{'reutnr_value.project_id': "PROJECT_ID"} |
There was a problem hiding this comment.
| **{'reutnr_value.project_id': "PROJECT_ID"} | |
| **{'return_value.project_id': "PROJECT_ID"} |
There was a problem hiding this comment.
Fixed. I also added missing assertion.
| } | ||
| result = self.instance._get_credentials_and_project_id() | ||
| mock_from_service_account_file.assert_called_once_with(service_account, scopes=self.instance.scopes) | ||
| self.assertEqual((mock_from_service_account_file.return_value, 'PROJECT_ID'), result) |
There was a problem hiding this comment.
(mock_from_service_account_file.return_value, 'PROJECT_ID') -> The first item is credential block?

Currently project_id is read correctly only if project_id is configured in extra.
However, the default project_id can also be configured in other place.:
It makes much easier to configure the connection during development
Currently, I need to setup connection using following command:
but I would like to be able to configure the connection using the following command:
or when I use a service account:
CC: @ryanyuan
Make sure you have checked all steps below.
Jira
Description
Tests
Commits
Documentation
Code Quality
flake8