Skip to content

Commit dd10b2c

Browse files
author
Jerjou Cheng
committed
Add Application Default Credentials quirks.
Also - refactor documentation.
1 parent ccf5fc8 commit dd10b2c

File tree

1 file changed

+30
-37
lines changed
  • cloud-storage/xml-api/serviceaccount-cmdline-sample

1 file changed

+30
-37
lines changed

cloud-storage/xml-api/serviceaccount-cmdline-sample/README.md

+30-37
Original file line numberDiff line numberDiff line change
@@ -6,43 +6,44 @@ Browse Online
66

77
The main file is [StorageServiceAccountSample.java](https://github.com/GoogleCloudPlatform/java-docs-samples/blob/master/cloud-storage/xml-api/serviceaccount-cmdline-sample/src/main/java/StorageServiceAccountSample.java).
88

9-
Get a Service Account
10-
---------------------
119

12-
See the instructions at https://developers.google.com/storage/docs/xml-api-java-samples
13-
for setting up a service account.
10+
Setup
11+
-----
1412

15-
Checkout Instructions
16-
---------------------
17-
18-
1. **Prerequisites:**
19-
1. install the latest version of [Java](http//java.com) and [Maven](http://maven.apache.org/download.html).
20-
1. [Create](https://cloud.google.com/storage/docs/cloud-console#_creatingbuckets) a Google Cloud Storage bucket
21-
1. You must also be able to work with [GitHub](https://help.github.com/articles/set-up-git) repositories.
22-
1. You may need to set your `JAVA_HOME`.
23-
24-
1. Clone repository.
13+
* [Create](https://cloud.google.com/storage/docs/cloud-console#_creatingbuckets) a Google Cloud Storage bucket
14+
* This module uses [Application Default Credentials](https://developers.google.com/accounts/docs/application-default-credentials). If you are running it outside of [Google Compute Engine](https://cloud.google.com/compute/), you'll need to
15+
* Download the json private key for a [Service Account](https://cloud.google.com/storage/docs/authentication#service_accounts) and have it available.
16+
* Set an environment variable: `export GOOGLE_APPLICATION_CREDENTIALS=path/to/your-key.json`
17+
* You must also be able to work with [GitHub](https://help.github.com/articles/set-up-git) repositories.
18+
* Clone repository.
2519

2620
git clone https://github.com/GoogleCloudPlatform/java-docs-samples.git
27-
cd java-docs-samples/cloud-storage/xml-api/serviceaccount-cmdline-sample
2821

29-
1. Update key.json file.
30-
1. Compile and run
3122

32-
mvn compile install
33-
export GOOGLE_APPLICATION_CREDENTIALS=key.json
34-
mvn -q exec:java -Dexec.args="your-bucket-name"
23+
Command-line Instructions
24+
-------------------------
3525

36-
37-
To enable logging of HTTP requests and responses (highly recommended when
26+
* **Prerequisites:**
27+
* Install the latest version of [Java](http//java.com) and [Maven](http://maven.apache.org/download.html).
28+
* Set the environment variable: `export GOOGLE_APPLICATION_CREDENTIALS=your-key-filename.json`
29+
* You may need to set your `JAVA_HOME`.
30+
31+
```bash
32+
cd java-docs-samples/cloud-storage/xml-api/serviceaccount-cmdline-sample
33+
# Compile and run
34+
mvn compile install
35+
mvn -q exec:java -Dexec.args="your-bucket-name"
36+
```
37+
38+
To enable logging of HTTP requests and responses (highly recommended when
3839
developing), please take a look at logging.properties.
3940

40-
Set Up a Project in Eclipse
41-
---------------------------
41+
42+
Eclipse Instructions
43+
--------------------
4244

4345
* **Prerequisites:**
4446
* Install [Eclipse](http://www.eclipse.org/downloads/), the [Maven plugin](http://eclipse.org/m2e/), and optionally the [GitHub plugin](http://eclipse.github.com/).
45-
* [Create](https://cloud.google.com/storage/docs/cloud-console#_creatingbuckets) a Google Cloud Storage bucket
4647

4748
* Set up Eclipse Preferences
4849

@@ -52,23 +53,15 @@ Set Up a Project in Eclipse
5253
* check on "Download Artifact Sources"
5354
* check on "Download Artifact JavaDoc"
5455

55-
* Clone the `serviceaccount-cmdline-sample` to your computer
56-
57-
* You can use either a plugin with Eclipse or any other tool you normally use
58-
to work with GitHub repositories.
59-
60-
* Create a new project using `serviceaccount-cmdline-sample`
56+
* Create a new project using `cloud-storage/xml-api/serviceaccount-cmdline-sample`
6157

6258
* Create a new Java Project.
63-
* Choose the **Location** of the project to be the root directory of the sample you cloned locally.
64-
* Make sure the Eclipse package name matches the package name used in the
65-
code file `com.google.api.services.samples.storage.serviceaccount.cmdline`.
59+
* Choose the **Location** of the project to be the location of `serviceaccount-cmdline-sample`
6660
* Select the project and **Convert to Maven Project** to add Maven Dependencies.
67-
* Update the key.json file.
6861
* Click on Run > Run configurations
6962
* Navigate to your **Java Application**'s configuration section
70-
* In the **Arguments** tab, add your bucket name as a **Program argument**
71-
* In the **Environment** tab, create a variable `GOOGLE_APPLICATION_CREDENTIALS` and set it to `key.json`
63+
* In the **Arguments** tab, add the name of the bucket you created above as a **Program argument**
64+
* In the **Environment** tab, create a variable `GOOGLE_APPLICATION_CREDENTIALS` and set it to the path to your json private key file.
7265

7366
* Run
7467

0 commit comments

Comments
 (0)