Просмотр исходного кода

Use GoogleCredentials to replace SignedJwtAssertionCredentials.

baizhang 10 лет назад
Родитель
Сommit
f4e62ed91a
2 измененных файлов с 14 добавлено и 22 удалено
  1. 4 12
      cloudbridge/cloud/providers/gce/provider.py
  2. 10 10
      setup.py

+ 4 - 12
cloudbridge/cloud/providers/gce/provider.py

@@ -11,7 +11,7 @@ import time
 
 from googleapiclient import discovery
 import httplib2
-from oauth2client.client import SignedJwtAssertionCredentials
+from oauth2client.client import GoogleCredentials
 
 from .services import GCESecurityService
 
@@ -73,18 +73,10 @@ class GCECloudProvider(BaseCloudProvider):
 
     def _connect_gce_compute(self):
         if self.credentials_file:
-            with open(self.credentials_file) as f:
-                data = json.load(f)
-                credentials = SignedJwtAssertionCredentials(
-                    data['client_email'], data['private_key'],
-                    'https://www.googleapis.com/auth/compute')
+            credentials = GoogleCredentials.from_json(self.credentials_file)
         else:
-            credentials = SignedJwtAssertionCredentials(
-                self.client_email, self.private_key,
-                'https://www.googleapis.com/auth/compute')
-        http = httplib2.Http()
-        http = credentials.authorize(http)
-        return discovery.build('compute', 'v1', http=http)
+            credentials = GoogleCredentials.get_application_default()
+        return discovery.build('compute', 'v1', credentials=credentials)
 
     def wait_for_global_operation(self, operation):
         while True:

+ 10 - 10
setup.py

@@ -13,18 +13,18 @@ with open(os.path.join('cloudbridge', '__init__.py')) as f:
             version = ast.literal_eval(m.group(1))
             break
 
-base_reqs = ['bunch==1.0.1', 'six==1.10.0', 'retrying==1.3.3']
-openstack_reqs = ['python-novaclient==2.33.0',
+base_reqs = ['bunch>=1.0.1', 'six>=1.10.0', 'retrying>=1.3.3']
+openstack_reqs = ['python-novaclient>=2.33.0',
                   'python-glanceclient',
-                  'python-cinderclient==1.4.0',
-                  'python-swiftclient==2.6.0',
-                  'python-neutronclient==3.1.0',
-                  'python-keystoneclient==2.0.0']
-aws_reqs = ['boto==2.38.0']
-gce_reqs = ['google-api-python-client==1.4.2', "pycrypto"]
+                  'python-cinderclient>=1.4.0',
+                  'python-swiftclient>=2.6.0',
+                  'python-neutronclient>=3.1.0',
+                  'python-keystoneclient>=2.0.0']
+aws_reqs = ['boto>=2.38.0']
+gce_reqs = ['google-api-python-client>=1.4.2', "pycrypto"]
 full_reqs = base_reqs + aws_reqs + openstack_reqs + gce_reqs
-dev_reqs = (['httpretty==0.8.10', 'tox==2.1.1', 'moto==0.4.18',
-             'sphinx==1.3.1'] + full_reqs)
+dev_reqs = (['httpretty>=0.8.10', 'tox>=2.1.1', 'moto>=0.4.18',
+             'sphinx>=1.3.1'] + full_reqs)
 
 setup(name='cloudbridge',
       version=version,