-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Get project ID from JSON credentials file #1813
Get project ID from JSON credentials file #1813
Conversation
Do we have tests that make sure the In other words, we need to follow the same policy of grabbing project IDs, trying the following in order to grab project ID from...
(I think that's the right order at least...) |
import os | ||
import tempfile | ||
with tempfile.NamedTemporaryFile() as credential_file: | ||
credential_file.write('{"project_id": "test-project-id"}') |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
To get this to work with the happy path that @jgeewax mentioned( |
I'm not sure. @jgeewax do we have a As for putting it with |
I can do the Ok cool, thanks @dhermes! I'll make a configuration doc. |
170dc66
to
5125599
Compare
:rtype: str or ``NoneType`` | ||
:returns: Project-ID from ``gcloud info`` else ``None`` | ||
""" | ||
command = subprocess.Popen(['gcloud info'], |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@dhermes @tseaver @jonparrott |
Not sure either.
$ cat keyfile.json
{
"type": "service_account",
"project_id": "PROJECT",
"private_key_id": "...",
"private_key": "-----BEGIN PRIVATE KEY-----...-----END PRIVATE KEY-----\n",
"client_email": "[email protected]",
"client_id": "...",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://accounts.google.com/o/oauth2/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/foo%40PROJECT.iam.gserviceaccount.com"
} |
@dhermes, so the only issue with grabbing it from Also, is that default file location the same for windows and linux both? I saw
So I wasn't sure what the story was there. But I think using _get_well_known_file might be the best option if it works after |
@daspecster There should be a cascade of checks here just like there is for credentials. (i.e. so the absence of |
43157db
to
4c686be
Compare
Also using |
Also, if I look back at #1792, the flow that happened there, I can add that to the list of places to check but I think we're back to pulling it from the |
The current project-check cascade is:
I'm suggesting you inject two more checks in there (not sure about the order yet):
For reference the cascade for credentials is:
|
Ok I will do that! Thanks again @dhermes! |
>>> from gcloud import bigquery | ||
>>> client = bigquery.Client() | ||
|
||
- :class:`Client <gcloud.client.Client>` objects hold both a ``project`` |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
be7e034
to
8c3b234
Compare
8c3b234
to
d7b1951
Compare
Sorry, I was AFK waiting on a contractor. Looking this evening. |
@@ -48,6 +51,7 @@ | |||
(?P<nanos>\d{1,9}) # nanoseconds, maybe truncated | |||
Z # Zulu | |||
""", re.VERBOSE) | |||
DEFAULT_CONFIGURATION_PATH = '~/.config/gcloud/configurations/config_default' |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
LGTM whichever way you answer my question about passing the Windows config path in addition to the Unix-y one. |
@tseaver I added it! win32_config_path = os.path.join(os.getenv('APPDATA', ''),
'gcloud\configurations\config_default') I don't have a windows machine to test on though. Is there a way that we test gcloud-python on windows in general? |
@daspecster pylint doesn't like your backsplashes. I believe you could use forward-slashes there.
We could look (again) into adding Appveyor CI. |
63444c2
to
3f408c1
Compare
@tseaver I think I got it this time! I just let python pick the slashes. win32_config_path = os.path.join(os.getenv('APPDATA', ''),
'gcloud', 'configurations',
'config_default') |
@tseaver if this looks good to you, I'll merge. |
LGTM |
@tseaver RE: AppVeyor, we've had a build running for 4+ months. I can add you guys as admins if needed. |
This is a possible resolution to #1792, making it easier to follow along with the documentation.
I looked for a way to clarify the documentation for this but it looks like this should make it work in the way that the documentation shows already.