Skip to content

Commit 57b949b

Browse files
committed
Checkstyle fixes for Cloud Storage CSEK sample.
Also, add license headers.
1 parent 47923d9 commit 57b949b

File tree

4 files changed

+83
-37
lines changed

4 files changed

+83
-37
lines changed

storage/json-api/pom.xml

+16-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
1+
<!--
2+
Copyright 2016 Google Inc. All Rights Reserved.
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+
<project>
417
<parent>
518
<artifactId>doc-samples</artifactId>
619
<groupId>com.google.cloud</groupId>

storage/json-api/src/main/java/CustomerSuppliedEncryptionKeysSamples.java

+33-16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2016 Google Inc. All Rights Reserved.
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+
117
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
218
import com.google.api.client.http.HttpHeaders;
319
import com.google.api.client.http.InputStreamContent;
@@ -45,18 +61,19 @@ class CustomerSuppliedEncryptionKeysSamples {
4561
* @param storage A Storage object, ready for use
4662
* @param bucketName The name of the destination bucket
4763
* @param objectName The name of the destination object
48-
* @param base64CSEKey An AES256 key, encoded as a base64 string.
49-
* @param base64CSEKeyHash The SHA-256 hash of the above key, also encoded as a base64 string.
50-
* @throws IOException if there was some error download from GCS.
64+
* @param base64CseKey An AES256 key, encoded as a base64 string.
65+
* @param base64CseKeyHash The SHA-256 hash of the above key, also encoded as a base64 string.
5166
*
5267
* @return An InputStream that contains the decrypted contents of the object.
68+
*
69+
* @throws IOException if there was some error download from GCS.
5370
*/
5471
public static InputStream downloadObject(
5572
Storage storage,
5673
String bucketName,
5774
String objectName,
58-
String base64CSEKey,
59-
String base64CSEKeyHash)
75+
String base64CseKey,
76+
String base64CseKeyHash)
6077
throws Exception {
6178
Storage.Objects.Get getObject = storage.objects().get(bucketName, objectName);
6279

@@ -66,8 +83,8 @@ public static InputStream downloadObject(
6683
// Now set the CSEK headers
6784
final HttpHeaders httpHeaders = new HttpHeaders();
6885
httpHeaders.set("x-goog-encryption-algorithm", "AES256");
69-
httpHeaders.set("x-goog-encryption-key", base64CSEKey);
70-
httpHeaders.set("x-goog-encryption-key-sha256", base64CSEKeyHash);
86+
httpHeaders.set("x-goog-encryption-key", base64CseKey);
87+
httpHeaders.set("x-goog-encryption-key-sha256", base64CseKeyHash);
7188

7289
getObject.setRequestHeaders(httpHeaders);
7390

@@ -89,17 +106,17 @@ public static InputStream downloadObject(
89106
* @param bucketName The name of the destination bucket
90107
* @param objectName The name of the destination object
91108
* @param data An InputStream containing the contents of the object to upload
92-
* @param base64CSEKey An AES256 key, encoded as a base64 string.
93-
* @param base64CSEKeyHash The SHA-256 hash of the above key, also encoded as a base64 string.
109+
* @param base64CseKey An AES256 key, encoded as a base64 string.
110+
* @param base64CseKeyHash The SHA-256 hash of the above key, also encoded as a base64 string.
94111
* @throws IOException if there was some error uploading to GCS.
95112
*/
96113
public static void uploadObject(
97114
Storage storage,
98115
String bucketName,
99116
String objectName,
100117
InputStream data,
101-
String base64CSEKey,
102-
String base64CSEKeyHash)
118+
String base64CseKey,
119+
String base64CseKeyHash)
103120
throws IOException {
104121
InputStreamContent mediaContent = new InputStreamContent("text/plain", data);
105122
Storage.Objects.Insert insertObject =
@@ -112,8 +129,8 @@ public static void uploadObject(
112129
// Now set the CSEK headers
113130
final HttpHeaders httpHeaders = new HttpHeaders();
114131
httpHeaders.set("x-goog-encryption-algorithm", "AES256");
115-
httpHeaders.set("x-goog-encryption-key", base64CSEKey);
116-
httpHeaders.set("x-goog-encryption-key-sha256", base64CSEKeyHash);
132+
httpHeaders.set("x-goog-encryption-key", base64CseKey);
133+
httpHeaders.set("x-goog-encryption-key-sha256", base64CseKeyHash);
117134

118135
insertObject.setRequestHeaders(httpHeaders);
119136

@@ -192,18 +209,18 @@ public static void main(String[] args) throws Exception {
192209
System.exit(1);
193210
}
194211
String bucketName = args[0];
195-
212+
196213
Storage storage = StorageFactory.getService();
197214
InputStream dataToUpload = new StorageUtils.ArbitrarilyLargeInputStream(10000000);
198215

199216
System.out.format("Uploading object gs://%s/%s using CSEK.\n", bucketName, OBJECT_NAME);
200217
uploadObject(storage, bucketName, OBJECT_NAME, dataToUpload, CSEK_KEY, CSEK_KEY_HASH);
201-
218+
202219
System.out.format("Downloading object gs://%s/%s using CSEK.\n", bucketName, OBJECT_NAME);
203220
InputStream objectData =
204221
downloadObject(storage, bucketName, OBJECT_NAME, CSEK_KEY, CSEK_KEY_HASH);
205222
StorageUtils.readStream(objectData);
206-
223+
207224
System.out.println("Rotating object to use a different CSEK.");
208225
rotateKey(storage, bucketName, OBJECT_NAME, CSEK_KEY, CSEK_KEY_HASH,
209226
ANOTHER_CESK_KEY, ANOTHER_CSEK_KEY_HASH);

storage/json-api/src/main/java/StorageFactory.java

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2016 Google Inc. All Rights Reserved.
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+
117
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
218
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
319
import com.google.api.client.http.HttpTransport;
@@ -10,22 +26,6 @@
1026
import java.security.GeneralSecurityException;
1127
import java.util.Collection;
1228

13-
/*
14-
* Copyright (c) 2016 Google Inc.
15-
*
16-
* Licensed under the Apache License, Version 2.0 (the "License"); you may
17-
* not use this file except in compliance with the License. You may obtain a
18-
* copy of the License at
19-
*
20-
* http://www.apache.org/licenses/LICENSE-2.0
21-
*
22-
* Unless required by applicable law or agreed to in writing, software
23-
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
24-
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
25-
* License for the specific language governing permissions and limitations under
26-
* the License.
27-
*/
28-
2929
/**
3030
* This class manages the details of creating a Storage service, including auth.
3131
*/

storage/json-api/src/main/java/StorageUtils.java

+18-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
1+
/*
2+
* Copyright 2016 Google Inc. All Rights Reserved.
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+
117
import java.io.IOException;
218
import java.io.InputStream;
319

420
public class StorageUtils {
5-
21+
622
/**
723
* Reads the contents of an InputStream and does nothing with it.
824
*/
925
public static void readStream(InputStream is) throws IOException {
10-
byte inputBuffer[] = new byte[256];
26+
byte[] inputBuffer = new byte[256];
1127
while (is.read(inputBuffer) != -1) {}
1228
// The caller is responsible for closing this InputStream.
1329
is.close();

0 commit comments

Comments
 (0)