Skip to content

Commit 31a6d9e

Browse files
aozarovmziccard
authored andcommitted
---
yaml --- r: 6141 b: refs/heads/tswast-patch-1 c: af17114 h: refs/heads/master i: 6139: fed8313
1 parent 4898635 commit 31a6d9e

10 files changed

Lines changed: 546 additions & 172 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ refs/tags/v0.18.0: 9d193c4c4b9d1c6f21515dd8e50836b9194ec9bb
5757
refs/tags/v0.19.0: e67b56e4d8dad5f9a7b38c9b2107c23c828f2ed5
5858
refs/tags/v0.20.0: 839f7fb7156535146aa1cb2c5aadd8d375d854e8
5959
refs/tags/v0.20.1: 370471f437f1f4f68a11e068df5cd6bf39edb1fa
60-
refs/heads/tswast-patch-1: d63892676203619534d3d81f712943d8395701a1
60+
refs/heads/tswast-patch-1: af171147208aeade287e2cf81794f922bf147b1a
6161
refs/heads/pubsub-streaming-pull: 19262b752ee874eb2ca3b950eb2aef44d5a5267b

branches/tswast-patch-1/gcloud-java-core/src/main/java/com/google/gcloud/AuthCredentials.java

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import com.google.auth.oauth2.GoogleCredentials;
3131

3232
import java.io.IOException;
33-
import java.io.InputStream;
3433
import java.io.ObjectInputStream;
3534
import java.io.ObjectStreamException;
3635
import java.io.Serializable;
@@ -134,7 +133,7 @@ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundE
134133
try {
135134
computeCredential = getComputeCredential();
136135
} catch (GeneralSecurityException e) {
137-
throw new IOException(e);
136+
throw new IOException(e);
138137
}
139138
}
140139

@@ -157,7 +156,7 @@ private static class ApplicationDefaultAuthCredentials extends AuthCredentials {
157156

158157
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
159158
in.defaultReadObject();
160-
googleCredentials = GoogleCredentials.getApplicationDefault();
159+
googleCredentials = GoogleCredentials.getApplicationDefault();
161160
}
162161

163162
@Override
@@ -184,8 +183,8 @@ public static AuthCredentials createForComputeEngine()
184183
*
185184
* <p>Returns the Application Default Credentials which are credentials that identify and
186185
* authorize the whole application. This is the built-in service account if running on
187-
* Google Compute Engine or the credentials file can be read from the path in the environment
188-
* variable GOOGLE_APPLICATION_CREDENTIALS.
186+
* Google Compute Engine or the credentials file from the path in the environment variable
187+
* GOOGLE_APPLICATION_CREDENTIALS.
189188
* </p>
190189
*
191190
* @return the credentials instance.
@@ -195,41 +194,10 @@ public static AuthCredentials createApplicationDefaults() throws IOException {
195194
return new ApplicationDefaultAuthCredentials();
196195
}
197196

198-
/**
199-
* Creates Service Account Credentials given an account id and a private key.
200-
*
201-
* <p>For details on how to obtain Service Account Credentials see
202-
* <a href="https://cloud.google.com/storage/docs/authentication?hl=en#service_accounts">Service
203-
* Account Authentication</a>.
204-
* </p>
205-
*
206-
* @param account id of the Service Account
207-
* @param privateKey private key associated to the account
208-
* @return the credentials instance.
209-
*/
210197
public static ServiceAccountAuthCredentials createFor(String account, PrivateKey privateKey) {
211198
return new ServiceAccountAuthCredentials(account, privateKey);
212199
}
213200

214-
/**
215-
* Creates Service Account Credentials given a stream for credentials in JSON format.
216-
*
217-
* <p>For details on how to obtain Service Account Credentials in JSON format see
218-
* <a href="https://cloud.google.com/storage/docs/authentication?hl=en#service_accounts">Service
219-
* Account Authentication</a>.
220-
* </p>
221-
*
222-
* @param jsonCredentialStream stream for Service Account Credentials in JSON format
223-
* @return the credentials instance.
224-
* @throws IOException if the credentials cannot be created from the stream.
225-
*/
226-
public static ServiceAccountAuthCredentials createForJson(InputStream jsonCredentialStream)
227-
throws IOException {
228-
GoogleCredential tempCredentials = GoogleCredential.fromStream(jsonCredentialStream);
229-
return new ServiceAccountAuthCredentials(tempCredentials.getServiceAccountId(),
230-
tempCredentials.getServiceAccountPrivateKey());
231-
}
232-
233201
public static AuthCredentials noCredentials() {
234202
return ServiceAccountAuthCredentials.NO_CREDENTIALS;
235203
}

