Skip to content

Commit 8952bfd

Browse files
jean-philippe-martinsduskis
authored andcommitted
---
yaml --- r: 25213 b: refs/heads/autosynth-tasks c: f574484 h: refs/heads/master i: 25211: e470198
1 parent 52f287a commit 8952bfd

5 files changed

Lines changed: 58 additions & 4 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ refs/heads/autosynth-redis: 6bedce4d7c7c6ca6a22e83ad1780e08fdc565a9e
139139
refs/heads/autosynth-scheduler: 57f9fdb1e7de30c85f4ec7198931a07f50603e55
140140
refs/heads/autosynth-spanner: cbd30ccc550e9d0419ce4e5e6cfef4951ea170b1
141141
refs/heads/autosynth-speech: 64692f6db11364f663921be02c08072b966b6e7b
142-
refs/heads/autosynth-tasks: bd8d2cecdfb56b35d41a86697eda279e34f19bcf
142+
refs/heads/autosynth-tasks: f5744849a2bb093b21577730984510f657968526
143143
refs/heads/autosynth-texttospeech: 2dcc5dc22be0f456caa1b6a8a4bcdace2641239c
144144
refs/heads/autosynth-trace: 8804c46bfe147702ee9c95669f17f42d3790cf23
145145
refs/heads/autosynth-websecurityscanner: a3c778316a0f78f7ad4bac3dc3721da5ca832d3c

branches/autosynth-tasks/google-cloud-clients/google-cloud-contrib/google-cloud-nio-examples/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ application that uses Java NIO without the need to recompile.
66

77
Note that whenever possible, you instead want to recompile the app and use the normal
88
dependency mechanism to add a dependency to google-cloud-nio. You can see examples of
9-
this in the [google-cloud-examples](../../../google-cloud-examples) project.
9+
this in the [google-cloud-examples](../../../google-cloud-examples) project,
10+
[under nio](../../../google-cloud-examples/src/main/java/com/google/cloud/examples/nio).
1011

1112
To run this example:
1213

branches/autosynth-tasks/google-cloud-clients/google-cloud-contrib/google-cloud-nio/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ Authentication
5757
--------------
5858

5959
See the [Authentication](https://github.com/googleapis/google-cloud-java#authentication)
60-
section in the base directory's README.
60+
section in the base directory's README. This shows how to construct the `StorageOptions` object,
61+
which you can then pass to `CloudStorageFileSystem.forBucket`.
6162

6263
About Google Cloud Storage
6364
--------------------------

branches/autosynth-tasks/google-cloud-clients/google-cloud-contrib/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystemProvider.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,12 @@ protected Path computeNext() {
140140
}
141141
}
142142

143-
/** Sets options that are only used by the constructor. */
143+
/**
144+
* Sets options that are only used by the constructor.
145+
*
146+
* <p>Instead of calling this, when possible use CloudStorageFileSystem.forBucket and pass
147+
* StorageOptions as an argument.
148+
*/
144149
@VisibleForTesting
145150
public static void setStorageOptions(@Nullable StorageOptions newStorageOptions) {
146151
futureStorageOptions = newStorageOptions;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2019 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.cloud.examples.nio.snippets;
18+
19+
import com.google.auth.oauth2.ServiceAccountCredentials;
20+
import com.google.cloud.storage.StorageOptions;
21+
import com.google.cloud.storage.contrib.nio.CloudStorageConfiguration;
22+
import com.google.cloud.storage.contrib.nio.CloudStorageFileSystem;
23+
import java.io.FileInputStream;
24+
import java.io.IOException;
25+
26+
/**
27+
* A snippet for Google Cloud Storage NIO that shows how to create a {@link CloudStorageFileSystem}
28+
* using explicitly-provided credentials instead of the default ones.
29+
*/
30+
public class UseExplicitCredentials {
31+
32+
public static void main(String... args) throws IOException {
33+
// Create a file system for the bucket using the service account credentials
34+
// saved in the file below.
35+
String myCredentials = "/path/to/my/key.json";
36+
CloudStorageFileSystem fs =
37+
CloudStorageFileSystem.forBucket(
38+
"mybucket",
39+
CloudStorageConfiguration.DEFAULT,
40+
StorageOptions.newBuilder()
41+
.setCredentials(
42+
ServiceAccountCredentials.fromStream(new FileInputStream(myCredentials)))
43+
.build());
44+
// Can now read and write to the bucket using fs
45+
// (see e.g. ReadAllLines for an example).
46+
}
47+
}

0 commit comments

Comments
 (0)