|
3 | 3 | from oauth2client import client |
4 | 4 |
|
5 | 5 |
|
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. |
8 | 8 |
|
9 | 9 | .. note:: |
10 | | - You should not need to use this class directly. |
| 10 | + You should not need to use this method directly. |
11 | 11 | Instead, use the helper methods provided in |
12 | 12 | :func:`gcloud.datastore.__init__.get_connection` |
13 | 13 | and |
14 | 14 | :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). |
17 | 24 |
|
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) |
0 commit comments