GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Create client from service account stored in string · Issue #8 · googleapis/python-cloud-core
This repository was archived by the owner on Feb 13, 2026. It is now read-only.
This repository was archived by the owner on Feb 13, 2026. It is now read-only.
Create client from service account stored in string #8Copy link Copy link Closed Labels type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design. DescriptionHi, 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: # Storage example but is a general issue AFAIU import os import json from google.cloud import storage from google.oauth2 import service_account credentials_json_string = "{...service account....}" credentials_json = json.loads(credentials_json_string) credentials = service_account.Credentials.from_service_account_info(credentials_json) # Credentials has project_id already so project should be optional but it's not. client = storage.Client(project=credentials['project_id'], credentials=credentials) print(list(client.list_buckets())) Proposal:@classmethod def from_service_account_json_string(cls, json_credentials, *args, **kwargs): """Factory to create credentials with provided json_credentials. :type json_credentials: str :param json_credentials: The contents of a private key file. This string must contain 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 provided 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_info = json.load(json_credentials) credentials = service_account.Credentials.from_service_account_info( credentials_info ) if cls._SET_PROJECT: if "project" not in kwargs: kwargs["project"] = credentials_info.get("project_id") kwargs["credentials"] = credentials return cls(*args, **kwargs) Activity
MetadataMetadataAssigneesLabelstype: feature request‘Nice-to-have’ improvement, new feature or different behavior or design. TypeProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |