def from_service_account_p12(cls, client_email, private_key_path, *args, **kwargs): """Factory to retrieve P12 credentials while creating client. .. 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.client.Client` :returns: The client 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)
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. :rtype: :class:`gcloud.connection.Connection` :returns: The connection created with the retrieved P12 credentials. """ credentials = get_for_service_account_p12(client_email, private_key_path) if 'credentials' in kwargs: raise TypeError('credentials must not be in keyword arguments') kwargs['credentials'] = credentials return cls(*args, **kwargs)
def from_service_account_p12(cls, client_email, private_key_path, project=None): """Factory to retrieve P12 credentials while creating client. .. 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 project: string :param project: the project which the client acts on behalf of. Will be passed when creating a topic. If not passed, falls back to the default inferred from the environment. :rtype: :class:`gcloud.pubsub.client.Client` :returns: The client created with the retrieved P12 credentials. """ credentials = get_for_service_account_p12(client_email, private_key_path) return cls(project=project, credentials=credentials)
def from_service_account_p12(cls, client_email, private_key_path, *args, **kwargs): """Factory to retrieve P12 credentials while creating client. .. 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: dict :param kwargs: Remaining keyword arguments to pass to constructor. :rtype: :class:`gcloud.client.Client` :returns: The client 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)
def test_get_for_service_account_p12_wo_scope(self): from tempfile import NamedTemporaryFile from gcloud import credentials from gcloud._testing import _Monkey CLIENT_EMAIL = '*****@*****.**' PRIVATE_KEY = b'SEEkR1t' client = _Client() with _Monkey(credentials, client=client): with NamedTemporaryFile() as file_obj: file_obj.write(PRIVATE_KEY) file_obj.flush() found = credentials.get_for_service_account_p12( CLIENT_EMAIL, file_obj.name) self.assertTrue(found is client._signed) expected_called_with = { 'service_account_name': CLIENT_EMAIL, 'private_key': PRIVATE_KEY, 'scope': None, } self.assertEqual(client._called_with, expected_called_with)
def test_get_for_service_account_p12_wo_scope(self): from tempfile import NamedTemporaryFile from gcloud import credentials from gcloud._testing import _Monkey CLIENT_EMAIL = '*****@*****.**' PRIVATE_KEY = 'SEEkR1t' client = _Client() with _Monkey(credentials, client=client): with NamedTemporaryFile() as file_obj: file_obj.write(PRIVATE_KEY) file_obj.flush() found = credentials.get_for_service_account_p12( CLIENT_EMAIL, file_obj.name) self.assertTrue(found is client._signed) expected_called_with = { 'service_account_name': CLIENT_EMAIL, 'private_key': PRIVATE_KEY, 'scope': None, } self.assertEqual(client._called_with, expected_called_with)
def _callFUT(self, client_email, private_key_path, scope=None): from gcloud.credentials import get_for_service_account_p12 return get_for_service_account_p12(client_email, private_key_path, scope=scope)