Skip to content

Commit a25bcf5

Browse files
jean-philippe-martinsduskis
authored andcommitted
---
yaml --- r: 23097 b: refs/heads/autosynth-containeranalysis c: f574484 h: refs/heads/master i: 23095: 82d161f
1 parent 40dbaae commit a25bcf5

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
@@ -126,7 +126,7 @@ refs/heads/autosynth-bigquerydatatransfer: d88aa5aae5fd9d3c6d75bbab1a05162c6d4d9
126126
refs/heads/autosynth-bigquerystorage: d2c53da3b012e38c662e4df0738042435f19365f
127127
refs/heads/autosynth-bigtable: 9e5429f45cf9face9fed585d0233534993e36b58
128128
refs/heads/autosynth-bigtable-admin: 6379a2bc712f2736c83de0e009b4d26da4fa82ca
129-
refs/heads/autosynth-containeranalysis: bd8d2cecdfb56b35d41a86697eda279e34f19bcf
129+
refs/heads/autosynth-containeranalysis: f5744849a2bb093b21577730984510f657968526
130130
refs/heads/autosynth-datastore: 9acd400b484d6691a080c9152a331d88d24fefc1
131131
refs/heads/autosynth-dialogflow: 7dbc2c1ea714328ccfa4f33645045f017ff080e7
132132
refs/heads/autosynth-errorreporting: 1101a04e8be074802c35332d5fcf8297f61cae32

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