From 704b3903a95a7a485a829dbba1d8b24b2388f36a Mon Sep 17 00:00:00 2001 From: Vedant Prajapati <40185967+vedantprajapati@users.noreply.github.com> Date: Fri, 4 Mar 2022 13:32:36 -0500 Subject: [PATCH 01/23] logging added --- sqlalchemy_bigquery/_helpers.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/sqlalchemy_bigquery/_helpers.py b/sqlalchemy_bigquery/_helpers.py index b03e232a..a79859ba 100644 --- a/sqlalchemy_bigquery/_helpers.py +++ b/sqlalchemy_bigquery/_helpers.py @@ -14,7 +14,7 @@ import sqlalchemy import base64 import json - +import logging USER_AGENT_TEMPLATE = "sqlalchemy/{}" SCOPES = ( @@ -28,6 +28,7 @@ def google_client_info(): user_agent = USER_AGENT_TEMPLATE.format(sqlalchemy.__version__) return client_info.ClientInfo(user_agent=user_agent) +logger = logging.getLogger() def create_bigquery_client( credentials_info=None, @@ -37,8 +38,11 @@ def create_bigquery_client( location=None, project_id=None, ): + logger.critical( + 'yooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo') + default_project = None - + if credentials_base64: credentials_info = json.loads(base64.b64decode(credentials_base64)) @@ -59,6 +63,17 @@ def create_bigquery_client( if project_id is None: project_id = default_project + + logger.critical("client_info") + logger.critical(google_client_info()) + logger.critical("projectid") + logger.critical(project_id) + logger.critical("credentials") + logger.critical(credentials) + logger.critical("location") + logger.critical(location) + logger.critical("queryjobconfig") + logger.critical(default_query_job_config) return bigquery.Client( client_info=google_client_info(), From 5d69444cfa11b6861f2de7ea90b3b1f0da3eef8a Mon Sep 17 00:00:00 2001 From: Jay Zuo Date: Tue, 8 Mar 2022 16:45:53 -0500 Subject: [PATCH 02/23] Log username and email params --- sqlalchemy_bigquery/parse_url.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/sqlalchemy_bigquery/parse_url.py b/sqlalchemy_bigquery/parse_url.py index b1d4b589..f43ab21d 100644 --- a/sqlalchemy_bigquery/parse_url.py +++ b/sqlalchemy_bigquery/parse_url.py @@ -18,6 +18,7 @@ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. import re +import logging from google.cloud.bigquery import QueryJobConfig from google.cloud.bigquery.dataset import DatasetReference @@ -31,7 +32,7 @@ GROUP_DELIMITER = re.compile(r"\s*\,\s*") KEY_VALUE_DELIMITER = re.compile(r"\s*\:\s*") - +logger = logging.getLogger() def parse_boolean(bool_string): bool_string = bool_string.lower() @@ -62,7 +63,14 @@ def parse_url(url): # noqa: C901 # maximum_billing_tier (deprecated) if "maximum_billing_tier" in query: raise ValueError("maximum_billing_tier is a deprecated argument") - + + + username = url.username or None + email = url.email or None + + logger.critical('parse_url.py username', username) + logger.critical('parse_url.py email', email) + project_id = url.host location = None dataset_id = url.database or None @@ -70,6 +78,7 @@ def parse_url(url): # noqa: C901 credentials_path = None credentials_base64 = None list_tables_page_size = None + # location if "location" in query: From c355b16107e665f3b650a8f43f3e58b45588b660 Mon Sep 17 00:00:00 2001 From: Jay Zuo Date: Tue, 8 Mar 2022 17:20:17 -0500 Subject: [PATCH 03/23] add attribute checks --- sqlalchemy_bigquery/parse_url.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/sqlalchemy_bigquery/parse_url.py b/sqlalchemy_bigquery/parse_url.py index f43ab21d..d4d47990 100644 --- a/sqlalchemy_bigquery/parse_url.py +++ b/sqlalchemy_bigquery/parse_url.py @@ -64,12 +64,13 @@ def parse_url(url): # noqa: C901 if "maximum_billing_tier" in query: raise ValueError("maximum_billing_tier is a deprecated argument") - - username = url.username or None - email = url.email or None - - logger.critical('parse_url.py username', username) - logger.critical('parse_url.py email', email) + if hasattr(url, 'username'): + username = url.username or None + logger.critical('parse_url.py username', username) + + if hasattr(url, 'email'): + email = url.email or None + logger.critical('parse_url.py email', email) project_id = url.host location = None From 148ded55e51d85ca1e84c62cb4cec468b11bd2e6 Mon Sep 17 00:00:00 2001 From: Jay Zuo Date: Tue, 8 Mar 2022 17:28:49 -0500 Subject: [PATCH 04/23] Use string templates --- sqlalchemy_bigquery/parse_url.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sqlalchemy_bigquery/parse_url.py b/sqlalchemy_bigquery/parse_url.py index d4d47990..c7bc8d8d 100644 --- a/sqlalchemy_bigquery/parse_url.py +++ b/sqlalchemy_bigquery/parse_url.py @@ -66,11 +66,11 @@ def parse_url(url): # noqa: C901 if hasattr(url, 'username'): username = url.username or None - logger.critical('parse_url.py username', username) + logger.critical(f'parse_url.py username: {username}') if hasattr(url, 'email'): email = url.email or None - logger.critical('parse_url.py email', email) + logger.critical(f'parse_url.py email: {email}') project_id = url.host location = None From 8e74ade0106d4c59fefb567f02b627aed6050e4d Mon Sep 17 00:00:00 2001 From: Vedant Prajapati Date: Wed, 9 Mar 2022 09:01:28 -0500 Subject: [PATCH 05/23] added email and username field to parseurl output --- sqlalchemy_bigquery/_helpers.py | 10 +++++++++- sqlalchemy_bigquery/base.py | 4 ++++ sqlalchemy_bigquery/parse_url.py | 3 +++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/sqlalchemy_bigquery/_helpers.py b/sqlalchemy_bigquery/_helpers.py index a79859ba..dbd8a2e3 100644 --- a/sqlalchemy_bigquery/_helpers.py +++ b/sqlalchemy_bigquery/_helpers.py @@ -37,6 +37,8 @@ def create_bigquery_client( default_query_job_config=None, location=None, project_id=None, + username=None, + email=None, ): logger.critical( 'yooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo') @@ -63,7 +65,13 @@ def create_bigquery_client( if project_id is None: project_id = default_project - + + logger.critical(email, username) + if email is not None and username is not None: + logger.critical("WE IN BOYS") + credentials = credentials.with_scopes(['email']) + credentials = credentials.with_subject("vedantprajapati@geotab.com") + logger.critical("client_info") logger.critical(google_client_info()) logger.critical("projectid") diff --git a/sqlalchemy_bigquery/base.py b/sqlalchemy_bigquery/base.py index ca1772a0..91e3a8fa 100644 --- a/sqlalchemy_bigquery/base.py +++ b/sqlalchemy_bigquery/base.py @@ -802,6 +802,8 @@ def create_connect_args(self, url): credentials_base64, default_query_job_config, list_tables_page_size, + username, + email, ) = parse_url(url) self.arraysize = arraysize or self.arraysize @@ -820,6 +822,8 @@ def create_connect_args(self, url): project_id=project_id, location=self.location, default_query_job_config=default_query_job_config, + username=username, + email=email ) return ([client], {}) diff --git a/sqlalchemy_bigquery/parse_url.py b/sqlalchemy_bigquery/parse_url.py index c7bc8d8d..9df1f9db 100644 --- a/sqlalchemy_bigquery/parse_url.py +++ b/sqlalchemy_bigquery/parse_url.py @@ -46,6 +46,7 @@ def parse_boolean(bool_string): def parse_url(url): # noqa: C901 query = dict(url.query) # need mutable query. + username, email = None # use_legacy_sql (legacy) if "use_legacy_sql" in query: @@ -285,4 +286,6 @@ def parse_url(url): # noqa: C901 credentials_base64, job_config, list_tables_page_size, + username, + email, ) From f731412eb9e05a9c00f5e782106426a7e98a1fb5 Mon Sep 17 00:00:00 2001 From: Vedant Prajapati Date: Wed, 9 Mar 2022 09:06:39 -0500 Subject: [PATCH 06/23] removed with_subject call --- sqlalchemy_bigquery/_helpers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sqlalchemy_bigquery/_helpers.py b/sqlalchemy_bigquery/_helpers.py index dbd8a2e3..4794a3ae 100644 --- a/sqlalchemy_bigquery/_helpers.py +++ b/sqlalchemy_bigquery/_helpers.py @@ -69,8 +69,8 @@ def create_bigquery_client( logger.critical(email, username) if email is not None and username is not None: logger.critical("WE IN BOYS") - credentials = credentials.with_scopes(['email']) - credentials = credentials.with_subject("vedantprajapati@geotab.com") + # credentials = credentials.with_scopes(['email']) + # credentials = credentials.with_subject("vedantprajapati@geotab.com") logger.critical("client_info") logger.critical(google_client_info()) From 6b6b008bc5f0695b0c98b8b6b74d3254007798eb Mon Sep 17 00:00:00 2001 From: Vedant Prajapati Date: Wed, 9 Mar 2022 09:13:34 -0500 Subject: [PATCH 07/23] removed with_subject call --- sqlalchemy_bigquery/_helpers.py | 10 +++++----- sqlalchemy_bigquery/base.py | 8 ++++---- sqlalchemy_bigquery/parse_url.py | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/sqlalchemy_bigquery/_helpers.py b/sqlalchemy_bigquery/_helpers.py index 4794a3ae..94c0b5b3 100644 --- a/sqlalchemy_bigquery/_helpers.py +++ b/sqlalchemy_bigquery/_helpers.py @@ -37,8 +37,8 @@ def create_bigquery_client( default_query_job_config=None, location=None, project_id=None, - username=None, - email=None, + # username=None, + # email=None, ): logger.critical( 'yooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo') @@ -66,9 +66,9 @@ def create_bigquery_client( if project_id is None: project_id = default_project - logger.critical(email, username) - if email is not None and username is not None: - logger.critical("WE IN BOYS") + # logger.critical(email, username) + # if email is not None and username is not None: + # logger.critical("WE IN BOYS") # credentials = credentials.with_scopes(['email']) # credentials = credentials.with_subject("vedantprajapati@geotab.com") diff --git a/sqlalchemy_bigquery/base.py b/sqlalchemy_bigquery/base.py index 91e3a8fa..ba9aadfe 100644 --- a/sqlalchemy_bigquery/base.py +++ b/sqlalchemy_bigquery/base.py @@ -802,8 +802,8 @@ def create_connect_args(self, url): credentials_base64, default_query_job_config, list_tables_page_size, - username, - email, + # username, + # email, ) = parse_url(url) self.arraysize = arraysize or self.arraysize @@ -822,8 +822,8 @@ def create_connect_args(self, url): project_id=project_id, location=self.location, default_query_job_config=default_query_job_config, - username=username, - email=email + # username=username, + # email=email ) return ([client], {}) diff --git a/sqlalchemy_bigquery/parse_url.py b/sqlalchemy_bigquery/parse_url.py index 9df1f9db..7f1c09c4 100644 --- a/sqlalchemy_bigquery/parse_url.py +++ b/sqlalchemy_bigquery/parse_url.py @@ -286,6 +286,6 @@ def parse_url(url): # noqa: C901 credentials_base64, job_config, list_tables_page_size, - username, - email, + # username, + # email, ) From 8f43759c973e4830f0e98f19122f65e07315cc6a Mon Sep 17 00:00:00 2001 From: Vedant Prajapati Date: Wed, 9 Mar 2022 09:22:42 -0500 Subject: [PATCH 08/23] synatax error --- sqlalchemy_bigquery/parse_url.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlalchemy_bigquery/parse_url.py b/sqlalchemy_bigquery/parse_url.py index 7f1c09c4..3f800de6 100644 --- a/sqlalchemy_bigquery/parse_url.py +++ b/sqlalchemy_bigquery/parse_url.py @@ -46,7 +46,7 @@ def parse_boolean(bool_string): def parse_url(url): # noqa: C901 query = dict(url.query) # need mutable query. - username, email = None + username, email = None, None # use_legacy_sql (legacy) if "use_legacy_sql" in query: From 0c4bc3795c10384b53294e592f04bed14d3427c5 Mon Sep 17 00:00:00 2001 From: Vedant Prajapati Date: Wed, 9 Mar 2022 09:28:28 -0500 Subject: [PATCH 09/23] added email arg --- sqlalchemy_bigquery/_helpers.py | 14 +++++++++----- sqlalchemy_bigquery/base.py | 8 ++++---- sqlalchemy_bigquery/parse_url.py | 8 ++++++-- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/sqlalchemy_bigquery/_helpers.py b/sqlalchemy_bigquery/_helpers.py index 94c0b5b3..b72cfe00 100644 --- a/sqlalchemy_bigquery/_helpers.py +++ b/sqlalchemy_bigquery/_helpers.py @@ -37,8 +37,8 @@ def create_bigquery_client( default_query_job_config=None, location=None, project_id=None, - # username=None, - # email=None, + username=None, + email=None, ): logger.critical( 'yooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo') @@ -66,11 +66,15 @@ def create_bigquery_client( if project_id is None: project_id = default_project - # logger.critical(email, username) - # if email is not None and username is not None: - # logger.critical("WE IN BOYS") + logger.critical(email, username) + if email is not None: + logger.critical("WE IN BOYS") # credentials = credentials.with_scopes(['email']) # credentials = credentials.with_subject("vedantprajapati@geotab.com") + + if username is not None: + logger.critical("another one") + logger.critical("client_info") logger.critical(google_client_info()) diff --git a/sqlalchemy_bigquery/base.py b/sqlalchemy_bigquery/base.py index ba9aadfe..91e3a8fa 100644 --- a/sqlalchemy_bigquery/base.py +++ b/sqlalchemy_bigquery/base.py @@ -802,8 +802,8 @@ def create_connect_args(self, url): credentials_base64, default_query_job_config, list_tables_page_size, - # username, - # email, + username, + email, ) = parse_url(url) self.arraysize = arraysize or self.arraysize @@ -822,8 +822,8 @@ def create_connect_args(self, url): project_id=project_id, location=self.location, default_query_job_config=default_query_job_config, - # username=username, - # email=email + username=username, + email=email ) return ([client], {}) diff --git a/sqlalchemy_bigquery/parse_url.py b/sqlalchemy_bigquery/parse_url.py index 3f800de6..c4ca133d 100644 --- a/sqlalchemy_bigquery/parse_url.py +++ b/sqlalchemy_bigquery/parse_url.py @@ -126,6 +126,8 @@ def parse_url(url): # noqa: C901 credentials_base64, QueryJobConfig(), list_tables_page_size, + username, + email, ) else: return ( @@ -137,6 +139,8 @@ def parse_url(url): # noqa: C901 credentials_base64, None, list_tables_page_size, + username, + email, ) job_config = QueryJobConfig() @@ -286,6 +290,6 @@ def parse_url(url): # noqa: C901 credentials_base64, job_config, list_tables_page_size, - # username, - # email, + username, + email, ) From 079b48108a2109d969cb1c710fb6b797ba0c3486 Mon Sep 17 00:00:00 2001 From: Vedant Prajapati Date: Wed, 9 Mar 2022 09:38:07 -0500 Subject: [PATCH 10/23] moved log statement --- sqlalchemy_bigquery/_helpers.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sqlalchemy_bigquery/_helpers.py b/sqlalchemy_bigquery/_helpers.py index b72cfe00..5b481db7 100644 --- a/sqlalchemy_bigquery/_helpers.py +++ b/sqlalchemy_bigquery/_helpers.py @@ -66,14 +66,15 @@ def create_bigquery_client( if project_id is None: project_id = default_project - logger.critical(email, username) if email is not None: logger.critical("WE IN BOYS") + logger.critical(email) # credentials = credentials.with_scopes(['email']) # credentials = credentials.with_subject("vedantprajapati@geotab.com") - + if username is not None: logger.critical("another one") + logger.critical(username) logger.critical("client_info") From 7162730282b0784504365a07da12363e84c2bcab Mon Sep 17 00:00:00 2001 From: Vedant Prajapati Date: Wed, 9 Mar 2022 15:26:25 -0500 Subject: [PATCH 11/23] added with scope --- sqlalchemy_bigquery/_helpers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sqlalchemy_bigquery/_helpers.py b/sqlalchemy_bigquery/_helpers.py index 5b481db7..54356557 100644 --- a/sqlalchemy_bigquery/_helpers.py +++ b/sqlalchemy_bigquery/_helpers.py @@ -69,8 +69,8 @@ def create_bigquery_client( if email is not None: logger.critical("WE IN BOYS") logger.critical(email) - # credentials = credentials.with_scopes(['email']) - # credentials = credentials.with_subject("vedantprajapati@geotab.com") + credentials = credentials.with_scopes(['email']) + credentials = credentials.with_subject("vedantprajapati@geotab.com") if username is not None: logger.critical("another one") From 3e545bc3411c373fce0451fb988b0bf286ac6215 Mon Sep 17 00:00:00 2001 From: Vedant Prajapati Date: Wed, 9 Mar 2022 16:08:15 -0500 Subject: [PATCH 12/23] removed withscopes --- sqlalchemy_bigquery/_helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlalchemy_bigquery/_helpers.py b/sqlalchemy_bigquery/_helpers.py index 54356557..3187b9e7 100644 --- a/sqlalchemy_bigquery/_helpers.py +++ b/sqlalchemy_bigquery/_helpers.py @@ -69,7 +69,7 @@ def create_bigquery_client( if email is not None: logger.critical("WE IN BOYS") logger.critical(email) - credentials = credentials.with_scopes(['email']) + # credentials = credentials.with_scopes(['email']) credentials = credentials.with_subject("vedantprajapati@geotab.com") if username is not None: From 5f4928a67cf4427da72761f4da0c8a4c822a35a1 Mon Sep 17 00:00:00 2001 From: Vedant Prajapati Date: Thu, 10 Mar 2022 09:39:32 -0500 Subject: [PATCH 13/23] scopes has email --- sqlalchemy_bigquery/_helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlalchemy_bigquery/_helpers.py b/sqlalchemy_bigquery/_helpers.py index 3187b9e7..3d64d7bc 100644 --- a/sqlalchemy_bigquery/_helpers.py +++ b/sqlalchemy_bigquery/_helpers.py @@ -69,7 +69,7 @@ def create_bigquery_client( if email is not None: logger.critical("WE IN BOYS") logger.critical(email) - # credentials = credentials.with_scopes(['email']) + credentials = credentials.with_scopes(SCOPES + ("email")) credentials = credentials.with_subject("vedantprajapati@geotab.com") if username is not None: From 6d82f2f6fdcb3226fd8aa725ad7f6956c5053f3d Mon Sep 17 00:00:00 2001 From: Vedant Prajapati Date: Thu, 10 Mar 2022 15:47:28 -0500 Subject: [PATCH 14/23] removed email from scope --- sqlalchemy_bigquery/_helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlalchemy_bigquery/_helpers.py b/sqlalchemy_bigquery/_helpers.py index 3d64d7bc..d4e8902f 100644 --- a/sqlalchemy_bigquery/_helpers.py +++ b/sqlalchemy_bigquery/_helpers.py @@ -69,7 +69,7 @@ def create_bigquery_client( if email is not None: logger.critical("WE IN BOYS") logger.critical(email) - credentials = credentials.with_scopes(SCOPES + ("email")) + # credentials = credentials.with_scopes(SCOPES + ("email")) credentials = credentials.with_subject("vedantprajapati@geotab.com") if username is not None: From 157a1fd737d8096ad351cbfe38a41fb2c8cc8836 Mon Sep 17 00:00:00 2001 From: Vedant Prajapati Date: Thu, 10 Mar 2022 15:51:59 -0500 Subject: [PATCH 15/23] test add db with email --- sqlalchemy_bigquery/_helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlalchemy_bigquery/_helpers.py b/sqlalchemy_bigquery/_helpers.py index d4e8902f..06a7e6cd 100644 --- a/sqlalchemy_bigquery/_helpers.py +++ b/sqlalchemy_bigquery/_helpers.py @@ -38,7 +38,7 @@ def create_bigquery_client( location=None, project_id=None, username=None, - email=None, + email="vedantprajapati@geotab.com", ): logger.critical( 'yooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo') From 5ff0fd4aeebf1148fce03e51d1544badeef32fa8 Mon Sep 17 00:00:00 2001 From: Vedant Prajapati Date: Thu, 10 Mar 2022 15:58:01 -0500 Subject: [PATCH 16/23] with_subject doesnt change credentials --- sqlalchemy_bigquery/_helpers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sqlalchemy_bigquery/_helpers.py b/sqlalchemy_bigquery/_helpers.py index 06a7e6cd..a51c9e29 100644 --- a/sqlalchemy_bigquery/_helpers.py +++ b/sqlalchemy_bigquery/_helpers.py @@ -38,7 +38,7 @@ def create_bigquery_client( location=None, project_id=None, username=None, - email="vedantprajapati@geotab.com", + email=None, ): logger.critical( 'yooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo') @@ -70,7 +70,7 @@ def create_bigquery_client( logger.critical("WE IN BOYS") logger.critical(email) # credentials = credentials.with_scopes(SCOPES + ("email")) - credentials = credentials.with_subject("vedantprajapati@geotab.com") + delegated_credentials = credentials.with_subject("vedantprajapati@geotab.com") if username is not None: logger.critical("another one") From 060358f9bd1c2b5c88346102d2b6a042dbf70ee3 Mon Sep 17 00:00:00 2001 From: Vedant Prajapati Date: Thu, 10 Mar 2022 16:05:33 -0500 Subject: [PATCH 17/23] with_subject doesnt change credentials --- sqlalchemy_bigquery/_helpers.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sqlalchemy_bigquery/_helpers.py b/sqlalchemy_bigquery/_helpers.py index a51c9e29..6923fd3e 100644 --- a/sqlalchemy_bigquery/_helpers.py +++ b/sqlalchemy_bigquery/_helpers.py @@ -21,6 +21,7 @@ "https://www.googleapis.com/auth/bigquery", "https://www.googleapis.com/auth/cloud-platform", "https://www.googleapis.com/auth/drive", + "email", ) From be0a02c79d837778fd37c398b305924e5f2a5854 Mon Sep 17 00:00:00 2001 From: Vedant Prajapati Date: Thu, 10 Mar 2022 16:09:43 -0500 Subject: [PATCH 18/23] with_subject doesnt change credentials --- sqlalchemy_bigquery/_helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlalchemy_bigquery/_helpers.py b/sqlalchemy_bigquery/_helpers.py index 6923fd3e..6817f601 100644 --- a/sqlalchemy_bigquery/_helpers.py +++ b/sqlalchemy_bigquery/_helpers.py @@ -71,7 +71,7 @@ def create_bigquery_client( logger.critical("WE IN BOYS") logger.critical(email) # credentials = credentials.with_scopes(SCOPES + ("email")) - delegated_credentials = credentials.with_subject("vedantprajapati@geotab.com") + credentials = credentials.with_subject("vedantprajapati@geotab.com") if username is not None: logger.critical("another one") From 14fa48308561baad0b2cb6d2a8aee64340280f98 Mon Sep 17 00:00:00 2001 From: Vedant Prajapati Date: Mon, 14 Mar 2022 14:23:47 -0400 Subject: [PATCH 19/23] cleaner code for debugging --- sqlalchemy_bigquery/_helpers.py | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/sqlalchemy_bigquery/_helpers.py b/sqlalchemy_bigquery/_helpers.py index 6817f601..53f1a0ea 100644 --- a/sqlalchemy_bigquery/_helpers.py +++ b/sqlalchemy_bigquery/_helpers.py @@ -31,6 +31,8 @@ def google_client_info(): logger = logging.getLogger() +# Create a new google client on query run, database added, dataset added +# username and email fields are added for impersonation from parse_url (attributes are part of URL object) def create_bigquery_client( credentials_info=None, credentials_path=None, @@ -41,8 +43,6 @@ def create_bigquery_client( username=None, email=None, ): - logger.critical( - 'yooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo') default_project = None @@ -68,26 +68,19 @@ def create_bigquery_client( project_id = default_project if email is not None: - logger.critical("WE IN BOYS") - logger.critical(email) + logger.debug("email: {}".format(email)) # credentials = credentials.with_scopes(SCOPES + ("email")) credentials = credentials.with_subject("vedantprajapati@geotab.com") if username is not None: - logger.critical("another one") - logger.critical(username) - - - logger.critical("client_info") - logger.critical(google_client_info()) - logger.critical("projectid") - logger.critical(project_id) - logger.critical("credentials") - logger.critical(credentials) - logger.critical("location") - logger.critical(location) - logger.critical("queryjobconfig") - logger.critical(default_query_job_config) + logger.debug("username: {}".format(username)) + + + logger.debug("client_info: {}".format(google_client_info())) + logger.debug("projectid: {}".format(project_id)) + logger.debug("credentials info: {}".format(credentials)) + logger.debug("location {}".format(location)) + logger.debug("queryjobconfig {}".format(default_query_job_config)) return bigquery.Client( client_info=google_client_info(), From 13c5832044b5718e2778e3aa74f2d4b6445f3004 Mon Sep 17 00:00:00 2001 From: Vedant Prajapati <40185967+vedantprajapati@users.noreply.github.com> Date: Thu, 17 Mar 2022 09:57:09 -0400 Subject: [PATCH 20/23] Update _helpers.py --- sqlalchemy_bigquery/_helpers.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sqlalchemy_bigquery/_helpers.py b/sqlalchemy_bigquery/_helpers.py index 53f1a0ea..6e73e238 100644 --- a/sqlalchemy_bigquery/_helpers.py +++ b/sqlalchemy_bigquery/_helpers.py @@ -29,6 +29,13 @@ def google_client_info(): user_agent = USER_AGENT_TEMPLATE.format(sqlalchemy.__version__) return client_info.ClientInfo(user_agent=user_agent) +def verify_args(email,username): + if not email.endswith("geotab.com"): + return False + if not bool(re.match("^[A-Za-z0-9_-]*$", username)): + return False + return True + logger = logging.getLogger() # Create a new google client on query run, database added, dataset added @@ -67,6 +74,9 @@ def create_bigquery_client( if project_id is None: project_id = default_project + if email is not None and username is not None and not verify_args(email, username): + logger.critical("INVALID USERNAME OR EMAIL: {} {}".format(username, email) + if email is not None: logger.debug("email: {}".format(email)) # credentials = credentials.with_scopes(SCOPES + ("email")) From 3cb793e3b6453d65de5b452ac3c6612e2c494452 Mon Sep 17 00:00:00 2001 From: Vedant Prajapati Date: Thu, 17 Mar 2022 14:15:55 -0400 Subject: [PATCH 21/23] fixed syntax error --- sqlalchemy_bigquery/_helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlalchemy_bigquery/_helpers.py b/sqlalchemy_bigquery/_helpers.py index 6e73e238..01efba38 100644 --- a/sqlalchemy_bigquery/_helpers.py +++ b/sqlalchemy_bigquery/_helpers.py @@ -75,7 +75,7 @@ def create_bigquery_client( project_id = default_project if email is not None and username is not None and not verify_args(email, username): - logger.critical("INVALID USERNAME OR EMAIL: {} {}".format(username, email) + logger.critical("INVALID USERNAME OR EMAIL: {} {}".format(username, email)) if email is not None: logger.debug("email: {}".format(email)) From 5d1e9f8451237a1dc4ea454775a15752508f4aab Mon Sep 17 00:00:00 2001 From: Jay Zuo Date: Thu, 17 Mar 2022 14:37:27 -0400 Subject: [PATCH 22/23] Removed drive scope --- sqlalchemy_bigquery/_helpers.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/sqlalchemy_bigquery/_helpers.py b/sqlalchemy_bigquery/_helpers.py index 01efba38..efa9972e 100644 --- a/sqlalchemy_bigquery/_helpers.py +++ b/sqlalchemy_bigquery/_helpers.py @@ -19,9 +19,7 @@ USER_AGENT_TEMPLATE = "sqlalchemy/{}" SCOPES = ( "https://www.googleapis.com/auth/bigquery", - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/drive", - "email", + "https://www.googleapis.com/auth/cloud-platform" ) @@ -32,9 +30,7 @@ def google_client_info(): def verify_args(email,username): if not email.endswith("geotab.com"): return False - if not bool(re.match("^[A-Za-z0-9_-]*$", username)): - return False - return True + return bool(re.match("^[A-Za-z0-9_-]*$", username)) logger = logging.getLogger() @@ -79,8 +75,7 @@ def create_bigquery_client( if email is not None: logger.debug("email: {}".format(email)) - # credentials = credentials.with_scopes(SCOPES + ("email")) - credentials = credentials.with_subject("vedantprajapati@geotab.com") + credentials = credentials.with_subject(email) if username is not None: logger.debug("username: {}".format(username)) From 29467ac7e46d9eeab64b897574eae48783dde6ef Mon Sep 17 00:00:00 2001 From: Jay Zuo Date: Fri, 18 Mar 2022 13:52:41 -0400 Subject: [PATCH 23/23] Remove logging --- sqlalchemy_bigquery/_helpers.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/sqlalchemy_bigquery/_helpers.py b/sqlalchemy_bigquery/_helpers.py index efa9972e..73d0801a 100644 --- a/sqlalchemy_bigquery/_helpers.py +++ b/sqlalchemy_bigquery/_helpers.py @@ -70,22 +70,22 @@ def create_bigquery_client( if project_id is None: project_id = default_project - if email is not None and username is not None and not verify_args(email, username): - logger.critical("INVALID USERNAME OR EMAIL: {} {}".format(username, email)) +# if email is not None and username is not None and not verify_args(email, username): +# logger.critical("INVALID USERNAME OR EMAIL: {} {}".format(username, email)) if email is not None: - logger.debug("email: {}".format(email)) + logger.debug("Impersonated email: {}".format(email)) credentials = credentials.with_subject(email) - if username is not None: - logger.debug("username: {}".format(username)) +# if username is not None: +# logger.debug("username: {}".format(username)) - logger.debug("client_info: {}".format(google_client_info())) - logger.debug("projectid: {}".format(project_id)) - logger.debug("credentials info: {}".format(credentials)) - logger.debug("location {}".format(location)) - logger.debug("queryjobconfig {}".format(default_query_job_config)) +# logger.debug("client_info: {}".format(google_client_info())) +# logger.debug("projectid: {}".format(project_id)) +# logger.debug("credentials info: {}".format(credentials)) +# logger.debug("location {}".format(location)) +# logger.debug("queryjobconfig {}".format(default_query_job_config)) return bigquery.Client( client_info=google_client_info(),