1717You'll typically use these to get started with the API:
1818
1919>>> from gcloud import datastore
20- >>> dataset = datastore.get_dataset('dataset-id-here',
21- ... 'long-email@googleapis.com',
22- ... '/path/to/private.key')
20+ >>> dataset = datastore.get_dataset('dataset-id-here')
2321>>> # Then do other things...
2422>>> query = dataset.query().kind('EntityKind')
2523>>> entity = dataset.entity('EntityKind')
5351"""The scope required for authenticating as a Cloud Datastore consumer."""
5452
5553
56- def get_connection (client_email , private_key_path ):
54+ from gcloud import credentials
55+ from gcloud .datastore .connection import Connection
56+
57+
58+ def get_connection ():
5759 """Shortcut method to establish a connection to the Cloud Datastore.
5860
5961 Use this if you are going to access several datasets
6062 with the same set of credentials (unlikely):
6163
6264 >>> from gcloud import datastore
63- >>> connection = datastore.get_connection(email, key_path )
65+ >>> connection = datastore.get_connection()
6466 >>> dataset1 = connection.dataset('dataset1')
6567 >>> dataset2 = connection.dataset('dataset2')
6668
67- :type client_email: string
68- :param client_email: The e-mail attached to the service account.
69-
70- :type private_key_path: string
71- :param private_key_path: The path to a private key file (this file was
72- given to you when you created the service
73- account).
74-
7569 :rtype: :class:`gcloud.datastore.connection.Connection`
7670 :returns: A connection defined with the proper credentials.
7771 """
78- from gcloud import credentials
79- from gcloud .datastore .connection import Connection
72+ implicit_credentials = credentials .get_credentials ()
73+ scoped_credentials = implicit_credentials .create_scoped (SCOPE )
74+ return Connection (credentials = scoped_credentials )
8075
81- svc_account_credentials = credentials .get_for_service_account (
82- client_email , private_key_path , scope = SCOPE )
83- return Connection (credentials = svc_account_credentials )
8476
85-
86- def get_dataset (dataset_id , client_email , private_key_path ):
77+ def get_dataset (dataset_id ):
8778 """Establish a connection to a particular dataset in the Cloud Datastore.
8879
8980 This is a shortcut method for creating a connection and using it
@@ -92,7 +83,7 @@ def get_dataset(dataset_id, client_email, private_key_path):
9283 You'll generally use this as the first call to working with the API:
9384
9485 >>> from gcloud import datastore
95- >>> dataset = datastore.get_dataset('dataset-id', email, key_path )
86+ >>> dataset = datastore.get_dataset('dataset-id')
9687 >>> # Now you can do things with the dataset.
9788 >>> dataset.query().kind('TestKind').fetch()
9889 [...]
@@ -103,16 +94,8 @@ def get_dataset(dataset_id, client_email, private_key_path):
10394 and is usually the same as your Cloud Datastore project
10495 name.
10596
106- :type client_email: string
107- :param client_email: The e-mail attached to the service account.
108-
109- :type private_key_path: string
110- :param private_key_path: The path to a private key file (this file was
111- given to you when you created the service
112- account).
113-
11497 :rtype: :class:`gcloud.datastore.dataset.Dataset`
11598 :returns: A dataset with a connection using the provided credentials.
11699 """
117- connection = get_connection (client_email , private_key_path )
100+ connection = get_connection ()
118101 return connection .dataset (dataset_id )
0 commit comments