-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Support BigQuery OAuth using a refresh token and client secrets #2805
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1cf87c6
(#2344) Support BigQuery OAuth using a refesh token and client secrets
drewbanin e4644bf
support providing a token directly; update method name
drewbanin ee6571d
Merge branch 'dev/kiyoshi-kuromiya' into feature/bigquery-oauth-token
drewbanin 056d8fa
Merge branch 'dev/kiyoshi-kuromiya' into feature/bigquery-oauth-token
drewbanin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,6 +71,31 @@ def setUp(self): | |
'threads': 1, | ||
'impersonate_service_account': '[email protected]' | ||
}, | ||
'oauth-credentials-token': { | ||
'type': 'bigquery', | ||
'method': 'oauth-secrets', | ||
'token': 'abc', | ||
'project': 'dbt-unit-000000', | ||
'schema': 'dummy_schema', | ||
'threads': 1, | ||
'location': 'Luna Station', | ||
'priority': 'batch', | ||
'maximum_bytes_billed': 0, | ||
}, | ||
'oauth-credentials': { | ||
'type': 'bigquery', | ||
'method': 'oauth-secrets', | ||
'client_id': 'abc', | ||
'client_secret': 'def', | ||
'refresh_token': 'ghi', | ||
'token_uri': 'jkl', | ||
'project': 'dbt-unit-000000', | ||
'schema': 'dummy_schema', | ||
'threads': 1, | ||
'location': 'Luna Station', | ||
'priority': 'batch', | ||
'maximum_bytes_billed': 0, | ||
}, | ||
}, | ||
'target': 'oauth', | ||
} | ||
|
@@ -145,6 +170,40 @@ def test_acquire_connection_service_account_validations(self, mock_open_connecti | |
connection.handle | ||
mock_open_connection.assert_called_once() | ||
|
||
@patch('dbt.adapters.bigquery.BigQueryConnectionManager.open', return_value=_bq_conn()) | ||
def test_acquire_connection_oauth_token_validations(self, mock_open_connection): | ||
adapter = self.get_adapter('oauth-credentials-token') | ||
try: | ||
connection = adapter.acquire_connection('dummy') | ||
self.assertEqual(connection.type, 'bigquery') | ||
|
||
except dbt.exceptions.ValidationException as e: | ||
self.fail('got ValidationException: {}'.format(str(e))) | ||
|
||
except BaseException as e: | ||
raise | ||
|
||
mock_open_connection.assert_not_called() | ||
connection.handle | ||
mock_open_connection.assert_called_once() | ||
|
||
@patch('dbt.adapters.bigquery.BigQueryConnectionManager.open', return_value=_bq_conn()) | ||
def test_acquire_connection_oauth_credentials_validations(self, mock_open_connection): | ||
adapter = self.get_adapter('oauth-credentials') | ||
try: | ||
connection = adapter.acquire_connection('dummy') | ||
self.assertEqual(connection.type, 'bigquery') | ||
|
||
except dbt.exceptions.ValidationException as e: | ||
self.fail('got ValidationException: {}'.format(str(e))) | ||
|
||
except BaseException as e: | ||
raise | ||
|
||
mock_open_connection.assert_not_called() | ||
connection.handle | ||
mock_open_connection.assert_called_once() | ||
|
||
@patch('dbt.adapters.bigquery.BigQueryConnectionManager.open', return_value=_bq_conn()) | ||
def test_acquire_connection_impersonated_service_account_validations(self, mock_open_connection): | ||
adapter = self.get_adapter('impersonate') | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Were you going to rename this to
refresh-token
?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 decided not to! I actually updated this PR to also accept an access token directly via the
token
configuration. So, it's kind of just a grab bag of oauth auth methods. Google lets you supply:The access token is going to expire after ~60 mins (not well defined), but it was a one-line change and feels like a reasonable enough use case to support. You buy 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.
gotcha — does that mean that this resolves #2802 as well?