Skip to content

Commit 6935727

Browse files
committed
storage work in progress
1 parent 726f491 commit 6935727

10 files changed

Lines changed: 480 additions & 154 deletions

File tree

src/main/java/com/google/gcloud/storage/Acl.java

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,22 @@
1616

1717
package com.google.gcloud.storage;
1818

19-
public interface Acl {
19+
public final class Acl {
20+
21+
private final String domain;
22+
private final Entity entity;
23+
private final String entityId;
24+
25+
String email();
26+
27+
String etag();
28+
29+
String generation();
30+
31+
32+
ProjectTeam projectTeam();
33+
34+
String role();
2035

2136
class ProjectTeam {
2237
// ProjectNumber: The project number.
@@ -26,18 +41,29 @@ class ProjectTeam {
2641
//Team string `json:"team,omitempty"`
2742
}
2843

29-
enum Entity {
30-
USER_ID("user-userId"),
31-
USER_EMAIL("user-emailAddress"),
32-
GROUP_ID("group-groupId"),
33-
GROUP_EMAIL("group-emailAddress"),
34-
ALL_USERS("allUsers"),
35-
ALL_AUTHENTICATED_USERS("allAuthenticatedUsers");
44+
public static abstract class Entity {
45+
46+
private final Type type;
3647

37-
private final String value;
48+
public static final Entity ALL_USERS = new Entity(Type.ALL_USERS);
49+
50+
public enum Type {
51+
USER_ID("user-userId"),
52+
USER_EMAIL("user-emailAddress"),
53+
GROUP_ID("group-groupId"),
54+
GROUP_EMAIL("group-emailAddress"),
55+
ALL_USERS("allUsers"),
56+
ALL_AUTHENTICATED_USERS("allAuthenticatedUsers");
57+
58+
private final String value;
59+
60+
Type(String value) {
61+
this.value = value;
62+
}
63+
}
3864

39-
Entity(String value) {
40-
this.value = value;
65+
Entity(EntityType type) {
66+
this.type = type;
4167
}
4268
}
4369

src/main/java/com/google/gcloud/storage/Bucket.java

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,47 +16,9 @@
1616

1717
package com.google.gcloud.storage;
1818

19-
import java.util.Iterator;
20-
2119
public interface Bucket {
2220

23-
String id();
24-
25-
String name();
26-
27-
Cors cors();
28-
29-
Acl acl();
30-
31-
Acl defaultObjectAcl();
32-
33-
void updateCors(Cors cors);
34-
35-
void updateAcl(Acl acl);
36-
37-
void updateDefaultObjectAcl();
38-
39-
void delete(String... objectName);
40-
41-
void compose(Iterable<String> sourceObjectNames, String destObjectName);
42-
43-
void copy(String sourceObjectName, StorageObject.Key destObjectKey);
44-
45-
46-
// TODO (ozarov): consider replace with Object that has a reference to bucket and name
47-
// that object can return its own meta-data, update its own meta-data, replace its content
48-
// via a stream or byteBuffer, read its content (via stream or ByteBuffer),...
49-
//void copy(String source, String bucket, String dest);
50-
// Also consider read with an offset (and limit).
51-
52-
// returns null if not exists
53-
StorageObject get(String objectName);
54-
55-
Iterator<StorageObject> get(String... objectName);
56-
57-
InputChannel getInputChannel(String ObjectName);
5821

59-
OutputChannel getOutputChannel(String ObjectName);
22+
BucketInfo info();
6023

61-
// TODO: add listing
6224
}

src/main/java/com/google/gcloud/storage/BucketImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/* * Copyright 2015 Google Inc. All Rights Reserved. * * 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.gcloud.storage;import com.google.gcloud.storage.StorageObject.Key;import java.util.Iterator;public class BucketImpl implements Bucket { private final StorageServiceImpl storageService; private final com.google.api.services.storage.model.Bucket model; BucketImpl(StorageServiceImpl storageService, com.google.api.services.storage.model.Bucket model) { this.storageService = storageService; this.model = model; } @Override public String id() { return null; } @Override public String name() { return null; } @Override public Cors cors() { return null; } @Override public Acl acl() { return null; } @Override public Acl defaultObjectAcl() { return null; } @Override public void updateCors(Cors cors) { } @Override public void updateAcl(Acl acl) { } @Override public void updateDefaultObjectAcl() { } @Override public void delete(String... objectName) { } @Override public void compose(Iterable<String> sourceObjectNames, String destObjectName) { } @Override public void copy(String sourceObjectName, Key destObjectKey) { } @Override public StorageObject get(String objectName) { return null; } @Override public Iterator<StorageObject> get(String... objectName) { return null; } @Override public InputChannel getInputChannel(String ObjectName) { return null; } @Override public OutputChannel getOutputChannel(String ObjectName) { return null; }}
1+
/* * Copyright 2015 Google Inc. All Rights Reserved. * * 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.gcloud.storage;import com.google.gcloud.storage.StorageObject.Key;import java.util.Iterator;public class BucketImpl implements Bucket { private final StorageServiceImpl storageService; private final com.google.api.services.storage.model.Bucket model; BucketImpl(StorageServiceImpl storageService, com.google.api.services.storage.model.Bucket model) { this.storageService = storageService; this.model = model; } @Override public String id() { return null; } @Override public String name() { return null; } @Override public Cors cors() { return null; } @Override public Acl acl() { return null; } @Override public Acl defaultObjectAcl() { return null; } @Override public void updateCors(Cors cors) { } @Override public void updateAcl(Acl acl) { } @Override public void updateDefaultObjectAcl() { } @Override public void delete(String... objectName) { } @Override public void compose(Iterable<String> sourceObjectNames, String destObjectName) { } @Override public void copy(String sourceObjectName, Key destObjectKey) { } @Override public StorageObject get(String objectName) { return null; } @Override public Iterator<StorageObject> get(String... objectName) { return null; } @Override public ObjectReadChannel getInputChannel(String ObjectName) { return null; } @Override public ObjectWriteChannel getOutputChannel(String ObjectName) { return null; }}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
* Copyright 2015 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+
17+
package com.google.gcloud.storage;
18+
19+
public final class BucketInfo {
20+
21+
private final String id;
22+
private final String name;
23+
private final long createTime;
24+
private final long metageneration;
25+
private final Cors cors;
26+
private final Acl acl;
27+
private final Acl defaultAcl;
28+
29+
public enum StorageClass {
30+
DURABLE_REDUCED_AVAILABILITY,
31+
STANDARD
32+
}
33+
34+
public final static class Builder {
35+
36+
private final String id;
37+
private final String name;
38+
private final long createTime;
39+
private final long metageneration;
40+
private Cors cors;
41+
private Acl acl;
42+
private Acl defaultAcl;
43+
44+
Builder(String id, String name, long createTime, long metageneration) {
45+
this.id = id;
46+
this.name = name;
47+
this.createTime = createTime;
48+
this.metageneration = metageneration;
49+
}
50+
51+
public Builder cors(Cors cors) {
52+
this.cors = cors;
53+
return this;
54+
}
55+
56+
public Builder acl(Acl acl) {
57+
this.acl = acl;
58+
return this;
59+
}
60+
61+
public Builder defaultAcl(Acl defaultAcl) {
62+
this.defaultAcl = defaultAcl;
63+
return this;
64+
}
65+
66+
public BucketInfo build() {
67+
return new BucketInfo(this);
68+
}
69+
}
70+
71+
private BucketInfo(Builder builder) {
72+
id = builder.id;
73+
name = builder.name;
74+
createTime = builder.createTime;
75+
metageneration = builder.metageneration;
76+
cors = builder.cors;
77+
acl = builder.acl;
78+
defaultAcl = builder.defaultAcl;
79+
}
80+
81+
public String id() {
82+
return id;
83+
}
84+
85+
public String name() {
86+
return name;
87+
}
88+
89+
public Cors cors() {
90+
return cors;
91+
}
92+
93+
public Acl acl() {
94+
return acl;
95+
}
96+
97+
public Acl defaultObjectAcl() {
98+
return defaultAcl;
99+
}
100+
101+
public Builder toBuilder() {
102+
return builder(id, name, createTime, metageneration).cors(cors).acl(acl).defaultAcl(defaultAcl);
103+
}
104+
105+
public static Builder builder(String id, String name, long createTime, long metageneration) {
106+
return new Builder(id, name, createTime, metageneration);
107+
}
108+
}

src/main/java/com/google/gcloud/storage/Cors.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import java.net.URISyntaxException;
2323
import java.util.List;
2424

25-
public class Cors {
25+
public final class Cors {
2626

2727
private final Integer maxAgeSeconds;
2828
private final ImmutableList<Method> methods;
@@ -73,16 +73,31 @@ public Builder maxAgeSeconds(Integer maxAgeSeconds) {
7373
return this;
7474
}
7575

76+
public Builder methods(List<Method> methods) {
77+
this.methods = ImmutableList.copyOf(methods);
78+
return this;
79+
}
80+
7681
public Builder methods(Method... methods) {
7782
this.methods = ImmutableList.copyOf(methods);
7883
return this;
7984
}
8085

86+
public Builder origins(List<Origin> origins) {
87+
this.origins = ImmutableList.copyOf(origins);
88+
return this;
89+
}
90+
8191
public Builder origins(Origin... origins) {
8292
this.origins = ImmutableList.copyOf(origins);
8393
return this;
8494
}
8595

96+
public Builder responseHeaders(List<String> headers) {
97+
this.responseHeaders = ImmutableList.copyOf(headers);
98+
return this;
99+
}
100+
86101
public Builder responseHeaders(String... responseHeaders) {
87102
this.responseHeaders = ImmutableList.copyOf(responseHeaders);
88103
return this;
@@ -116,6 +131,14 @@ public List<String> responseHeaders() {
116131
return responseHeaders;
117132
}
118133

134+
public Builder toBuilder() {
135+
return builder()
136+
.maxAgeSeconds(maxAgeSeconds)
137+
.methods(methods)
138+
.origins(origins)
139+
.responseHeaders(responseHeaders);
140+
}
141+
119142
public static Builder builder() {
120143
return new Builder();
121144
}

0 commit comments

Comments
 (0)