diff --git a/gcloud/connection.py b/gcloud/connection.py index 80dcb92fadea..b7321134680f 100644 --- a/gcloud/connection.py +++ b/gcloud/connection.py @@ -21,9 +21,6 @@ import httplib2 -from gcloud.credentials import get_credentials -from gcloud.credentials import get_for_service_account_json -from gcloud.credentials import get_for_service_account_p12 from gcloud.exceptions import make_exception @@ -122,92 +119,6 @@ def _create_scoped_credentials(credentials, scope): credentials = credentials.create_scoped(scope) return credentials - @classmethod - def from_service_account_json(cls, json_credentials_path, *args, **kwargs): - """Factory to retrieve JSON credentials while creating connection. - - :type json_credentials_path: string - :param json_credentials_path: The path to a private key file (this file - was given to you when you created the - service account). This file must contain - a JSON object with a private key and - other credentials information (downloaded - from the Google APIs console). - - :type args: tuple - :param args: Remaining positional arguments to pass to constructor. - - :type kwargs: dictionary - :param kwargs: Remaining keyword arguments to pass to constructor. - - :rtype: :class:`gcloud.connection.Connection` - :returns: The connection created with the retrieved JSON credentials. - :raises: class:`TypeError` if there is a conflict with the kwargs - and the credentials created by the factory. - """ - if 'credentials' in kwargs: - raise TypeError('credentials must not be in keyword arguments') - credentials = get_for_service_account_json(json_credentials_path) - kwargs['credentials'] = credentials - return cls(*args, **kwargs) - - @classmethod - def from_service_account_p12(cls, client_email, private_key_path, - *args, **kwargs): - """Factory to retrieve P12 credentials while creating connection. - - .. note:: - Unless you have an explicit reason to use a PKCS12 key for your - service account, we recommend using a JSON key. - - :type client_email: string - :param client_email: The e-mail attached to the service account. - - :type private_key_path: string - :param private_key_path: The path to a private key file (this file was - given to you when you created the service - account). This file must be in P12 format. - - :type args: tuple - :param args: Remaining positional arguments to pass to constructor. - - :type kwargs: dictionary - :param kwargs: Remaining keyword arguments to pass to constructor. - - :rtype: :class:`gcloud.connection.Connection` - :returns: The connection created with the retrieved P12 credentials. - :raises: class:`TypeError` if there is a conflict with the kwargs - and the credentials created by the factory. - """ - if 'credentials' in kwargs: - raise TypeError('credentials must not be in keyword arguments') - credentials = get_for_service_account_p12(client_email, - private_key_path) - kwargs['credentials'] = credentials - return cls(*args, **kwargs) - - @classmethod - def from_environment(cls, *args, **kwargs): - """Factory to retrieve implicit credentials while creating connection. - - :type args: tuple - :param args: Remaining positional arguments to pass to constructor. - - :type kwargs: dictionary - :param kwargs: Remaining keyword arguments to pass to constructor. - - :rtype: :class:`gcloud.connection.Connection` - :returns: The connection created with the retrieved implicit - credentials. - :raises: class:`TypeError` if there is a conflict with the kwargs - and the credentials created by the factory. - """ - if 'credentials' in kwargs: - raise TypeError('credentials must not be in keyword arguments') - credentials = get_credentials() - kwargs['credentials'] = credentials - return cls(*args, **kwargs) - class JSONConnection(Connection): """A connection to a Google JSON-based API. diff --git a/gcloud/test_connection.py b/gcloud/test_connection.py index d5cbcaa768bc..0af98a821f52 100644 --- a/gcloud/test_connection.py +++ b/gcloud/test_connection.py @@ -66,81 +66,6 @@ def test_user_agent_format(self): conn = self._makeOne() self.assertEqual(conn.USER_AGENT, expected_ua) - def _from_service_account_json_helper(self, **kwargs): - from gcloud._testing import _Monkey - from gcloud import connection - - KLASS = self._getTargetClass() - CREDENTIALS = _Credentials() - _CALLED = [] - - def mock_creds(arg1): - _CALLED.append((arg1,)) - return CREDENTIALS - - FOO = object() - with _Monkey(connection, get_for_service_account_json=mock_creds): - conn = KLASS.from_service_account_json(FOO, **kwargs) - - self.assertTrue(conn.credentials is CREDENTIALS) - self.assertEqual(_CALLED, [(FOO,)]) - - def test_from_service_account_json(self): - self._from_service_account_json_helper() - - def test_from_service_account_json_fail(self): - with self.assertRaises(TypeError): - self._from_service_account_json_helper(credentials=None) - - def _from_service_account_p12_helper(self, **kwargs): - from gcloud._testing import _Monkey - from gcloud import connection - - KLASS = self._getTargetClass() - CREDENTIALS = _Credentials() - _CALLED = [] - - def mock_creds(arg1, arg2): - _CALLED.append((arg1, arg2)) - return CREDENTIALS - - FOO = object() - BAR = object() - with _Monkey(connection, get_for_service_account_p12=mock_creds): - conn = KLASS.from_service_account_p12(FOO, BAR, **kwargs) - - self.assertTrue(conn.credentials is CREDENTIALS) - self.assertEqual(_CALLED, [(FOO, BAR)]) - - def test_from_service_account_p12(self): - self._from_service_account_p12_helper() - - def test_from_service_account_p12_fail(self): - with self.assertRaises(TypeError): - self._from_service_account_p12_helper(credentials=None) - - def _from_environment_helper(self, **kwargs): - from gcloud._testing import _Monkey - from gcloud import connection - - KLASS = self._getTargetClass() - CREDENTIALS = _Credentials() - - def mock_creds(): - return CREDENTIALS - - with _Monkey(connection, get_credentials=mock_creds): - conn = KLASS.from_environment(**kwargs) - - self.assertTrue(conn.credentials is CREDENTIALS) - - def test_from_environment(self): - self._from_environment_helper() - - def test_from_environment_fail(self): - with self.assertRaises(TypeError): - self._from_environment_helper(credentials=None) - class TestJSONConnection(unittest2.TestCase):