Skip to content

Commit d3884dc

Browse files
authored
docs(sample): Add a top-level Datastore samples README (#790)
- [x] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/java-datastore/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea. **Issue already existed** - [x] Ensure the tests and linter pass **N/A** - [x] Code coverage does not decrease (if any source code was changed) **N/A** - [x] Appropriate docs were updated (if necessary) **Strictly a docs addition** Fixes #745 ☕️ Note: I can confirm that the existing pom.xml works correctly.
1 parent 86ca244 commit d3884dc

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

samples/README.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Getting Started with Datastore Samples
2+
3+
## Running a sample using Cloud Shell
4+
5+
The Google Cloud Shell has application default credentials from its compute instance which will allow you to run samples without having to obtain `GOOGLE_APPLICATION_CREDENTIALS`.
6+
Go to the [Datastore Client Readme](https://github.com/googleapis/java-datastore#samples) to run each sample in the Cloud Shell.
7+
8+
## Running a sample at the command line
9+
10+
1. First set up the `GOOGLE_CLOUD_PROJECT` environment variable.
11+
12+
2. Obtain authentication credentials.
13+
14+
Create local credentials by running the following command and following the
15+
oauth2 flow (read more about the command [here][auth_command]):
16+
17+
gcloud auth application-default login
18+
19+
Or manually set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable
20+
to point to a service account key JSON file path.
21+
22+
Learn more at [Setting Up Authentication for Server to Server Production Applications][ADC].
23+
24+
Now you can run a sample:
25+
26+
1. `cd samples/snippets` - all samples are located in the `java-datastore/samples/snippets` directory.
27+
2. `mvn compile exec:java -Dexec.mainClass="com.google.datastore.snippets.TaskList"` - this runs the [TaskList sample](https://github.com/googleapis/java-datastore/blob/master/samples/snippets/src/main/java/com/google/datastore/snippets/TaskList.java).
28+
29+
[ADC]: https://developers.google.com/identity/protocols/application-default-credentials
30+
[auth_command]: https://cloud.google.com/sdk/gcloud/reference/beta/auth/application-default/login

0 commit comments

Comments
 (0)