Skip to content

Commit fa260eb

Browse files
committed
Removing gcloud.credential.Credential class.
No instances of this class were ever created and it only had one factory method, which is now a function. This class was also misunderstood / misreferenced in the docstring mentions.
1 parent 398addf commit fa260eb

File tree

6 files changed

+40
-48
lines changed

6 files changed

+40
-48
lines changed

gcloud/connection.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from pkg_resources import get_distribution
2+
23
import httplib2
34

45

@@ -22,11 +23,10 @@ class Connection(object):
2223
"""The user agent for gcloud-python requests."""
2324

2425
def __init__(self, credentials=None):
25-
""":type credentials: :class:`gcloud.credentials.Credentials`
26+
"""
27+
:type credentials: :class:`oauth2client.client.OAuth2Credentials`
2628
:param credentials: The OAuth2 Credentials to use for this connection.
27-
2829
"""
29-
3030
self._credentials = credentials
3131

3232
@property

gcloud/credentials.py

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,36 @@
33
from oauth2client import client
44

55

6-
class Credentials(object):
7-
"""An object used to simplify the OAuth2 credentials library.
6+
def get_for_service_account(client_email, private_key_path, scope=None):
7+
"""Gets the credentials for a service account.
88
99
.. note::
10-
You should not need to use this class directly.
10+
You should not need to use this method directly.
1111
Instead, use the helper methods provided in
1212
:func:`gcloud.datastore.__init__.get_connection`
1313
and
1414
:func:`gcloud.datastore.__init__.get_dataset`
15-
which use this class under the hood.
16-
"""
15+
which use this method under the hood.
16+
17+
:type client_email: string
18+
:param client_email: The e-mail attached to the service account.
19+
20+
:type private_key_path: string
21+
:param private_key_path: The path to a private key file (this file was
22+
given to you when you created the service
23+
account).
1724
18-
@classmethod
19-
def get_for_service_account(cls, client_email, private_key_path,
20-
scope=None):
21-
"""Gets the credentials for a service account.
22-
23-
:type client_email: string
24-
:param client_email: The e-mail attached to the service account.
25-
26-
:type private_key_path: string
27-
:param private_key_path: The path to a private key file (this file was
28-
given to you when you created the service
29-
account).
30-
31-
:type scope: string or tuple of strings
32-
:param scope: The scope against which to authenticate.
33-
(Different services require different scopes,
34-
check the documentation for which scope is required
35-
for the different levels of access
36-
to any particular API.)
37-
"""
38-
return client.SignedJwtAssertionCredentials(
39-
service_account_name=client_email,
40-
private_key=open(private_key_path).read(),
41-
scope=scope)
25+
:type scope: string or tuple of strings
26+
:param scope: The scope against which to authenticate. (Different services
27+
require different scopes, check the documentation for which
28+
scope is required for the different levels of access to any
29+
particular API.)
30+
31+
:rtype: :class:`oauth2client.client.SignedJwtAssertionCredentials`
32+
:returns: A new SignedJwtAssertionCredentials instance with the
33+
needed service account settings.
34+
"""
35+
return client.SignedJwtAssertionCredentials(
36+
service_account_name=client_email,
37+
private_key=open(private_key_path).read(),
38+
scope=scope)

gcloud/datastore/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ def get_connection(client_email, private_key_path):
6161
:rtype: :class:`gcloud.datastore.connection.Connection`
6262
:returns: A connection defined with the proper credentials.
6363
"""
64-
from gcloud.credentials import Credentials
64+
from gcloud import credentials
6565
from gcloud.datastore.connection import Connection
6666

67-
credentials = Credentials.get_for_service_account(
67+
svc_account_credentials = credentials.get_for_service_account(
6868
client_email, private_key_path, scope=SCOPE)
69-
return Connection(credentials=credentials)
69+
return Connection(credentials=svc_account_credentials)
7070

7171

7272
def get_dataset(dataset_id, client_email, private_key_path):

gcloud/datastore/connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Connection(connection.Connection):
1010
This class should understand only the basic types (and protobufs)
1111
in method arguments, however should be capable of returning advanced types.
1212
13-
:type credentials: :class:`gcloud.credentials.Credentials`
13+
:type credentials: :class:`oauth2client.client.OAuth2Credentials`
1414
:param credentials: The OAuth2 Credentials to use for this connection.
1515
"""
1616

gcloud/storage/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ def get_connection(project, client_email, private_key_path):
6262
:returns: A connection defined with the proper credentials.
6363
"""
6464

65-
from gcloud.credentials import Credentials
65+
from gcloud import credentials
6666
from gcloud.storage.connection import Connection
6767

68-
credentials = Credentials.get_for_service_account(
68+
svc_account_credentials = credentials.get_for_service_account(
6969
client_email, private_key_path, scope=SCOPE)
70-
return Connection(project=project, credentials=credentials)
70+
return Connection(project=project, credentials=svc_account_credentials)
7171

7272

7373
def get_bucket(bucket_name, project, client_email, private_key_path):

gcloud/test_credentials.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,18 @@
33

44
class TestCredentials(unittest2.TestCase):
55

6-
def _getTargetClass(self):
7-
from gcloud.credentials import Credentials
8-
return Credentials
9-
106
def test_get_for_service_account_wo_scope(self):
117
from tempfile import NamedTemporaryFile
128
from gcloud import credentials
139
CLIENT_EMAIL = '[email protected]'
1410
PRIVATE_KEY = 'SEEkR1t'
15-
cls = self._getTargetClass()
1611
client = _Client()
1712
with _Monkey(credentials, client=client):
1813
with NamedTemporaryFile() as f:
1914
f.write(PRIVATE_KEY)
2015
f.flush()
21-
found = cls.get_for_service_account(CLIENT_EMAIL, f.name)
16+
found = credentials.get_for_service_account(
17+
CLIENT_EMAIL, f.name)
2218
self.assertTrue(found is client._signed)
2319
self.assertEqual(client._called_with,
2420
{'service_account_name': CLIENT_EMAIL,
@@ -32,14 +28,13 @@ def test_get_for_service_account_w_scope(self):
3228
CLIENT_EMAIL = '[email protected]'
3329
PRIVATE_KEY = 'SEEkR1t'
3430
SCOPE = 'SCOPE'
35-
cls = self._getTargetClass()
3631
client = _Client()
3732
with _Monkey(credentials, client=client):
3833
with NamedTemporaryFile() as f:
3934
f.write(PRIVATE_KEY)
4035
f.flush()
41-
found = cls.get_for_service_account(CLIENT_EMAIL, f.name,
42-
SCOPE)
36+
found = credentials.get_for_service_account(
37+
CLIENT_EMAIL, f.name, SCOPE)
4338
self.assertTrue(found is client._signed)
4439
self.assertEqual(client._called_with,
4540
{'service_account_name': CLIENT_EMAIL,

0 commit comments

Comments
 (0)