-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Gbq service account #11881
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
Gbq service account #11881
Conversation
from oauth2client.client import OAuth2WebServerFlow | ||
from oauth2client.file import Storage | ||
from oauth2client.tools import run_flow, argparser | ||
|
||
_check_google_client_version() | ||
|
||
flow = OAuth2WebServerFlow(client_id='495642085510-k0tmvj2m941jhre2nbqka17vqpjfddtd.apps.googleusercontent.com', | ||
client_secret='kOc9wMptUtxkcIFbtZCcrEAc', | ||
scope='https://www.googleapis.com/auth/bigquery', |
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.
TODO: use self.scope here
the |
OK, I've added |
6b67450
to
8fa76e7
Compare
@@ -37,6 +39,10 @@ def _check_google_client_version(): | |||
logger = logging.getLogger('pandas.io.gbq') | |||
logger.setLevel(logging.ERROR) | |||
|
|||
def _print(msg, end='\n'): | |||
sys.stdout.write(msg + end) |
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.
you should pass verbose
to this (and do the if inside here). That way you can simply:
_print(msg, verbose=verbose)
in the code itself.
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.
thanks, good point
pls add a whatsnew entry (enhancements). |
cc @parthea pls have a look |
8914df3
to
cd45e22
Compare
pls rebase / squash |
cd45e22
to
2d12d6d
Compare
ok, rabased and squashed |
cc @parthea any comments |
2d12d6d
to
4ba4401
Compare
I'm receiving the following exception related to the
I believe Travis will also have this issue. Travis is currently skipping integration tests that require a BigQuery project id, so the issue is not reported by Travis. Should we add a dependency for
|
we don't need any more deps use time.time() |
4ba4401
to
0d036cc
Compare
Ad FileNotFoundError) I'm running tests on python 3 only, where this exception is built-in, hence I've missed this out. After adding support for json contents handling this exception is not needed any more. See line 168 in gbq.py, where I'm checking file exists and is regular file. So file not found exception can not happend. I'm removing it from except clause. Doing this I've also rethinked, rewritten and tested invalid auth scenarios. Ad json.load) it works for me. I cant reproduce it under python3 :( |
|
Sample session
|
|
||
def __init__(self, project_id, reauth=False): | ||
def __init__(self, project_id, reauth=False, verbose=True, private_key=None): |
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.
let's default to verbose=False
. you could have an option do this I suppose, e.g. pd.options.gbq.verbose
pls |
needs a rebase; most of the codebase underwent a PEP cleanup very recently. |
|
||
You will be authenticated to the specified BigQuery account via Google's Oauth2 mechanism. | ||
|
||
Primary auth method is as simple as following the |
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.
The primary authentication
|
) | ||
except (KeyError, ValueError, TypeError, AttributeError): | ||
raise InvalidPrivateKeyFormat("Service account private key should be valid JSON (file path or string contents) " | ||
"with at least two keys: 'client_email' and 'private_key'. Can be obtained from google developers console. ") |
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 make a small change in the error message to indicate that file may be missing?
raise InvalidPrivateKeyFormat("Private key is missing or invalid. Service account private key should be valid JSON (file path or string contents) with at least two keys: 'client_email' and 'private_key'. Can be obtained from google developers console. ")
fefd245
to
2e5b404
Compare
1917703
to
e035747
Compare
|
||
.. note:: | ||
|
||
The `'private_key'` parameter can be set to either the file path of the service account key in JSON format, or |
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.
need indenting to the note
(same below)
@tworec just a couple of more stylistic changes to conform to the rest of the code base. almost there! |
gr8! all style fixes done. i'm running local tests and pushing it. please review. |
All 73 tests have passed both on py3.5 and py2.7 |
thanks! pls review the built docs and if necessary issue a followup for fixes http://pandas-docs.github.io/pandas-docs-travis/ (prob will take a few hours, lots of things in the queue :) |
It was my first PR. Thanks for feedback. |
This adds service account authentication while still supports standard web auth method.
It also adds some useful std out messages: progress with elapsed time and percentage
+ price calculation.In RTBHouse we're using this service account auth since may. It works perfectly with remote jupyter server (iPython notebooks).
fixes #8489