branches/tswast-patch-1/gcloud-java-storage/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ private Storage.Objects.Delete deleteRequest(StorageObject blob, Map<Option, ?>
282282
.setIfMetagenerationMatch(IF_METAGENERATION_MATCH.getLong(options))
283283
.setIfMetagenerationNotMatch(IF_METAGENERATION_NOT_MATCH.getLong(options))
284284
.setIfGenerationMatch(IF_GENERATION_MATCH.getLong(options))
285+
.setIfGenerationMatch(100L)
285286
.setIfGenerationNotMatch(IF_GENERATION_NOT_MATCH.getLong(options));
286287
}
287288

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
/*
2+
*
3+
* * Copyright 2015 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version
4+
* 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may
5+
* obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless
6+
* required by applicable law or agreed to in writing, software * distributed under the License is
7+
* distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
8+
* or implied. * See the License for the specific language governing permissions and * limitations
9+
* under the License.
10+
*/
11+
12+
package com.google.gcloud.storage;
13+
14+
import static com.google.common.base.Preconditions.checkArgument;
15+
import static com.google.common.base.Preconditions.checkNotNull;
16+
import static com.google.gcloud.storage.Blob.BlobSourceOption.convert;
17+
18+
import com.google.common.collect.ImmutableList;
19+
import com.google.common.collect.Iterables;
20+
import com.google.gcloud.spi.StorageRpc;
21+
import com.google.gcloud.storage.Storage.BlobTargetOption;
22+
import com.google.gcloud.storage.Storage.CopyRequest;
23+
import com.google.gcloud.storage.Storage.SignUrlOption;
24+
25+
import java.net.URL;
26+
import java.util.Objects;
27+
28+
29+
/**
30+
* A Google cloud storage object.
31+
*/
32+
public final class Blob {
33+
34+
private final Storage storage;
35+
private BlobInfo info;
36+
37+
public static class BlobSourceOption extends Option {
38+
39+
private static final long serialVersionUID = 214616862061934846L;
40+
41+
private BlobSourceOption(StorageRpc.Option rpcOption) {
42+
super(rpcOption, null);
43+
}
44+
45+
private Storage.BlobSourceOption convert(BlobInfo blobInfo) {
46+
switch (rpcOption()) {
47+
case IF_GENERATION_MATCH:
48+
return Storage.BlobSourceOption.generationMatch(blobInfo.generation());
49+
case IF_GENERATION_NOT_MATCH:
50+
return Storage.BlobSourceOption.generationNotMatch(blobInfo.generation());
51+
case IF_METAGENERATION_MATCH:
52+
return Storage.BlobSourceOption.metagenerationMatch(blobInfo.metageneration());
53+
case IF_METAGENERATION_NOT_MATCH:
54+
return Storage.BlobSourceOption.metagenerationNotMatch(blobInfo.metageneration());
55+
default:
56+
throw new AssertionError("Unexpected enum value");
57+
}
58+
}
59+
60+
public static BlobSourceOption generationMatch() {
61+
return new BlobSourceOption(StorageRpc.Option.IF_GENERATION_MATCH);
62+
}
63+
64+
public static BlobSourceOption generationNotMatch() {
65+
return new BlobSourceOption(StorageRpc.Option.IF_GENERATION_NOT_MATCH);
66+
}
67+
68+
public static BlobSourceOption metagenerationMatch() {
69+
return new BlobSourceOption(StorageRpc.Option.IF_METAGENERATION_MATCH);
70+
}
71+
72+
public static BlobSourceOption metagenerationNotMatch() {
73+
return new BlobSourceOption(StorageRpc.Option.IF_METAGENERATION_NOT_MATCH);
74+
}
75+
76+
static Storage.BlobSourceOption[] convert(BlobInfo blobInfo, BlobSourceOption... options) {
77+
Storage.BlobSourceOption[] convertedOptions = new Storage.BlobSourceOption[options.length];
78+
int index = 0;
79+
for (BlobSourceOption option : options) {
80+
convertedOptions[index++] = option.convert(blobInfo);
81+
}
82+
return convertedOptions;
83+
}
84+
}
85+
86+
public Blob(Storage storage, BlobInfo info) {
87+
this.storage = checkNotNull(storage);
88+
this.info = checkNotNull(info);
89+
}
90+
91+
public BlobInfo info() {
92+
return info;
93+
}
94+
95+
/**
96+
* Returns true if this blob exists.
97+
*
98+
* @throws StorageException upon failure
99+
*/
100+
public boolean exists() {
101+
return storage.get(info.bucket(), info.name()) != null;
102+
}
103+
104+
/**
105+
* Returns the blob's content.
106+
*
107+
* @throws StorageException upon failure
108+
*/
109+
public byte[] content(Storage.BlobSourceOption... options) {
110+
return storage.readAllBytes(info.bucket(), info.name(), options);
111+
}
112+
113+
/**
114+
* Updates the blob's information. Bucket or blob's name cannot be changed by this method. If you
115+
* want to rename the blob or move it to a different bucket use the {@link #copyTo} and
116+
* {@link #delete} operations.
117+
*
118+
* @throws StorageException upon failure
119+
*/
120+
public void update(BlobInfo blobInfo, BlobTargetOption... options) {
121+
checkArgument(Objects.equals(blobInfo.bucket(), info.bucket()), "Bucket name must match");
122+
checkArgument(Objects.equals(blobInfo.name(), info.name()), "Blob name must match");
123+
info = storage.update(blobInfo, options);
124+
}
125+
126+
/**
127+
* Deletes this blob.
128+
*
129+
* @return true if bucket was deleted
130+
* @throws StorageException upon failure
131+
*/
132+
public boolean delete(BlobSourceOption... options) {
133+
return storage.delete(info.bucket(), info.name(), convert(info, options));
134+
}
135+
136+
/**
137+
* Send a copy request.
138+
*
139+
* @return the copied blob.
140+
* @throws StorageException upon failure
141+
*/
142+
public Blob copyTo(BlobInfo target, BlobSourceOption... options) {
143+
return copyTo(target, ImmutableList.copyOf(options), ImmutableList.<BlobTargetOption>of());
144+
}
145+
146+
/**
147+
* Send a copy request.
148+
*
149+
* @return the copied blob.
150+
* @throws StorageException upon failure
151+
*/
152+
public Blob copyTo(BlobInfo target, Iterable<BlobSourceOption> sourceOptions,
153+
Iterable<BlobTargetOption> targetOptions) {
154+
CopyRequest copyRequest =
155+
CopyRequest.builder().source(info.bucket(), info.name())
156+
.sourceOptions(convert(info, Iterables.toArray(sourceOptions, BlobSourceOption.class)))
157+
.target(target).targetOptions(targetOptions).build();
158+
return new Blob(storage, storage.copy(copyRequest));
159+
}
160+
161+
/**
162+
* Returns a channel for reading this blob's content.
163+
*
164+
* @throws StorageException upon failure
165+
*/
166+
public BlobReadChannel reader(BlobSourceOption... options) {
167+
return storage.reader(info.bucket(), info.name(), convert(info, options));
168+
}
169+
170+
/**
171+
* Returns a channel for writing to this blob.
172+
*
173+
* @throws StorageException upon failure
174+
*/
175+
public BlobWriteChannel writer(BlobTargetOption... options) {
176+
return storage.writer(info, options);
177+
}
178+
179+
/**
180+
* Generates a signed URL for this blob. If you want to allow access to for a fixed amount of time
181+
* for this blob, you can use this method to generate a URL that is only valid within a certain
182+
* time period. This is particularly useful if you don't want publicly accessible blobs, but don't
183+
* want to require users to explicitly log in.
184+
*
185+
* @param expirationTimeInSeconds the signed URL expiration (using epoch time)
186+
* @see <a href="https://cloud.google.com/storage/docs/access-control#Signed-URLs">Signed-URLs</a>
187+
*/
188+
public URL signUrl(long expirationTimeInSeconds, SignUrlOption... options) {
189+
return storage.signUrl(info, expirationTimeInSeconds, options);
190+
}
191+
192+
public Storage storage() {
193+
return storage;
194+
}
195+
}

