-
Notifications
You must be signed in to change notification settings - Fork 17
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
Create client from service account stored in string #8
Comments
@busunkim96 are you an owner of Python-cloud-core? Not sure who I should ask if this is something that we'd like to support. |
@frankyn Yes! If this is added to google-cloud-core it should also be added to the generated clients. Since this will impact all the clients, I'll bring it up tomorrow at the Python client weekly. |
I just want to point out, this issue contains a secondary feature request. The original request provides this example: # Credentials has project_id already so project should be optional but it's not.
client = storage.Client(project=credentials['project_id'], credentials=credentials) In fact So the secondary feature request here is: if credentials are explicitly provided, then the client should skip autoloading. This behavior would be good whether the credentials are loaded from a file or string. |
@rvandegrift The secondary request is now tracked in #27, and should be resolved in PR #51. @frankyn The spelling of the class _ClientFactoryMixin(object):
...
@classmethod
def from_service_account_info(cls, info, *args, **kwargs):
"""Factory to load JSON credentials while creating client.
:type info: dict
:param info:
A JSON object with a private key and other credentials information
(downloaded from the Google APIs console).
:type args: tuple
:param args: Remaining positional arguments to pass to constructor.
:param kwargs: Remaining keyword arguments to pass to constructor.
:rtype: :class:`_ClientFactoryMixin`
:returns: The client created with the retrieved JSON credentials.
:raises TypeError: if there is a conflict with the kwargs
and the credentials created by the factory.
"""
if "credentials" in kwargs:
raise TypeError("credentials must not be in keyword arguments")
credentials = service_account.Credentials.from_service_account_info(info)
if cls._SET_PROJECT:
if "project" not in kwargs:
kwargs["project"] = credentials_info.get("project_id")
kwargs["credentials"] = credentials
return cls(*args, **kwargs) The existing @busunkim96 I created googleapis/gapic-generator-python#705 to track adding this method for the microgenerator. Do we need to add support for it in the macrogenerator too? |
@tseaver Nope, just the microgenerator is fine. The monolith is almost gone (we're down to 2 libraries). :) |
Hi,
This was raised in python-storage: googleapis/python-storage#93
python-cloud-core library has support for from_service_account_json, which accepts a file path to a service account.
Feature request is to add support to accept a json string of the service account. User stores the service account file contents in an environment variable instead of in a file.
Open question: I'm not sure if this is a path that should be supported so I'm leaving that as an open question in this issue. If this feature is not supported then the workaround is to construct a credentials object and explicitly set a project id:
Proposal:
The text was updated successfully, but these errors were encountered: