Skip to content
This repository has been archived by the owner on Nov 5, 2022. It is now read-only.

Commit

Permalink
feat(scopes): Assign scopes to Google default credentials.
Browse files Browse the repository at this point in the history
  • Loading branch information
joonlim committed Mar 7, 2019
1 parent 3225134 commit 072ae79
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
3 changes: 1 addition & 2 deletions citest/gcp_testing/api_resource_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,10 @@ def make_agent(self, api, default_scope, default_variables=None):
version = self.__investigator.get_api_version(api)
credentials = self.__credentials_path or None
default_variables = default_variables or self.__default_variables
scope_list = [default_scope] if credentials else None

return _gcp_agent_singleton(
api=api, version=version,
scopes=scope_list,
scopes=[default_scope],
credentials_path=credentials,
default_variables=default_variables)

Expand Down
7 changes: 3 additions & 4 deletions citest/gcp_testing/gcp_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,6 @@ def make_service(cls, api=None, version=None,
"""
credentials_path = credentials_path or None
logger = logger or logging.getLogger(__name__)
if (scopes is None) != (credentials_path is None):
raise ValueError(
'Either provide both scopes and credentials_path or neither')

if api is None:
default_api, default_version = cls.default_discovery_name_and_version()
Expand All @@ -123,12 +120,14 @@ def make_service(cls, api=None, version=None,
http = apiclient.http.set_user_agent(
http, 'citest/{version}'.format(version=citest.__version__))
credentials = None
if scopes is not None:
if credentials_path is not None:
logger.info('Authenticating %s %s', api, version)
credentials = ServiceAccountCredentials.from_json_keyfile_name(
credentials_path, scopes=scopes)
else:
credentials = GoogleCredentials.get_application_default()
if scopes and credentials.create_scoped_required():
credentials = credentials.create_scoped(scopes)

http = credentials.authorize(http)
logger.info('Constructing %s service...', api)
Expand Down
2 changes: 1 addition & 1 deletion citest/gcp_testing/resource_snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def delete_all_collected(
print('\n{action} from API={api} with scope={scope}'.format(
action=action,
api=api,
scope=scope if self.__credentials_path else '<default>'))
scope=scope))

sample = collected.pop()
was_aggregated = isinstance(sample, tuple)
Expand Down

0 comments on commit 072ae79

Please sign in to comment.