Skip to content

Commit 8e86218

Browse files
committed
Removing factories from base Connection class.
These are no longer needed since the factories are on all clients.
1 parent 51640a5 commit 8e86218

2 files changed

Lines changed: 0 additions & 164 deletions

File tree

gcloud/connection.py

Lines changed: 0 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121

2222
import httplib2
2323

24-
from gcloud.credentials import get_credentials
25-
from gcloud.credentials import get_for_service_account_json
26-
from gcloud.credentials import get_for_service_account_p12
2724
from gcloud.exceptions import make_exception
2825

2926

@@ -122,92 +119,6 @@ def _create_scoped_credentials(credentials, scope):
122119
credentials = credentials.create_scoped(scope)
123120
return credentials
124121

125-
@classmethod
126-
def from_service_account_json(cls, json_credentials_path, *args, **kwargs):
127-
"""Factory to retrieve JSON credentials while creating connection.
128-
129-
:type json_credentials_path: string
130-
:param json_credentials_path: The path to a private key file (this file
131-
was given to you when you created the
132-
service account). This file must contain
133-
a JSON object with a private key and
134-
other credentials information (downloaded
135-
from the Google APIs console).
136-
137-
:type args: tuple
138-
:param args: Remaining positional arguments to pass to constructor.
139-
140-
:type kwargs: dictionary
141-
:param kwargs: Remaining keyword arguments to pass to constructor.
142-
143-
:rtype: :class:`gcloud.connection.Connection`
144-
:returns: The connection created with the retrieved JSON credentials.
145-
:raises: class:`TypeError` if there is a conflict with the kwargs
146-
and the credentials created by the factory.
147-
"""
148-
if 'credentials' in kwargs:
149-
raise TypeError('credentials must not be in keyword arguments')
150-
credentials = get_for_service_account_json(json_credentials_path)
151-
kwargs['credentials'] = credentials
152-
return cls(*args, **kwargs)
153-
154-
@classmethod
155-
def from_service_account_p12(cls, client_email, private_key_path,
156-
*args, **kwargs):
157-
"""Factory to retrieve P12 credentials while creating connection.
158-
159-
.. note::
160-
Unless you have an explicit reason to use a PKCS12 key for your
161-
service account, we recommend using a JSON key.
162-
163-
:type client_email: string
164-
:param client_email: The e-mail attached to the service account.
165-
166-
:type private_key_path: string
167-
:param private_key_path: The path to a private key file (this file was
168-
given to you when you created the service
169-
account). This file must be in P12 format.
170-
171-
:type args: tuple
172-
:param args: Remaining positional arguments to pass to constructor.
173-
174-
:type kwargs: dictionary
175-
:param kwargs: Remaining keyword arguments to pass to constructor.
176-
177-
:rtype: :class:`gcloud.connection.Connection`
178-
:returns: The connection created with the retrieved P12 credentials.
179-
:raises: class:`TypeError` if there is a conflict with the kwargs
180-
and the credentials created by the factory.
181-
"""
182-
if 'credentials' in kwargs:
183-
raise TypeError('credentials must not be in keyword arguments')
184-
credentials = get_for_service_account_p12(client_email,
185-
private_key_path)
186-
kwargs['credentials'] = credentials
187-
return cls(*args, **kwargs)
188-
189-
@classmethod
190-
def from_environment(cls, *args, **kwargs):
191-
"""Factory to retrieve implicit credentials while creating connection.
192-
193-
:type args: tuple
194-
:param args: Remaining positional arguments to pass to constructor.
195-
196-
:type kwargs: dictionary
197-
:param kwargs: Remaining keyword arguments to pass to constructor.
198-
199-
:rtype: :class:`gcloud.connection.Connection`
200-
:returns: The connection created with the retrieved implicit
201-
credentials.
202-
:raises: class:`TypeError` if there is a conflict with the kwargs
203-
and the credentials created by the factory.
204-
"""
205-
if 'credentials' in kwargs:
206-
raise TypeError('credentials must not be in keyword arguments')
207-
credentials = get_credentials()
208-
kwargs['credentials'] = credentials
209-
return cls(*args, **kwargs)
210-
211122

212123
class JSONConnection(Connection):
213124
"""A connection to a Google JSON-based API.

gcloud/test_connection.py

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -66,81 +66,6 @@ def test_user_agent_format(self):
6666
conn = self._makeOne()
6767
self.assertEqual(conn.USER_AGENT, expected_ua)
6868

69-
def _from_service_account_json_helper(self, **kwargs):
70-
from gcloud._testing import _Monkey
71-
from gcloud import connection
72-
73-
KLASS = self._getTargetClass()
74-
CREDENTIALS = _Credentials()
75-
_CALLED = []
76-
77-
def mock_creds(arg1):
78-
_CALLED.append((arg1,))
79-
return CREDENTIALS
80-
81-
FOO = object()
82-
with _Monkey(connection, get_for_service_account_json=mock_creds):
83-
conn = KLASS.from_service_account_json(FOO, **kwargs)
84-
85-
self.assertTrue(conn.credentials is CREDENTIALS)
86-
self.assertEqual(_CALLED, [(FOO,)])
87-
88-
def test_from_service_account_json(self):
89-
self._from_service_account_json_helper()
90-
91-
def test_from_service_account_json_fail(self):
92-
with self.assertRaises(TypeError):
93-
self._from_service_account_json_helper(credentials=None)
94-
95-
def _from_service_account_p12_helper(self, **kwargs):
96-
from gcloud._testing import _Monkey
97-
from gcloud import connection
98-
99-
KLASS = self._getTargetClass()
100-
CREDENTIALS = _Credentials()
101-
_CALLED = []
102-
103-
def mock_creds(arg1, arg2):
104-
_CALLED.append((arg1, arg2))
105-
return CREDENTIALS
106-
107-
FOO = object()
108-
BAR = object()
109-
with _Monkey(connection, get_for_service_account_p12=mock_creds):
110-
conn = KLASS.from_service_account_p12(FOO, BAR, **kwargs)
111-
112-
self.assertTrue(conn.credentials is CREDENTIALS)
113-
self.assertEqual(_CALLED, [(FOO, BAR)])
114-
115-
def test_from_service_account_p12(self):
116-
self._from_service_account_p12_helper()
117-
118-
def test_from_service_account_p12_fail(self):
119-
with self.assertRaises(TypeError):
120-
self._from_service_account_p12_helper(credentials=None)
121-
122-
def _from_environment_helper(self, **kwargs):
123-
from gcloud._testing import _Monkey
124-
from gcloud import connection
125-
126-
KLASS = self._getTargetClass()
127-
CREDENTIALS = _Credentials()
128-
129-
def mock_creds():
130-
return CREDENTIALS
131-
132-
with _Monkey(connection, get_credentials=mock_creds):
133-
conn = KLASS.from_environment(**kwargs)
134-
135-
self.assertTrue(conn.credentials is CREDENTIALS)
136-
137-
def test_from_environment(self):
138-
self._from_environment_helper()
139-
140-
def test_from_environment_fail(self):
141-
with self.assertRaises(TypeError):
142-
self._from_environment_helper(credentials=None)
143-
14469

14570
class TestJSONConnection(unittest2.TestCase):
14671

0 commit comments

Comments
 (0)