-
Notifications
You must be signed in to change notification settings - Fork 19
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
Core: Move google-cloud-core functionality into api_core #2
Comments
Scattered thoughts on stuff for my own future benefit (feel free to comment, but just know these are raw). Clients:
Connection/JSONConnection:
|
@jonparrott I actually massively reduced the interface of |
Okay, here's my proposal for removing First, we will no longer have base classes for providing the credentials, We'll add an api_core helper for getting credentials and a project ID. class SomeClient:
SCOPES = [...]
def __init__(self, credentials=None):
self.credentials, _ = (
google.api_core.client_helpers.get_default_credentials_and_project(
credentials, scopes=self.SCOPES))
@property
def credentials():
return self._credentials Some clients need/use project id: class SomeClient:
def __init__(self, credentials=None, project=None):
self._credentials, self._project = (
google.api_core.client_helpers.get_default_credentials_and_project(
credentials,
project,
scopes=self.SCOPES,
require_project=True))
@property
def credentials():
return self._credentials
@property
def project():
return self._project Some clients need to construct an HTTP object, underlying gapic, etc. # HTTP
class SomeClient:
def __init__(self, credentials=None, project=None, _http=None):
self._credentials, self._project = (
google.api_core.client_helpers.get_default_credentials_and_project(
credentials,
project,
scopes=self.SCOPES,
require_project=True))
self._http = google.api_core.http_helpers.make_authorized_session(
self._credentials)
# GAPIC is easy
class SomeClient:
def __init__(self, credentials=None, project=None, _channel=None):
self._credentials, self._project = (
google.api_core.client_helpers.get_default_credentials_and_project(
credentials,
project,
scopes=self.SCOPES,
require_project=True))
self._gapic = some_api_v1.SomeClient(
credentials=self._credentials, channel=_channel) Now let's get tricky: some clients need to support emulators. class SomeClient:
EMULATOR_ENV_VAR = '...'
EMULATOR_PROJECT_ENV_VAR = '...' # optional
def __init__(self, credentials=None, project=None, _channel=None):
emulator_address = os.environ.get(EMULATOR_ENV_VAR)
if emulator_address:
self._credentials = google.auth.AnonymousCredentials()
# Optional
self._project = os.environ.get(
EMULATOR_PROJECT_ENV_VAR, 'project-id')
else:
self._credentials, self._project = (
google.api_core.client_helpers.get_default_credentials_and_project(
credentials, scopes=self.SCOPES)) In addition to just that, though, grpc clients need to detect this case and if emulator_address:
channel = google.api_core.grpc_helper.make_emulator_channel(
emulator_address)
...
self._gapic = some_api_v1.SomeClient(
credentials=self._credentials, channel=_channel) That may seem like a lot of code, but doing away with the inheritance based stuff for credentials/project/http will actually simplify a lot of code (see Datastore). This can also be done in a completely non-breaking way (yay). @lukesneeringer @tseaver WDYT? |
I'm fine with the notion overall. One note: the "construct an HTTP object" bit needs to account for the possibility that the user passed in |
Good catch. Anything else I might have missed? |
Necroing this bug to bring it to the attention of @crwilcox - this is what's needed to kill google-cloud-core. |
Any plans to make this happen? Also, anecdotally, |
The text was updated successfully, but these errors were encountered: