-
Notifications
You must be signed in to change notification settings - Fork 16.3k
[AIRFLOW-5303] Use project_id from GCP credentials #5907
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
2466d16 to
abddb0b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
kaxil
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but would be good if we can add the test case mentioned in last comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a 8 tests. I am testing a lot of different cases now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
|
|
||
| @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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| **{'reutnr_value.project_id': "PROJECT_ID"} | |
| **{'return_value.project_id': "PROJECT_ID"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. I also added missing assertion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
| } | ||
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(mock_from_service_account_file.return_value, 'PROJECT_ID') -> The first item is credential block?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.

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