GoogleCloudPlatform / gcs-oauth2-boto-plugin

Auth plugin allowing use the use of OAuth 2.0 credentials for Google Cloud Storage in the Boto library.
Apache License 2.0
21 stars 38 forks source link

Oauth2GoogleClient object has no attribute cache_key_base #17

Closed bivald closed 3 years ago

bivald commented 8 years ago

I'm trying to port gcs-oauth2-boto-plugin to make it Python2+Python3 compatible, but ran into this issue when cloning from master:

File "/enplore-code/environments/enplore-worker-aircraft-dfdr/site-packages/boto/connection.py", line 377, in authorize connection._auth_handler.add_auth(self, **kwargs) File "/enplore-code/environments/enplore-worker-aircraft-dfdr/site-packages/gcs_oauth2_boto_plugin/oauth2_plugin.py", line 69, in add_auth self.oauth2_client.GetAuthorizationHeader() File "/enplore-code/environments/enplore-worker-aircraft-dfdr/site-packages/gcs_oauth2_boto_plugin/oauth2_client.py", line 345, in GetAuthorizationHeader return 'Bearer %s' % self.GetAccessToken().token File "/enplore-code/environments/enplore-worker-aircraft-dfdr/site-packages/gcs_oauth2_boto_plugin/oauth2_client.py", line 310, in GetAccessToken cache_key = self.CacheKey() File "/enplore-code/environments/enplore-worker-aircraft-dfdr/site-packages/gcs_oauth2_boto_plugin/oauth2_client.py", line 335, in CacheKey h.update(self.cache_key_base) AttributeError: 'Oauth2GoogleClient' object has no attribute 'cache_key_base'

I'm using a boto config, with a gs service key file: gs_service_key_file = /etc/enplore/vagrant-etc/testdemo-s652y8s5.json

The issue doesn't exist when installing from pip but appeared in the January 27 commit (https://github.com/GoogleCloudPlatform/gcs-oauth2-boto-plugin/commit/53df987472d2440cd8661f2370f33f5e44aa115e)

I've spent a few hours on this, and would love some help. From what I can tell:

oauth2_helper.py

if json_key:
  return oauth2_client.Oauth2GoogleClient(
    oauth2client.client.GoogleCredentials.from_stream(private_key_filename)
  )

Doesn't return a oauth2_client with cache_key_base attribute which is later needed for CacheKey():

 def CacheKey(self):
"""Computes a cache key.
The cache key is computed as the SHA1 hash of the refresh token for user
accounts, or the hash of the gs_service_client_id for service accounts,
which satisfies the FileSystemTokenCache requirement that cache keys do not
leak information about token values.
Returns:
  A hash key.
"""
    h = sha1()
    h.update(self.cache_key_base.encode('utf-8'))
    return h.hexdigest()

However, I think there is a bunch of stuff missing on the Oauth2GoogleClient which is available on OAuth2ServiceAccountClient, like access_token_cache, FetchAccessToken etc.

I'm gonna do a pull request on my own branch and link to it from here, hopefully someone other then me can tell if I re-implemented it correctly (I've tested on py2 and py3 and it works on both)

bivald commented 8 years ago

Commit on my branch is available on https://github.com/enplore/gcs-oauth2-boto-plugin/commit/5fcf59242bc8109efe63d7fd40b16d386e86ebb3

If you are happy with it I'll open a pull request on the full python3 compatible branch (test passes on both py2 and py3, and at least the parts I use work on both)