Skip to content

Commit

Permalink
Use new google cloud client package
Browse files Browse the repository at this point in the history
The old gcloud package has been deprecated. The new package also has a
somewhat better implementation to handle authenticated http calls and
hopefully in the future allows us to throw away the monkey patching of
httplib2 completely.
  • Loading branch information
deverant committed Jan 23, 2017
1 parent 8362eb8 commit be9820b
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ will attempt to resolve them:
* gevent>=1.1.1
* boto>=2.40.0
* azure>=1.0.3
* gcloud>=0.17.0
* google-cloud-storage>=0.22.0
* python-swiftclient>=3.0.0
* python-keystoneclient>=3.0.0

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def read(fname):
extras_require={
'aws': ['boto>=2.40.0'],
'azure': ['azure>=1.0.3'],
'google': ['gcloud>=0.17.0'],
'google': ['google-cloud-storage>=0.22.0'],
'swift': ['python-swiftclient>=3.0.0',
'python-keystoneclient>=3.0.0']
},
Expand Down
4 changes: 2 additions & 2 deletions tests/gs_integration_help.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from gcloud import exceptions
from gcloud import storage
from google.cloud import exceptions
from google.cloud import storage
import base64
import hmac
import json
Expand Down
4 changes: 2 additions & 2 deletions tests/test_gs_deleter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from gevent import lock

from fast_wait import fast_wait
from gcloud import storage
from google.cloud import storage
from wal_e import exception
from wal_e.worker.gs import gs_deleter

Expand Down Expand Up @@ -58,7 +58,7 @@ def collect(monkeypatch):
"""Instead of performing bulk delete, collect blob names deleted.
This is to test invariants, as to ensure deleted blobs are passed
to gcloud properly.
to google cloud properly.
"""

collect = BucketDeleteBlobsCollector()
Expand Down
6 changes: 3 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ deps =
azure-storage==0.20.3
azure==1.0.3
boto==2.40.0
gcloud==0.17.0
google-cloud-storage==0.22.0
gevent==1.1.1
python-keystoneclient==3.0.0
python-swiftclient==3.0.0
Expand All @@ -19,7 +19,7 @@ deps =
# All optional cloud dependencies.
boto
azure
gcloud
google-cloud-storage
python-keystoneclient
python-swiftclient
{[base]deps}
Expand All @@ -29,7 +29,7 @@ deps =
# All optional cloud dependencies.
boto
azure
gcloud
google-cloud-storage
python-keystoneclient
python-swiftclient
{[base]deps}
Expand Down
8 changes: 4 additions & 4 deletions wal_e/blobstore/gs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
try:
import gcloud
assert gcloud
import google.cloud
assert google.cloud
except ImportError:
from wal_e.exception import UserException
raise UserException(
msg='Google support requires the module "gcloud" ',
hint='Try running "pip install gcloud')
msg='Google support requires the module "google-cloud-storage" ',
hint='Try running "pip install google-cloud-storage')

from wal_e.blobstore.gs.credentials import Credentials
from wal_e.blobstore.gs.utils import (
Expand Down
14 changes: 8 additions & 6 deletions wal_e/blobstore/gs/calling_format.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from gcloud.storage.connection import Connection
from gcloud.credentials import get_credentials
from gcloud import storage
from google.cloud.storage._http import Connection
from google.cloud.credentials import get_credentials
from google.cloud import storage
from google.auth.credentials import with_scopes_if_required
import google_auth_httplib2

from gevent.local import local
from httplib2 import Http


def connect(creds):
Expand All @@ -24,11 +25,12 @@ class ThreadSafeHttp(object):
__local = local()

def __init__(self, creds):
self.__scoped_credentials = Connection._create_scoped_credentials(
self.__scoped_credentials = with_scopes_if_required(
creds, Connection.SCOPE)

def __getattr__(self, name):
if not hasattr(self.__local, 'http'):
self.__local.http = self.__scoped_credentials.authorize(Http())
self.__local.http = google_auth_httplib2.AuthorizedHttp(
self.__scoped_credentials)

return getattr(self.__local.http, name)
4 changes: 2 additions & 2 deletions wal_e/blobstore/gs/credentials.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Credentials(object):
# Rely on default gcloud client credential resolution instead of
# reifying credentials in WAL-E.
# Rely on default google cloud client credential resolution
# instead of reifying credentials in WAL-E.
pass
2 changes: 1 addition & 1 deletion wal_e/blobstore/gs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from . import calling_format
from datetime import datetime
from datetime import timedelta
from gcloud import storage
from google.cloud import storage
from urllib.parse import urlparse
from wal_e import files
from wal_e import log_help
Expand Down

0 comments on commit be9820b

Please sign in to comment.