/
StorageOptions.java
186 lines (158 loc) · 5.89 KB
/
StorageOptions.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*
* Copyright 2015 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.storage;
import com.google.api.core.BetaApi;
import com.google.api.core.InternalApi;
import com.google.cloud.NoCredentials;
import com.google.cloud.ServiceDefaults;
import com.google.cloud.ServiceOptions;
import com.google.cloud.http.HttpTransportOptions;
import com.google.cloud.storage.HttpStorageOptions.HttpStorageDefaults;
import com.google.cloud.storage.HttpStorageOptions.HttpStorageFactory;
import com.google.cloud.storage.HttpStorageOptions.HttpStorageRpcFactory;
import com.google.cloud.storage.TransportCompatibility.Transport;
import com.google.cloud.storage.spi.StorageRpcFactory;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public abstract class StorageOptions extends ServiceOptions<Storage, StorageOptions> {
private static final long serialVersionUID = -7295846567928013233L;
private static final String VERSION;
static {
String tmp = "unresolved";
final Properties props = new Properties();
try {
String resourcePath =
String.format(
"/META-INF/maven/%s/%s/pom.properties", "com.google.cloud", "google-cloud-storage");
InputStream resourceAsStream = StorageOptions.class.getResourceAsStream(resourcePath);
if (resourceAsStream == null) {
// some classloaders don't like a leading slash
resourceAsStream = StorageOptions.class.getResourceAsStream(resourcePath.substring(1));
}
if (resourceAsStream != null) {
props.load(resourceAsStream);
resourceAsStream.close();
tmp = props.getProperty("version", "unknown-version");
}
} catch (IOException ignore) {
// ignored
}
VERSION = tmp;
}
/** @deprecated Use {@link HttpStorageFactory} */
@Deprecated
public static class DefaultStorageFactory extends HttpStorageFactory {
/** @deprecated Use {@link HttpStorageDefaults#getDefaultServiceFactory()} */
@Deprecated
public DefaultStorageFactory() {
super();
}
}
/** @deprecated Use {@link HttpStorageRpcFactory} */
@Deprecated
public static class DefaultStorageRpcFactory extends HttpStorageRpcFactory {
/** @deprecated Use {@link HttpStorageDefaults#getDefaultRpcFactory()} */
@Deprecated
public DefaultStorageRpcFactory() {
super();
}
}
public abstract static class Builder
extends ServiceOptions.Builder<Storage, StorageOptions, Builder> {
Builder() {}
Builder(StorageOptions options) {
super(options);
}
public abstract Builder setStorageRetryStrategy(StorageRetryStrategy storageRetryStrategy);
@Override
public abstract StorageOptions build();
}
StorageOptions(Builder builder, StorageDefaults serviceDefaults) {
super(StorageFactory.class, StorageRpcFactory.class, builder, serviceDefaults);
}
abstract static class StorageDefaults implements ServiceDefaults<Storage, StorageOptions> {}
/** @deprecated Use {@link HttpStorageDefaults#getDefaultTransportOptions()} */
@Deprecated
public static HttpTransportOptions getDefaultHttpTransportOptions() {
return HttpStorageOptions.defaults().getDefaultTransportOptions();
}
// Project ID is only required for creating buckets, so we don't require it for creating the
// service.
@Override
protected boolean projectIdRequired() {
return false;
}
@Override
public String getLibraryVersion() {
return VERSION;
}
/* This can break at any time, the value produce is intended to be informative not authoritative */
@InternalApi
public static String version() {
return VERSION;
}
@SuppressWarnings("unchecked")
@Override
public abstract StorageOptions.Builder toBuilder();
@Override
public abstract int hashCode();
@Override
public abstract boolean equals(Object obj);
/**
* Returns a default {@code StorageOptions} instance. The default instance will use JSON over HTTP
* for its transport.
*/
@TransportCompatibility(Transport.HTTP)
public static StorageOptions getDefaultInstance() {
return HttpStorageOptions.newBuilder().build();
}
/**
* Returns a unauthenticated {@code StorageOptions} instance. The returned instance will use JSON
* over HTTP for its transport.
*/
@TransportCompatibility(Transport.HTTP)
public static StorageOptions getUnauthenticatedInstance() {
return HttpStorageOptions.newBuilder().setCredentials(NoCredentials.getInstance()).build();
}
/** The returned instance will use JSON over HTTP for its transport. */
@TransportCompatibility(Transport.HTTP)
public static StorageOptions.Builder newBuilder() {
return http();
}
/**
* Builder factory method which will create a JSON over HTTP specific instance of storage options.
*
* @since 2.14.0 This new api is in preview and is subject to breaking changes.
*/
@BetaApi
@TransportCompatibility(Transport.HTTP)
public static HttpStorageOptions.Builder http() {
return HttpStorageOptions.newBuilder();
}
/**
* Builder factory method which will create a gRPC specific instance of storage options.
*
* <p>Google Cloud Storage is in Private Preview for a gRPC centric transport.
*
* @since 2.14.0 This new api is in preview and is subject to breaking changes.
*/
@BetaApi
@TransportCompatibility(Transport.GRPC)
public static GrpcStorageOptions.Builder grpc() {
return GrpcStorageOptions.newBuilder();
}
}