branches/tswast-patch-1/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobInfo.java

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
/*
2-
* Copyright 2015 Google Inc. All Rights Reserved.
32
*
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.
3+
* * Copyright 2015 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version
4+
* 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may
5+
* obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless
6+
* required by applicable law or agreed to in writing, software * distributed under the License is
7+
* distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
8+
* or implied. * See the License for the specific language governing permissions and * limitations
9+
* under the License.
1510
*/
1611

1712
package com.google.gcloud.storage;
@@ -37,30 +32,28 @@
3732
import java.util.Objects;
3833

3934
/**
40-
* A Google Storage object.
35+
* Google Storage object metadata.
4136
*
42-
* @see <a href="https://cloud.google.com/storage/docs/concepts-techniques#concepts">Concepts and Terminology</a>
37+
* @see <a href="https://cloud.google.com/storage/docs/concepts-techniques#concepts">Concepts and
38+
* Terminology</a>
4339
*/
4440
public final class BlobInfo implements Serializable {
4541

46-
private static final long serialVersionUID = 2228487739943277159L;
47-
4842
static final Function<StorageObject, BlobInfo> FROM_PB_FUNCTION =
4943
new Function<StorageObject, BlobInfo>() {
5044
@Override
5145
public BlobInfo apply(StorageObject pb) {
5246
return BlobInfo.fromPb(pb);
5347
}
5448
};
55-
5649
static final Function<BlobInfo, StorageObject> TO_PB_FUNCTION =
5750
new Function<BlobInfo, StorageObject>() {
5851
@Override
5952
public StorageObject apply(BlobInfo blobInfo) {
6053
return blobInfo.toPb();
6154
}
6255
};
63-
56+
private static final long serialVersionUID = 2228487739943277159L;
6457
private final String bucket;
6558
private final String id;
6659
private final String name;
@@ -378,29 +371,14 @@ public String toString() {
378371
.toString();
379372
}
380373

381-
public static BlobInfo of(String bucket, String name) {
382-
return builder(bucket, name).build();
383-
}
384-
385-
public static Builder builder(BucketInfo bucketInfo, String name) {
386-
return builder(bucketInfo.name(), name);
387-
}
388-
389-
public static Builder builder(String bucket, String name) {
390-
return new Builder().bucket(bucket).name(name);
391-
}
392-
393374
@Override
394375
public int hashCode() {
395376
return Objects.hash(bucket, name);
396377
}
397378

398379
@Override
399380
public boolean equals(Object obj) {
400-
if (!(obj instanceof BlobInfo)) {
401-
return false;
402-
}
403-
return Objects.equals(toPb(), ((BlobInfo) obj).toPb());
381+
return obj instanceof BlobInfo && Objects.equals(toPb(), ((BlobInfo) obj).toPb());
404382
}
405383

406384
StorageObject toPb() {
@@ -445,6 +423,18 @@ public ObjectAccessControl apply(Acl acl) {
445423
return storageObject;
446424
}
447425

426+
public static BlobInfo of(String bucket, String name) {
427+
return builder(bucket, name).build();
428+
}
429+
430+
public static Builder builder(BucketInfo bucketInfo, String name) {
431+
return builder(bucketInfo.name(), name);
432+
}
433+
434+
public static Builder builder(String bucket, String name) {
435+
return new Builder().bucket(bucket).name(name);
436+
}
437+
448438
static BlobInfo fromPb(StorageObject storageObject) {
449439
Builder builder = new Builder()
450440
.bucket(storageObject.getBucket())

0 commit comments

Comments
 (0)