Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AmendsenProject
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shaik Janipasha
AmendsenProject
Commits
dd675699
Unverified
Commit
dd675699
authored
Oct 23, 2019
by
Tao Feng
Committed by
GitHub
Oct 23, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow credential pass from conf variable for BQ extractor (#154)
parent
020bb6f3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
1 deletion
+12
-1
bigquery_metadata_extractor.py
databuilder/extractor/bigquery_metadata_extractor.py
+12
-1
No files found.
databuilder/extractor/bigquery_metadata_extractor.py
View file @
dd675699
import
json
import
logging
import
logging
from
collections
import
namedtuple
from
collections
import
namedtuple
...
@@ -32,6 +33,8 @@ class BigQueryMetadataExtractor(Extractor):
...
@@ -32,6 +33,8 @@ class BigQueryMetadataExtractor(Extractor):
PROJECT_ID_KEY
=
'project_id'
PROJECT_ID_KEY
=
'project_id'
KEY_PATH_KEY
=
'key_path'
KEY_PATH_KEY
=
'key_path'
# sometimes we don't have a key path, but only have an variable
CRED_KEY
=
'project_cred'
PAGE_SIZE_KEY
=
'page_size'
PAGE_SIZE_KEY
=
'page_size'
FILTER_KEY
=
'filter'
FILTER_KEY
=
'filter'
_DEFAULT_SCOPES
=
[
'https://www.googleapis.com/auth/bigquery.readonly'
,
]
_DEFAULT_SCOPES
=
[
'https://www.googleapis.com/auth/bigquery.readonly'
,
]
...
@@ -41,7 +44,9 @@ class BigQueryMetadataExtractor(Extractor):
...
@@ -41,7 +44,9 @@ class BigQueryMetadataExtractor(Extractor):
def
init
(
self
,
conf
):
def
init
(
self
,
conf
):
# type: (ConfigTree) -> None
# type: (ConfigTree) -> None
# should use key_path, or cred_key if the former doesn't exist
self
.
key_path
=
conf
.
get_string
(
BigQueryMetadataExtractor
.
KEY_PATH_KEY
,
None
)
self
.
key_path
=
conf
.
get_string
(
BigQueryMetadataExtractor
.
KEY_PATH_KEY
,
None
)
self
.
cred_key
=
conf
.
get_string
(
BigQueryMetadataExtractor
.
CRED_KEY
,
None
)
self
.
project_id
=
conf
.
get_string
(
BigQueryMetadataExtractor
.
PROJECT_ID_KEY
)
self
.
project_id
=
conf
.
get_string
(
BigQueryMetadataExtractor
.
PROJECT_ID_KEY
)
self
.
pagesize
=
conf
.
get_int
(
self
.
pagesize
=
conf
.
get_int
(
BigQueryMetadataExtractor
.
PAGE_SIZE_KEY
,
BigQueryMetadataExtractor
.
PAGE_SIZE_KEY
,
...
@@ -53,7 +58,13 @@ class BigQueryMetadataExtractor(Extractor):
...
@@ -53,7 +58,13 @@ class BigQueryMetadataExtractor(Extractor):
google
.
oauth2
.
service_account
.
Credentials
.
from_service_account_file
(
google
.
oauth2
.
service_account
.
Credentials
.
from_service_account_file
(
self
.
key_path
,
scopes
=
BigQueryMetadataExtractor
.
_DEFAULT_SCOPES
))
self
.
key_path
,
scopes
=
BigQueryMetadataExtractor
.
_DEFAULT_SCOPES
))
else
:
else
:
credentials
,
_
=
google
.
auth
.
default
(
scopes
=
BigQueryMetadataExtractor
.
_DEFAULT_SCOPES
)
if
self
.
cred_key
:
service_account_info
=
json
.
loads
(
self
.
cred_key
)
credentials
=
(
google
.
oauth2
.
service_account
.
Credentials
.
from_service_account_info
(
service_account_info
,
scopes
=
BigQueryMetadataExtractor
.
_DEFAULT_SCOPES
))
else
:
credentials
,
_
=
google
.
auth
.
default
(
scopes
=
BigQueryMetadataExtractor
.
_DEFAULT_SCOPES
)
http
=
httplib2
.
Http
()
http
=
httplib2
.
Http
()
authed_http
=
google_auth_httplib2
.
AuthorizedHttp
(
credentials
,
http
=
http
)
authed_http
=
google_auth_httplib2
.
AuthorizedHttp
(
credentials
,
http
=
http
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment