@@ -137,6 +137,15 @@ def GetCredentials(package_name, scopes, client_id, client_secret, user_agent,
137137 ** kwds ):
138138 """Attempt to get credentials, using an oauth dance as the last resort."""
139139 scopes = util .NormalizeScopes (scopes )
140+ if isinstance (scope_spec , six .string_types ):
141+ scope_spec = six .ensure_str (scope_spec )
142+ return set (scope_spec .split (' ' ))
143+ elif isinstance (scope_spec , collections .Iterable ):
144+ scope_spec = [six .ensure_str (x ) for x in scope_spec ]
145+ return set (scope_spec )
146+ raise exceptions .TypecheckError (
147+ 'NormalizeScopes expected string or iterable, found %s' % (
148+ type (scope_spec ),))
140149 client_info = {
141150 'client_id' : client_id ,
142151 'client_secret' : client_secret ,
@@ -355,15 +364,15 @@ def _ScopesFromMetadataServer(self, scopes):
355364 def GetServiceAccount (self , account ):
356365 relative_url = 'instance/service-accounts'
357366 response = _GceMetadataRequest (relative_url )
358- response_lines = [six .ensure_text (line ).rstrip (u'/\n \r ' )
367+ response_lines = [six .ensure_str (line ).rstrip (u'/\n \r ' )
359368 for line in response .readlines ()]
360369 return account in response_lines
361370
362371 def GetInstanceScopes (self ):
363372 relative_url = 'instance/service-accounts/{0}/scopes' .format (
364373 self .__service_account_name )
365374 response = _GceMetadataRequest (relative_url )
366- return util .NormalizeScopes (scope .strip ()
375+ return util .NormalizeScopes (six . ensure_str ( scope ) .strip ()
367376 for scope in response .readlines ())
368377
369378 # pylint: disable=arguments-differ
0 commit comments