Skip to content
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

feat: add support for using the emulator programatically #87

Merged
merged 4 commits into from May 26, 2020

Conversation

larkee
Copy link
Contributor

@larkee larkee commented May 21, 2020

Currently, we do not support setting the emulator host outside of the env flag SPANNER_EMULATOR_HOST.

This PR allows users to set the emulator host by using the api_endpoint in client_options with google.auth.credentials.AnonymousCredentials

e.g.

from google.auth.credentials import AnonymousCredentials
from google.cloud import spanner

cred = AnonymousCredentials()
client_options = {'api_endpoint': '0.0.0.0:9010'}
client = spanner.Client(
    credentials=cred,
    client_options=client_options,
    project='emulator-project'
)

@larkee larkee requested a review from hengfengli May 21, 2020 04:40
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label May 21, 2020
else:
self._client_options = client_options

if isinstance(credentials, AnonymousCredentials):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for other libraries, we may have done the opposite.
If the emulator_env_variable is set, we hard-code anonymous/null credentials for the emulator.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated it to set AnonymousCredentials when the env var is set.

Copy link

@hengfengli hengfengli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. A few comments.

google/cloud/spanner_v1/client.py Show resolved Hide resolved
google/cloud/spanner_v1/database.py Show resolved Hide resolved
tests/unit/test_client.py Show resolved Hide resolved
Copy link

@hengfengli hengfengli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@larkee larkee added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 26, 2020
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 26, 2020
@larkee larkee merged commit b22630b into googleapis:master May 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants