Skip to content

Commit ec0e857

Browse files
jean-philippe-martinsduskis
authored andcommitted
---
yaml --- r: 23979 b: refs/heads/autosynth-kms c: f574484 h: refs/heads/master i: 23977: 0475ca8 23975: cab7b05
1 parent 11dffc0 commit ec0e857

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
@@ -132,7 +132,7 @@ refs/heads/autosynth-dialogflow: cb1ceeb3ec1a132d3096fc88d44b930a52130e18
132132
refs/heads/autosynth-errorreporting: 3f176c20b55dfaaa8fc32f28d82b31784b93e636
133133
refs/heads/autosynth-firestore: d48d82caace227856b6cd85ac30ee474528733ea
134134
refs/heads/autosynth-iot: 4025d1804241e74d54950a324dc4f667aeaad4b3
135-
refs/heads/autosynth-kms: bd8d2cecdfb56b35d41a86697eda279e34f19bcf
135+
refs/heads/autosynth-kms: f5744849a2bb093b21577730984510f657968526
136136
refs/heads/autosynth-language: c3d990dd34d81e7e935041e7147fb9dd27f8a557
137137
refs/heads/autosynth-os-login: 092fdbed6d5317948f92b708e9f50dedd89fc666
138138
refs/heads/autosynth-redis: 9e1fe503973c7b4a9ba26afb1fcddc2a57ba795a

branches/autosynth-kms/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-kms/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-kms/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)