1717package com .google .cloud .storage .contrib .nio ;
1818
1919import static com .google .common .base .Preconditions .checkArgument ;
20+ import static com .google .common .base .Preconditions .checkNotNull ;
2021
2122import com .google .auto .value .AutoValue ;
2223
24+ import javax .annotation .Nullable ;
2325import java .util .Map ;
2426
2527/**
@@ -65,6 +67,25 @@ public abstract class CloudStorageConfiguration {
6567 */
6668 public abstract int maxChannelReopens ();
6769
70+ /**
71+ * Returns the project to be billed when accessing buckets. Leave empty for normal semantics,
72+ * set to bill that project (project you own) for all accesses. This is required for accessing
73+ * requester-pays buckets. This value cannot be null.
74+ */
75+ public abstract @ Nullable String userProject ();
76+
77+ /**
78+ * Returns whether userProject will be cleared for non-requester-pays buckets. That is,
79+ * if false (the default value), setting userProject causes that project to be billed
80+ * regardless of whether the bucket is requester-pays or not. If true, setting
81+ * userProject will only cause that project to be billed when the project is requester-pays.
82+ *
83+ * Setting this will cause the bucket to be accessed when the CloudStorageFileSystem object
84+ * is created.
85+ */
86+ public abstract boolean useUserProjectOnlyForRequesterPaysBuckets ();
87+
88+
6889 /**
6990 * Creates a new builder, initialized with the following settings:
7091 *
@@ -90,6 +111,9 @@ public static final class Builder {
90111 private boolean usePseudoDirectories = true ;
91112 private int blockSize = CloudStorageFileSystem .BLOCK_SIZE_DEFAULT ;
92113 private int maxChannelReopens = 0 ;
114+ private @ Nullable String userProject = null ;
115+ // This of this as "clear userProject if not RequesterPays"
116+ private boolean useUserProjectOnlyForRequesterPaysBuckets = false ;
93117
94118 /**
95119 * Changes current working directory for new filesystem. This defaults to the root directory.
@@ -99,6 +123,7 @@ public static final class Builder {
99123 * @throws IllegalArgumentException if {@code path} is not absolute.
100124 */
101125 public Builder workingDirectory (String path ) {
126+ checkNotNull (path );
102127 checkArgument (UnixPath .getPath (false , path ).isAbsolute (), "not absolute: %s" , path );
103128 workingDirectory = path ;
104129 return this ;
@@ -147,6 +172,16 @@ public Builder maxChannelReopens(int value) {
147172 return this ;
148173 }
149174
175+ public Builder userProject (String value ) {
176+ userProject = value ;
177+ return this ;
178+ }
179+
180+ public Builder autoDetectRequesterPays (boolean value ) {
181+ useUserProjectOnlyForRequesterPaysBuckets = value ;
182+ return this ;
183+ }
184+
150185 /**
151186 * Creates new instance without destroying builder.
152187 */
@@ -157,7 +192,9 @@ public CloudStorageConfiguration build() {
157192 stripPrefixSlash ,
158193 usePseudoDirectories ,
159194 blockSize ,
160- maxChannelReopens );
195+ maxChannelReopens ,
196+ userProject ,
197+ useUserProjectOnlyForRequesterPaysBuckets );
161198 }
162199
163200 Builder (CloudStorageConfiguration toModify ) {
@@ -167,6 +204,8 @@ public CloudStorageConfiguration build() {
167204 usePseudoDirectories = toModify .usePseudoDirectories ();
168205 blockSize = toModify .blockSize ();
169206 maxChannelReopens = toModify .maxChannelReopens ();
207+ userProject = toModify .userProject ();
208+ useUserProjectOnlyForRequesterPaysBuckets = toModify .useUserProjectOnlyForRequesterPaysBuckets ();
170209 }
171210
172211 Builder () {}
@@ -201,6 +240,12 @@ static private CloudStorageConfiguration fromMap(Builder builder, Map<String, ?>
201240 case "maxChannelReopens" :
202241 builder .maxChannelReopens ((Integer ) entry .getValue ());
203242 break ;
243+ case "userProject" :
244+ builder .userProject ((String ) entry .getValue ());
245+ break ;
246+ case "useUserProjectOnlyForRequesterPaysBuckets" :
247+ builder .autoDetectRequesterPays ((Boolean ) entry .getValue ());
248+ break ;
204249 default :
205250 throw new IllegalArgumentException (entry .getKey ());
206251 }
0 commit comments