Skip to content

Commit 1449232

Browse files
jean-philippe-martinsduskis
authored andcommitted
---
yaml --- r: 19703 b: refs/heads/autosynth-firestore c: f574484 h: refs/heads/master i: 19701: 2174458 19699: e2c14d8 19695: 645fec6
1 parent d4eddaf commit 1449232

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
@@ -131,7 +131,7 @@ refs/heads/autosynth-containeranalysis: 0f377286f60df2b6fd37c183bf170c68dc014cfb
131131
refs/heads/autosynth-datastore: 9acd400b484d6691a080c9152a331d88d24fefc1
132132
refs/heads/autosynth-dialogflow: 7dbc2c1ea714328ccfa4f33645045f017ff080e7
133133
refs/heads/autosynth-errorreporting: 1101a04e8be074802c35332d5fcf8297f61cae32
134-
refs/heads/autosynth-firestore: bd8d2cecdfb56b35d41a86697eda279e34f19bcf
134+
refs/heads/autosynth-firestore: f5744849a2bb093b21577730984510f657968526
135135
refs/heads/autosynth-iot: f16fc4ba85bbb37eacecb64a2a7336f685813f6c
136136
refs/heads/autosynth-kms: 4fff8f3cf6c830f7706ac4ef272f036bb87fbaf8
137137
refs/heads/autosynth-language: 6262e2eb76944f01972c887b3e684aaf65ec999a

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