From 0dee4fd7748326b30c3528bb14259cecf89949c9 Mon Sep 17 00:00:00 2001 From: hsbhathiya Date: Sun, 27 Jul 2014 03:50:09 +0530 Subject: [PATCH] JCLOUDS-458: Ad Object Access Controls live tests --- .../GoogleCloudStorageApi.java | 8 + .../domain/BucketAccessControls.java | 3 +- .../domain/ListObjectAccessControls.java | 112 ++++++ .../domain/ObjectAccessControls.java | 208 ++++++++++ .../domain/ObjectAccessControlsTemplate.java | 65 ++++ .../domain/internal/ProjectTeam.java | 26 +- .../features/ObjectAccessControlsApi.java | 365 ++++++++++++++++++ .../GoogleCloudStorageErrorHandler.java | 10 + .../handlers/ObjectAccessControlsBinder.java | 43 +++ .../BucketAccessControlsApiLiveTest.java | 112 ++++++ ...aultObjectAccessControlsApiExpectTest.java | 20 +- ...efaultObjectAccessControlsApiLiveTest.java | 117 ++++++ .../ObjectAccessControlsApiExpectTest.java | 282 ++++++++++++++ .../parse/BucketAclListTest.java | 2 +- .../parse/DefaultObjectAclGetTest.java | 2 +- .../parse/DefaultObjectAclListTest.java | 2 +- .../parse/FullBucketGetTest.java | 2 +- .../parse/ObjectAclGetTest.java | 54 +++ .../parse/ObjectAclInsertTest.java | 49 +++ .../parse/ObjectAclListTest.java | 55 +++ .../parse/ObjectAclUpdateTest.java | 44 +++ .../src/test/resources/objectacl_get.json | 15 + .../objectacl_insert_requestpayload.json | 4 + .../resources/objectacl_insert_response.json | 10 + .../src/test/resources/objectacl_list.json | 17 + .../resources/objectacl_request_payload.json | 4 + .../resources/objectacl_update_initial.json | 9 + .../resources/objectacl_update_response.json | 9 + 28 files changed, 1621 insertions(+), 28 deletions(-) create mode 100644 providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/domain/ListObjectAccessControls.java create mode 100644 providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/domain/ObjectAccessControls.java create mode 100644 providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/domain/ObjectAccessControlsTemplate.java create mode 100644 providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/features/ObjectAccessControlsApi.java create mode 100644 providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/handlers/ObjectAccessControlsBinder.java create mode 100644 providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/BucketAccessControlsApiLiveTest.java create mode 100644 providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/DefaultObjectAccessControlsApiLiveTest.java create mode 100644 providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/ObjectAccessControlsApiExpectTest.java create mode 100644 providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/parse/ObjectAclGetTest.java create mode 100644 providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/parse/ObjectAclInsertTest.java create mode 100644 providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/parse/ObjectAclListTest.java create mode 100644 providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/parse/ObjectAclUpdateTest.java create mode 100644 providers/google-cloud-storage/src/test/resources/objectacl_get.json create mode 100644 providers/google-cloud-storage/src/test/resources/objectacl_insert_requestpayload.json create mode 100644 providers/google-cloud-storage/src/test/resources/objectacl_insert_response.json create mode 100644 providers/google-cloud-storage/src/test/resources/objectacl_list.json create mode 100644 providers/google-cloud-storage/src/test/resources/objectacl_request_payload.json create mode 100644 providers/google-cloud-storage/src/test/resources/objectacl_update_initial.json create mode 100644 providers/google-cloud-storage/src/test/resources/objectacl_update_response.json diff --git a/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/GoogleCloudStorageApi.java b/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/GoogleCloudStorageApi.java index f92efbf2c1..538188074e 100644 --- a/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/GoogleCloudStorageApi.java +++ b/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/GoogleCloudStorageApi.java @@ -23,6 +23,7 @@ import javax.ws.rs.Path; import org.jclouds.googlecloudstorage.features.BucketAccessControlsApi; import org.jclouds.googlecloudstorage.features.BucketApi; import org.jclouds.googlecloudstorage.features.DefaultObjectAccessControlsApi; +import org.jclouds.googlecloudstorage.features.ObjectAccessControlsApi; import org.jclouds.rest.annotations.Delegate; /** @@ -52,4 +53,11 @@ public interface GoogleCloudStorageApi extends Closeable { @Delegate @Path("") BucketApi getBucketApi(); + + /** + * Provides access to Object Access Control features + */ + @Delegate + @Path("") + ObjectAccessControlsApi getObjectAccessControlsApi(); } diff --git a/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/domain/BucketAccessControls.java b/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/domain/BucketAccessControls.java index 76876cf1c4..e81f297d97 100644 --- a/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/domain/BucketAccessControls.java +++ b/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/domain/BucketAccessControls.java @@ -92,7 +92,8 @@ public class BucketAccessControls extends Resource { if (obj == null || getClass() != obj.getClass()) return false; BucketAccessControls that = BucketAccessControls.class.cast(obj); - return equal(this.kind, that.kind) && equal(this.bucket, that.bucket) && equal(this.entity, that.entity); + return equal(this.kind, that.kind) && equal(this.bucket, that.bucket) && equal(this.entity, that.entity) + && equal(this.id, that.id); } protected MoreObjects.ToStringHelper string() { diff --git a/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/domain/ListObjectAccessControls.java b/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/domain/ListObjectAccessControls.java new file mode 100644 index 0000000000..a33d5bccfe --- /dev/null +++ b/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/domain/ListObjectAccessControls.java @@ -0,0 +1,112 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.jclouds.googlecloudstorage.domain; + +import static com.google.common.base.MoreObjects.toStringHelper; +import static com.google.common.base.Objects.equal; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Set; + +import org.jclouds.googlecloudstorage.domain.Resource.Kind; + +import com.google.common.base.MoreObjects.ToStringHelper; +import com.google.common.base.Objects; +import com.google.common.collect.ImmutableSet; + +public class ListObjectAccessControls { + + protected final Kind kind; + protected final Set items; + + protected ListObjectAccessControls(Kind kind, Set items) { + + this.kind = checkNotNull(kind, "kind"); + this.items = checkNotNull(items, "items"); + } + + public Kind getKind() { + return kind; + } + + public Set getItems() { + return items; + } + + @Override + public int hashCode() { + return Objects.hashCode(kind, items); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; + ListObjectAccessControls that = ListObjectAccessControls.class.cast(obj); + return equal(this.kind, that.kind) && equal(this.items, that.items); + + } + + protected ToStringHelper string() { + return toStringHelper(this).omitNullValues().add("kind", kind).add("items", items); + } + + @Override + public String toString() { + return string().toString(); + } + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder().fromListObjectAccessControls(this); + } + + public static final class Builder { + + private Kind kind; + private ImmutableSet.Builder items = ImmutableSet.builder(); + + public Builder kind(Kind kind) { + this.kind = checkNotNull(kind , "kind"); + return this; + } + + public Builder addItems(ObjectAccessControls bucketAccessControls) { + this.items.add(bucketAccessControls); + return this; + } + + public Builder items(Set items) { + this.items.addAll(items); + return this; + } + + public ListObjectAccessControls build() { + return new ListObjectAccessControls(this.kind, items.build()); + } + + public Builder fromListObjectAccessControls(ListObjectAccessControls in) { + return this.kind(in.getKind()).items(in.getItems()); + } + } +} diff --git a/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/domain/ObjectAccessControls.java b/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/domain/ObjectAccessControls.java new file mode 100644 index 0000000000..f9b735e429 --- /dev/null +++ b/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/domain/ObjectAccessControls.java @@ -0,0 +1,208 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.jclouds.googlecloudstorage.domain; + +import static com.google.common.base.Objects.equal; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.net.URI; + +import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.ObjectRole; +import org.jclouds.googlecloudstorage.domain.internal.ProjectTeam; +import org.jclouds.javax.annotation.Nullable; + +import com.google.common.base.MoreObjects; +import com.google.common.base.Objects; + +/** + * Represents a Object Access Control Resource. + * + * @see + */ +public class ObjectAccessControls extends Resource { + + protected final String bucket; + protected final String entity; + protected final String object; + protected final Long generation; + protected final ObjectRole role; + protected final String email; + protected final String entityId; + protected final String domain; + protected final ProjectTeam projectTeam; + + protected ObjectAccessControls(@Nullable String id, @Nullable URI selfLink, @Nullable String etag, String bucket, + @Nullable String object, @Nullable Long generation, String entity, @Nullable String entityId, + ObjectRole role, @Nullable String email, @Nullable String domain, @Nullable ProjectTeam projectTeam) { + super(Kind.OBJECT_ACCESS_CONTROL, id, selfLink, etag); + + this.bucket = bucket; + this.entity = checkNotNull(entity, "entity"); + this.object = object; + this.generation = generation; + this.entityId = entityId; + this.role = checkNotNull(role, "role"); + this.email = email; + this.domain = domain; + this.projectTeam = projectTeam; + } + + public String getBucket() { + return bucket; + } + + public String getEntity() { + return entity; + } + + public ObjectRole getRole() { + return role; + } + + public String getEmail() { + return email; + } + + public String getObject() { + return object; + } + + public Long getGeneration() { + return generation; + } + + public String getDomain() { + return domain; + } + + public String getEntityId() { + return entityId; + } + + public ProjectTeam getProjectTeam() { + return projectTeam; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; + ObjectAccessControls that = ObjectAccessControls.class.cast(obj); + return equal(this.kind, that.kind) && equal(this.bucket, that.bucket) && equal(this.object, that.object) + && equal(this.entity, that.entity) && equal(this.id , that.id); + } + + protected MoreObjects.ToStringHelper string() { + return super.string().omitNullValues().add("bucket", bucket).add("entity", entity).add("entityId", entityId) + .add("object", object).add("generation", generation).add("role", role).add("email", email) + .add("domain", domain).add("projectTeam", projectTeam); + } + + @Override + public int hashCode() { + return Objects.hashCode(kind, bucket, object, entity); + } + + @Override + public String toString() { + return string().toString(); + } + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder().fromObjectAccessControls(this); + } + + public static final class Builder extends Resource.Builder { + + protected String object; + protected Long generation; + protected String bucket; + protected String entity; + protected String entityId; + protected ObjectRole role; + protected String email; + protected String domain; + protected ProjectTeam projectTeam; + + public Builder bucket(String bucket) { + this.bucket = bucket; + return this; + } + + public Builder object(String object) { + this.object = object; + return this; + } + + public Builder generation(Long generation) { + this.generation = generation; + return this; + } + + public Builder entity(String entity) { + this.entity = entity; + return this; + } + + public Builder entityId(String entityId) { + this.entityId = entityId; + return this; + } + + public Builder role(ObjectRole role) { + this.role = role; + return this; + } + + public Builder email(String email) { + this.email = email; + return this; + } + + public Builder domain(String domain) { + this.domain = domain; + return this; + } + + public Builder projectTeam(ProjectTeam projectTeam) { + this.projectTeam = projectTeam; + return this; + } + + public ObjectAccessControls build() { + return new ObjectAccessControls(super.id, super.selfLink, super.etag, bucket, object, generation, entity, + entityId, role, email, domain, projectTeam); + } + + public Builder fromObjectAccessControls(ObjectAccessControls in) { + return super.fromResource(in).bucket(in.getBucket()).entity(in.getEntity()).entityId(in.getEntityId()) + .role(in.getRole()).email(in.getEmail()).domain(in.getDomain()).object(in.getObject()) + .generation(in.getGeneration()).projectTeam(in.getProjectTeam()); + } + + @Override + protected Builder self() { + return this; + } + } +} diff --git a/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/domain/ObjectAccessControlsTemplate.java b/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/domain/ObjectAccessControlsTemplate.java new file mode 100644 index 0000000000..7740207a9e --- /dev/null +++ b/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/domain/ObjectAccessControlsTemplate.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.jclouds.googlecloudstorage.domain; + +import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.ObjectRole; + +/** + * Represents a Object Access Control Resource. + * + * @see + */ +public class ObjectAccessControlsTemplate { + + protected String entity; + protected ObjectRole role; + + public ObjectAccessControlsTemplate role(ObjectRole role) { + this.role = role; + return this; + } + + public ObjectAccessControlsTemplate entity(String entity) { + this.entity = entity; + return this; + } + + public String getEntity() { + return entity; + } + + public ObjectRole getRole() { + return role; + } + + public static Builder builder() { + return new Builder(); + } + + public static ObjectAccessControlsTemplate fromObjectAccessControlsTemplate( + ObjectAccessControlsTemplate objectAccessControlsTemplate) { + return Builder.fromObjectAccessControlsTemplate(objectAccessControlsTemplate); + } + + public static class Builder { + + public static ObjectAccessControlsTemplate fromObjectAccessControlsTemplate(ObjectAccessControlsTemplate in) { + return new ObjectAccessControlsTemplate().role(in.getRole()).entity(in.getEntity()); + } + + } +} diff --git a/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/domain/internal/ProjectTeam.java b/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/domain/internal/ProjectTeam.java index e53ea4ec63..1022b3ed2f 100644 --- a/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/domain/internal/ProjectTeam.java +++ b/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/domain/internal/ProjectTeam.java @@ -46,17 +46,17 @@ public final class ProjectTeam { } } - private final String projectId; + private final String projectNumber; private final Team team; - private ProjectTeam(String projectId, Team team) { - this.projectId = projectId; + private ProjectTeam(String projectNumber, Team team) { + this.projectNumber = projectNumber; this.team = team; } - public String getProjectId() { - return projectId; + public String getProjectNumber() { + return projectNumber; } public Team getTeam() { @@ -65,7 +65,7 @@ public final class ProjectTeam { @Override public int hashCode() { - return Objects.hashCode(projectId, team); + return Objects.hashCode(projectNumber, team); } @Override @@ -75,11 +75,11 @@ public final class ProjectTeam { if (obj == null || getClass() != obj.getClass()) return false; ProjectTeam that = ProjectTeam.class.cast(obj); - return equal(this.projectId, that.projectId) && equal(this.team, that.team); + return equal(this.projectNumber, that.projectNumber) && equal(this.team, that.team); } protected MoreObjects.ToStringHelper string() { - return toStringHelper(this).add("projectId", projectId).add("team", team); + return toStringHelper(this).add("projectNumber", projectNumber).add("team", team); } @Override @@ -93,11 +93,11 @@ public final class ProjectTeam { public static class Builder { - private String projectId; + private String projectNumber; private Team team; - public Builder projectId(String projectId) { - this.projectId = projectId; + public Builder projectNumber(String projectNumber) { + this.projectNumber = projectNumber; return this; } @@ -107,11 +107,11 @@ public final class ProjectTeam { } public ProjectTeam build() { - return new ProjectTeam(this.projectId, this.team); + return new ProjectTeam(this.projectNumber, this.team); } public Builder fromProjectTeam(ProjectTeam in) { - return this.projectId(in.getProjectId()).team(in.getTeam()); + return this.projectNumber(in.getProjectNumber()).team(in.getTeam()); } } } diff --git a/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/features/ObjectAccessControlsApi.java b/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/features/ObjectAccessControlsApi.java new file mode 100644 index 0000000000..87503a2826 --- /dev/null +++ b/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/features/ObjectAccessControlsApi.java @@ -0,0 +1,365 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.jclouds.googlecloudstorage.features; + +import static org.jclouds.googlecloudstorage.reference.GoogleCloudStorageConstants.STORAGE_FULLCONTROL_SCOPE; + +import javax.inject.Named; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; + +import org.jclouds.Fallbacks.NullOnNotFoundOr404; +import org.jclouds.googlecloudstorage.domain.ListObjectAccessControls; +import org.jclouds.googlecloudstorage.domain.ObjectAccessControls; +import org.jclouds.googlecloudstorage.domain.ObjectAccessControlsTemplate; +import org.jclouds.googlecloudstorage.handlers.ObjectAccessControlsBinder; +import org.jclouds.javax.annotation.Nullable; +import org.jclouds.oauth.v2.config.OAuthScopes; +import org.jclouds.oauth.v2.filters.OAuthAuthenticator; +import org.jclouds.rest.annotations.BinderParam; +import org.jclouds.rest.annotations.Fallback; +import org.jclouds.rest.annotations.MapBinder; +import org.jclouds.rest.annotations.PATCH; +import org.jclouds.rest.annotations.PayloadParam; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.SkipEncoding; +import org.jclouds.rest.binders.BindToJsonPayload; + +/** + * Provides access to ObjectAccessControl entities via their REST API. + * + * @see + */ + +@SkipEncoding({ '/', '=' }) +@RequestFilters(OAuthAuthenticator.class) +public interface ObjectAccessControlsApi { + + /** + * Returns the acl entry for the specified entity on the specified object. + * + * @param bucketName + * Name of the bucket which contains the object + * @param objectName + * Name of the bucket of that acl is related + * @param entity + * The entity holding the permission. Can be user-userId, user-emailAddress, group-groupId, + * group-emailAddress, allUsers, or allAuthenticatedUsers + * + * @return an {@link ObjectAccessControls } + */ + + @Named("ObjectAccessControls:get") + @GET + @Consumes(MediaType.APPLICATION_JSON) + @Path("/b/{bucket}/o/{object}/acl/{entity}") + @OAuthScopes(STORAGE_FULLCONTROL_SCOPE) + @Fallback(NullOnNotFoundOr404.class) + @Nullable + ObjectAccessControls getObjectAccessControls(@PathParam("bucket") String bucketName, + @PathParam("object") String objectName, @PathParam("entity") String entity); + + /** + * Returns the acl entry for the specified entity on the specified object. + * + * @param bucketName + * Name of the bucket which contains the object + * @param objectName + * Name of the object of that acl is related + * @param entity + * The entity holding the permission. Can be user-userId, user-emailAddress, group-groupId, + * group-emailAddress, allUsers, or allAuthenticatedUsers + * @param generation + * If present, selects a specific revision of this object + * + * @return an {@link ObjectAccessControls } + */ + + @Named("ObjectAccessControls:get") + @GET + @Consumes(MediaType.APPLICATION_JSON) + @Path("/b/{bucket}/o/{object}/acl/{entity}") + @OAuthScopes(STORAGE_FULLCONTROL_SCOPE) + @Fallback(NullOnNotFoundOr404.class) + @Nullable + ObjectAccessControls getObjectAccessControls(@PathParam("bucket") String bucketName, + @PathParam("object") String objectName, @PathParam("entity") String entity, + @QueryParam("generation") Long generation); + + /** + * Creates a new acl entry for specified object + * + * @param bucketName + * Name of the bucket of that acl to be created In the request body, supply a ObjectAccessControls resource + * with the following properties + * @param objectName + * Name of the bucket of that acl is related + * + * @return an {@link ObjectAccessControls } + */ + + @Named("ObjectAccessControls:insert") + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Path("/b/{bucket}/o/{object}/acl") + @OAuthScopes(STORAGE_FULLCONTROL_SCOPE) + @MapBinder(ObjectAccessControlsBinder.class) + ObjectAccessControls createObjectAccessControls(@PathParam("bucket") String bucketName, + @PathParam("object") String objectName, @PayloadParam("template") ObjectAccessControlsTemplate template); + + /** + * Creates a new acl entry for specified object + * + * @param bucketName + * Name of the bucket of that acl to be created In the request body, supply a ObjectAccessControls resource + * with the following properties + * @param objectName + * Name of the bucket of that acl is related + * @param generation + * If present, selects a specific revision of this object + * + * @return an {@link ObjectAccessControls } + */ + + @Named("ObjectAccessControls:insert") + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Path("/b/{bucket}/o/{object}/acl") + @OAuthScopes(STORAGE_FULLCONTROL_SCOPE) + @MapBinder(ObjectAccessControlsBinder.class) + ObjectAccessControls createObjectAccessControls(@PathParam("bucket") String bucketName, + @PathParam("object") String objectName, @PayloadParam("template") ObjectAccessControlsTemplate template, + @QueryParam("generation") Long generation); + + /** + * Permanently deletes the acl entry for the specified entity on the specified bucket. + * + * @param bucketName + * Name of the bucket which contains the object + * @param objectName + * Name of the bucket of which acl is related + * @param entity + * The entity holding the permission. Can be user-userId, user-emailAddress, group-groupId, + * group-emailAddress, allUsers, or allAuthenticatedUsers + */ + + @Named("ObjectAccessControls:delete") + @DELETE + @Consumes(MediaType.APPLICATION_JSON) + @Path("/b/{bucket}/o/{object}/acl/{entity}") + @OAuthScopes(STORAGE_FULLCONTROL_SCOPE) + void deleteObjectAccessControls(@PathParam("bucket") String bucketName, @PathParam("object") String objectName, + @PathParam("entity") String entity); + + /** + * Permanently deletes the acl entry for the specified entity on the specified bucket. + * + * @param bucketName + * Name of the bucket which contains the object + * @param objectName + * Name of the bucket of that acl is related + * @param generation + * If present, selects a specific revision of this object + * @param entity + * The entity holding the permission. Can be user-userId, user-emailAddress, group-groupId, + * group-emailAddress, allUsers, or allAuthenticatedUsers + */ + + @Named("ObjectAccessControls:delete") + @DELETE + @Consumes(MediaType.APPLICATION_JSON) + @Path("/b/{bucket}/o/{object}/acl/{entity}") + @OAuthScopes(STORAGE_FULLCONTROL_SCOPE) + void deleteObjectAccessControls(@PathParam("bucket") String bucketName, @PathParam("object") String objectName, + @PathParam("entity") String entity, @QueryParam("generation") Long generation); + + /** + * Retrieves acl entries on a specified object + * + * @param bucketName + * Name of the bucket which contains the object + * @param objectName + * Name of the bucket of that acl is related + * @param generation + * If present, selects a specific revision of this object + * + * @return {@link ListObjectAccessControls } resource + * + */ + + @Named("ObjectAccessControls:list") + @GET + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Path("/b/{bucket}/o/{object}/acl") + @OAuthScopes(STORAGE_FULLCONTROL_SCOPE) + @Fallback(NullOnNotFoundOr404.class) + @Nullable + ListObjectAccessControls listObjectAccessControls(@PathParam("bucket") String bucketName, + @PathParam("object") String objectName); + + /** + * Retrieves acl entries on a specified object + * + * @param bucketName + * Name of the bucket which contains the object + * @param objectName + * Name of the bucket of that acl is related + * @param generation + * If present, selects a specific revision of this object + * + * @return a {@link ListObjectAccessControls } + * + */ + + @Named("ObjectAccessControls:list") + @GET + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Path("/b/{bucket}/o/{object}/acl") + @OAuthScopes(STORAGE_FULLCONTROL_SCOPE) + @Fallback(NullOnNotFoundOr404.class) + @Nullable + ListObjectAccessControls listObjectAccessControls(@PathParam("bucket") String bucketName, + @PathParam("object") String objectName, @QueryParam("generation") Long generation); + + /** + * Updates an acl entry on the specified object + * + * @param bucketName + * Name of the bucket of which contains the object + * @param objectName + * Name of the object which acl is related + * @param entity + * The entity holding the permission. Can be user-userId, user-emailAddress, group-groupId, + * group-emailAddress, allUsers, or allAuthenticatedUsers. + * @param template + * Supply an {@link ObjectAccessControlsTemplate} + * + * @return an {@link ObjectAccessControls } + */ + + @Named("ObjectAccessControls:update") + @PUT + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Path("/b/{bucket}/o/{object}/acl/{entity}") + @OAuthScopes(STORAGE_FULLCONTROL_SCOPE) + @Fallback(NullOnNotFoundOr404.class) + @Nullable + ObjectAccessControls updateObjectAccessControls(@PathParam("bucket") String bucketName, + @PathParam("object") String objectName, @PathParam("entity") String entity, + @BinderParam(BindToJsonPayload.class) ObjectAccessControlsTemplate template); + + /** + * Updates an acl entry on the specified object + * + * @param bucketName + * Name of the bucket of which contains the object + * @param objectName + * Name of the object which acl is related * + * @param entity + * The entity holding the permission. Can be user-userId, user-emailAddress, group-groupId, + * group-emailAddress, allUsers, or allAuthenticatedUsers + * @param template + * Supply an {@link ObjectAccessControlsTemplate} + * @param generation + * If present, selects a specific revision of this object + * + * @return {@link ObjectAccessControls } + */ + + @Named("ObjectAccessControls:update") + @PUT + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Path("/b/{bucket}/o/{object}/acl/{entity}") + @OAuthScopes(STORAGE_FULLCONTROL_SCOPE) + @Fallback(NullOnNotFoundOr404.class) + ObjectAccessControls updateObjectAccessControls(@PathParam("bucket") String bucketName, + @PathParam("object") String objectName, @PathParam("entity") String entity, + @BinderParam(BindToJsonPayload.class) ObjectAccessControlsTemplate template, + @QueryParam("generation") Long generation); + + /** + * Updates an acl entry on the specified object + * + * @param bucketName + * Name of the bucket of which contains the object + * @param objectName + * Name of the object which acl is related + * @param template + * Supply an {@link ObjectAccessControlsTemplate} + * @param entity + * The entity holding the permission. Can be user-userId, user-emailAddress, group-groupId, + * group-emailAddress, allUsers, or allAuthenticatedUsers. + * + * @return an {@link ObjectAccessControls } + */ + + @Named("ObjectAccessControls:patch") + @PATCH + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Path("/b/{bucket}/o/{object}/acl/{entity}") + @OAuthScopes(STORAGE_FULLCONTROL_SCOPE) + @Fallback(NullOnNotFoundOr404.class) + ObjectAccessControls patchObjectAccessControls(@PathParam("bucket") String bucketName, + @PathParam("object") String objectName, @PathParam("entity") String entity, + @BinderParam(BindToJsonPayload.class) ObjectAccessControlsTemplate template); + + /** + * Updates an acl entry on the specified object + * + * @param bucketName + * Name of the bucket of which contains the object + * @param objectName + * Name of the object which acl is related + * @param entity + * The entity holding the permission. Can be user-userId, user-emailAddress, group-groupId, + * group-emailAddress, allUsers, or allAuthenticatedUsers + * @param template + * Supply an {@link ObjectAccessControlsTemplate} + * @param generation + * If present, selects a specific revision of this object + * + * @return {@link ObjectAccessControls } + */ + + @Named("ObjectAccessControls:patch") + @PATCH + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Path("/b/{bucket}/o/{object}/acl/{entity}") + @OAuthScopes(STORAGE_FULLCONTROL_SCOPE) + @Fallback(NullOnNotFoundOr404.class) + ObjectAccessControls patchObjectAccessControls(@PathParam("bucket") String bucketName, + @PathParam("object") String objectName, @PathParam("entity") String entity, + @BinderParam(BindToJsonPayload.class) ObjectAccessControlsTemplate template, + @QueryParam("generation") Long generation); + +} diff --git a/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/handlers/GoogleCloudStorageErrorHandler.java b/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/handlers/GoogleCloudStorageErrorHandler.java index 9198618559..f7e24e9f0e 100644 --- a/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/handlers/GoogleCloudStorageErrorHandler.java +++ b/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/handlers/GoogleCloudStorageErrorHandler.java @@ -41,6 +41,10 @@ public class GoogleCloudStorageErrorHandler implements HttpErrorHandler { : new HttpResponseException(command, response); message = message != null ? message : String.format("%s -> %s", command.getCurrentRequest().getRequestLine(), response.getStatusLine()); + + String message411 = "MissingContentLength: You must provide the Content-Length HTTP header.\n"; + String message412 = "PreconditionFailed: At least one of the pre-conditions you specified did not hold.\n"; + switch (response.getStatusCode()) { case 401: case 403: @@ -52,6 +56,12 @@ public class GoogleCloudStorageErrorHandler implements HttpErrorHandler { case 409: exception = new IllegalStateException(message, exception); break; + case 411: + exception = new IllegalStateException(message411 + message, exception); + break; + case 412: + exception = new IllegalStateException(message412 + message, exception); + break; } command.setException(exception); } diff --git a/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/handlers/ObjectAccessControlsBinder.java b/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/handlers/ObjectAccessControlsBinder.java new file mode 100644 index 0000000000..e1f4eda998 --- /dev/null +++ b/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/handlers/ObjectAccessControlsBinder.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.jclouds.googlecloudstorage.handlers; + +import java.util.Map; + +import javax.inject.Inject; + +import org.jclouds.googlecloudstorage.domain.ObjectAccessControlsTemplate; +import org.jclouds.http.HttpRequest; +import org.jclouds.rest.MapBinder; +import org.jclouds.rest.binders.BindToJsonPayload; + +public class ObjectAccessControlsBinder implements MapBinder { + + @Inject + private BindToJsonPayload jsonBinder; + + @Override + public R bindToRequest(R request, Map postParams) throws IllegalArgumentException{ + ObjectAccessControlsTemplate postBucket = (ObjectAccessControlsTemplate) postParams.get("template"); + return bindToRequest(request, postBucket); + } + + @Override + public R bindToRequest(R request, Object input) { + return jsonBinder.bindToRequest(request, input); + } +} diff --git a/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/BucketAccessControlsApiLiveTest.java b/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/BucketAccessControlsApiLiveTest.java new file mode 100644 index 0000000000..ea3010c93a --- /dev/null +++ b/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/BucketAccessControlsApiLiveTest.java @@ -0,0 +1,112 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.jclouds.googlecloudstorage.features; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + +import java.util.UUID; + +import org.jclouds.googlecloudstorage.domain.Bucket; +import org.jclouds.googlecloudstorage.domain.BucketAccessControls; +import org.jclouds.googlecloudstorage.domain.BucketTemplate; +import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.Role; +import org.jclouds.googlecloudstorage.domain.ListBucketAccessControls; +import org.jclouds.googlecloudstorage.domain.Resource.Kind; +import org.jclouds.googlecloudstorage.internal.BaseGoogleCloudStorageApiLiveTest; +import org.testng.annotations.Test; + +public class BucketAccessControlsApiLiveTest extends BaseGoogleCloudStorageApiLiveTest { + + protected static final String BUCKET_NAME = "jcloudstestbucketacl" + UUID.randomUUID(); + + private BucketAccessControlsApi api() { + return api.getBucketAccessControlsApi(); + } + + private void createBucket(String BucketName) { + BucketTemplate template = new BucketTemplate().name(BucketName); + Bucket response = api.getBucketApi().createBucket(PROJECT_NUMBER, template); + assertNotNull(response); + } + + @Test(groups = "live") + public void testCreateBucketAcl() { + createBucket(BUCKET_NAME); + BucketAccessControls bucketAcl = BucketAccessControls.builder().bucket(BUCKET_NAME).entity("allUsers") + .role(Role.READER).build(); + BucketAccessControls response = api().createBucketAccessControls(BUCKET_NAME, bucketAcl); + + assertNotNull(response); + assertEquals(response.getId(), BUCKET_NAME + "/allUsers"); + } + + @Test(groups = "live", dependsOnMethods = "testCreateBucketAcl") + public void testUpdateBucketAcl() { + BucketAccessControls bucketAcl = BucketAccessControls.builder().bucket(BUCKET_NAME).entity("allUsers") + .role(Role.WRITER).build(); + BucketAccessControls response = api().updateBucketAccessControls(BUCKET_NAME, "allUsers", bucketAcl); + + assertNotNull(response); + assertEquals(response.getId(), BUCKET_NAME + "/allUsers"); + assertEquals(response.getRole(), Role.WRITER); + } + + @Test(groups = "live", dependsOnMethods = "testUpdateBucketAcl") + public void testGetBucketAcl() { + BucketAccessControls response = api().getBucketAccessControls(BUCKET_NAME, "allUsers"); + + assertNotNull(response); + assertEquals(response.getId(), BUCKET_NAME + "/allUsers"); + assertEquals(response.getRole(), Role.WRITER); + } + + @Test(groups = "live", dependsOnMethods = "testUpdateBucketAcl") + public void testListBucketAcl() { + ListBucketAccessControls response = api().listBucketAccessControls(BUCKET_NAME); + + assertNotNull(response); + assertEquals(response.getKind(), Kind.BUCKET_ACCESS_CONTROLS); + assertNotNull(response.getItems()); + } + + @Test(groups = "live", dependsOnMethods = "testUpdateBucketAcl") + public void testPatchBucketAcl() { + BucketAccessControls bucketAcl = BucketAccessControls.builder().bucket(BUCKET_NAME).entity("allUsers") + .role(Role.READER).build(); + BucketAccessControls response = api().patchBucketAccessControls(BUCKET_NAME, "allUsers", bucketAcl); + + assertNotNull(response); + assertEquals(response.getId(), BUCKET_NAME + "/allUsers"); + assertEquals(response.getRole(), Role.READER); + } + + @Test(groups = "live", dependsOnMethods = "testPatchBucketAcl") + public void testDeleteBucketAcl() { + api().deleteBucketAccessControls(BUCKET_NAME, "allUsers"); + deleteBucket(BUCKET_NAME); + } + + @Test(groups = "live", dependsOnMethods = "testDeleteBucketAcl") + public void testDeleteNotExistingBucketAccessControls() { + api().deleteBucketAccessControls(BUCKET_NAME, "allUsers"); + } + + private void deleteBucket(String BucketName) { + api.getBucketApi().deleteBucket(BucketName); + } +} diff --git a/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/DefaultObjectAccessControlsApiExpectTest.java b/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/DefaultObjectAccessControlsApiExpectTest.java index 0659847e30..987605dc76 100644 --- a/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/DefaultObjectAccessControlsApiExpectTest.java +++ b/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/DefaultObjectAccessControlsApiExpectTest.java @@ -40,31 +40,31 @@ public class DefaultObjectAccessControlsApiExpectTest extends BaseGoogleCloudSto private static final String EXPECTED_TEST_BUCKET = "jcloudtestbucket"; private static final String EXPECTED_TEST_GROUP_ENTITY = "group-00b4903a971ec6cff233284d6d24f5bf5cba904c4ade4d43ebd6a5d33800e68b"; - private static final HttpRequest GET_DEFAULT_OBJECTACL_REQUEST = HttpRequest + private static final HttpRequest GET_DEFAULT_OBJECT_ACL_REQUEST = HttpRequest .builder() .method("GET") .endpoint( "https://www.googleapis.com/storage/v1/b/jcloudtestbucket/defaultObjectAcl/group-00b4903a971ec6cff233284d6d24f5bf5cba904c4ade4d43ebd6a5d33800e68b") .addHeader("Accept", "application/json").addHeader("Authorization", "Bearer " + TOKEN).build(); - private final HttpResponse GET_DEFAULT_OBJECTACL_RESPONSE = HttpResponse.builder().statusCode(200) + private final HttpResponse GET_DEFAULT_OBJECT_ACL_RESPONSE = HttpResponse.builder().statusCode(200) .payload(staticPayloadFromResource("/default_objectacl_get.json")).build(); - private final HttpResponse CREATE_DEFAULT_OBJECTACL_RESPONSE = HttpResponse.builder().statusCode(200) + private final HttpResponse CREATE_DEFAULT_OBJECT_ACL_RESPONSE = HttpResponse.builder().statusCode(200) .payload(staticPayloadFromResource("/default_objectacl_insert_response.json")).build(); - public final HttpRequest LIST_DEFAULT_OBJECTACL_REQUEST = HttpRequest.builder().method("GET") + public final HttpRequest LIST_DEFAULT_OBJECT_ACL_REQUEST = HttpRequest.builder().method("GET") .endpoint("https://www.googleapis.com/storage/v1/b/jcloudtestbucket/defaultObjectAcl") .addHeader("Accept", "application/json").addHeader("Authorization", "Bearer " + TOKEN).build(); - private final HttpResponse LIST_DEFAULT_OBJECTACL_RESPONSE = HttpResponse.builder().statusCode(200) + private final HttpResponse LIST_DEFAULT_OBJECT_ACL_RESPONSE = HttpResponse.builder().statusCode(200) .payload(staticPayloadFromResource("/default_objectacl_list.json")).build(); // Test getDefaultObjectAccessControls public void testGetDefaultObjectAclResponseIs2xx() throws Exception { DefaultObjectAccessControlsApi api = requestsSendResponses(requestForScopes(STORAGE_FULLCONTROL_SCOPE), - TOKEN_RESPONSE, GET_DEFAULT_OBJECTACL_REQUEST, GET_DEFAULT_OBJECTACL_RESPONSE) + TOKEN_RESPONSE, GET_DEFAULT_OBJECT_ACL_REQUEST, GET_DEFAULT_OBJECT_ACL_RESPONSE) .getDefaultObjectAccessControlsApi(); assertEquals(api.getDefaultObjectAccessControls(EXPECTED_TEST_BUCKET, EXPECTED_TEST_GROUP_ENTITY), @@ -76,7 +76,7 @@ public class DefaultObjectAccessControlsApiExpectTest extends BaseGoogleCloudSto HttpResponse getResponse = HttpResponse.builder().statusCode(404).build(); DefaultObjectAccessControlsApi api = requestsSendResponses(requestForScopes(STORAGE_FULLCONTROL_SCOPE), - TOKEN_RESPONSE, GET_DEFAULT_OBJECTACL_REQUEST, getResponse).getDefaultObjectAccessControlsApi(); + TOKEN_RESPONSE, GET_DEFAULT_OBJECT_ACL_REQUEST, getResponse).getDefaultObjectAccessControlsApi(); assertNull(api.getDefaultObjectAccessControls(EXPECTED_TEST_BUCKET, EXPECTED_TEST_GROUP_ENTITY)); } @@ -85,7 +85,7 @@ public class DefaultObjectAccessControlsApiExpectTest extends BaseGoogleCloudSto public void testListDefaultObjectAclWithNoOptionsResponseIs2xx() throws Exception { DefaultObjectAccessControlsApi api = requestsSendResponses(requestForScopes(STORAGE_FULLCONTROL_SCOPE), - TOKEN_RESPONSE, LIST_DEFAULT_OBJECTACL_REQUEST, LIST_DEFAULT_OBJECTACL_RESPONSE) + TOKEN_RESPONSE, LIST_DEFAULT_OBJECT_ACL_REQUEST, LIST_DEFAULT_OBJECT_ACL_RESPONSE) .getDefaultObjectAccessControlsApi(); assertEquals(api.listDefaultObjectAccessControls(EXPECTED_TEST_BUCKET), new DefaultObjectAclListTest().expected()); @@ -96,7 +96,7 @@ public class DefaultObjectAccessControlsApiExpectTest extends BaseGoogleCloudSto HttpResponse listResponse = HttpResponse.builder().statusCode(404).build(); DefaultObjectAccessControlsApi api = requestsSendResponses(requestForScopes(STORAGE_FULLCONTROL_SCOPE), - TOKEN_RESPONSE, LIST_DEFAULT_OBJECTACL_REQUEST, listResponse).getDefaultObjectAccessControlsApi(); + TOKEN_RESPONSE, LIST_DEFAULT_OBJECT_ACL_REQUEST, listResponse).getDefaultObjectAccessControlsApi(); assertNull(api.listDefaultObjectAccessControls(EXPECTED_TEST_BUCKET)); } @@ -113,7 +113,7 @@ public class DefaultObjectAccessControlsApiExpectTest extends BaseGoogleCloudSto MediaType.APPLICATION_JSON)).build(); DefaultObjectAccessControlsApi api = requestsSendResponses(requestForScopes(STORAGE_FULLCONTROL_SCOPE), - TOKEN_RESPONSE, insertRequest, CREATE_DEFAULT_OBJECTACL_RESPONSE).getDefaultObjectAccessControlsApi(); + TOKEN_RESPONSE, insertRequest, CREATE_DEFAULT_OBJECT_ACL_RESPONSE).getDefaultObjectAccessControlsApi(); DefaultObjectAccessControlsTemplate template = new DefaultObjectAccessControlsTemplate().entity("allUsers").role( ObjectRole.OWNER); diff --git a/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/DefaultObjectAccessControlsApiLiveTest.java b/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/DefaultObjectAccessControlsApiLiveTest.java new file mode 100644 index 0000000000..0f3191405b --- /dev/null +++ b/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/DefaultObjectAccessControlsApiLiveTest.java @@ -0,0 +1,117 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.jclouds.googlecloudstorage.features; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + +import java.util.UUID; + +import org.jclouds.googlecloudstorage.domain.Bucket; +import org.jclouds.googlecloudstorage.domain.BucketTemplate; +import org.jclouds.googlecloudstorage.domain.DefaultObjectAccessControls; +import org.jclouds.googlecloudstorage.domain.DefaultObjectAccessControlsTemplate; +import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.ObjectRole; +import org.jclouds.googlecloudstorage.domain.ListDefaultObjectAccessControls; +import org.jclouds.googlecloudstorage.domain.Resource.Kind; +import org.jclouds.googlecloudstorage.internal.BaseGoogleCloudStorageApiLiveTest; +import org.testng.annotations.Test; + +public class DefaultObjectAccessControlsApiLiveTest extends BaseGoogleCloudStorageApiLiveTest { + + protected static final String BUCKET_NAME = "jcloudtestbucketdefaultoacl" + UUID.randomUUID(); + + private DefaultObjectAccessControlsApi api() { + return api.getDefaultObjectAccessControlsApi(); + } + + private void createBucket(String BucketName) { + BucketTemplate template = new BucketTemplate().name(BucketName); + Bucket response = api.getBucketApi().createBucket(PROJECT_NUMBER, template); + assertNotNull(response); + } + + @Test(groups = "live") + public void testCreateDefaultObjectAcl() { + createBucket(BUCKET_NAME); + DefaultObjectAccessControlsTemplate template = new DefaultObjectAccessControlsTemplate().entity("allUsers").role( + ObjectRole.READER); + + DefaultObjectAccessControls response = api().createDefaultObjectAccessControls(BUCKET_NAME, template); + + assertNotNull(response); + assertEquals(response.getEntity(), "allUsers"); + assertEquals(response.getRole(), ObjectRole.READER); + } + + @Test(groups = "live", dependsOnMethods = "testCreateDefaultObjectAcl") + public void testUpdateDefaultObjectAcl() { + DefaultObjectAccessControls defaultObjectAcl = DefaultObjectAccessControls.builder().bucket(BUCKET_NAME) + .entity("allUsers").role(ObjectRole.OWNER).build(); + DefaultObjectAccessControls response = api().updateDefaultObjectAccessControls(BUCKET_NAME, "allUsers", + defaultObjectAcl); + + assertNotNull(response); + assertEquals(response.getEntity(), "allUsers"); + assertEquals(response.getRole(), ObjectRole.OWNER); + } + + @Test(groups = "live", dependsOnMethods = "testUpdateDefaultObjectAcl") + public void testGetDefaultObjectAcl() { + DefaultObjectAccessControls response = api().getDefaultObjectAccessControls(BUCKET_NAME, "allUsers"); + + assertNotNull(response); + assertEquals(response.getEntity(), "allUsers"); + assertEquals(response.getRole(), ObjectRole.OWNER); + } + + @Test(groups = "live", dependsOnMethods = "testUpdateDefaultObjectAcl") + public void testListDefaultObjectAcl() { + ListDefaultObjectAccessControls response = api().listDefaultObjectAccessControls(BUCKET_NAME); + + assertNotNull(response); + assertEquals(response.getKind(), Kind.OBJECT_ACCESS_CONTROLS); + assertNotNull(response.getItems()); + } + + @Test(groups = "live", dependsOnMethods = "testUpdateDefaultObjectAcl") + public void testPatchDefaultObjectAcl() { + DefaultObjectAccessControls defaultObjectAcl = DefaultObjectAccessControls.builder().bucket(BUCKET_NAME) + .entity("allUsers").role(ObjectRole.READER).build(); + DefaultObjectAccessControls response = api().patchDefaultObjectAccessControls(BUCKET_NAME, "allUsers", + defaultObjectAcl); + + assertNotNull(response); + assertEquals(response.getEntity(), "allUsers"); + assertEquals(response.getRole(), ObjectRole.READER); + } + + @Test(groups = "live", dependsOnMethods = "testPatchDefaultObjectAcl") + public void testDeleteBucketAcl() { + api().deleteDefaultObjectAccessControls(BUCKET_NAME, "allUsers"); + deleteBucket(BUCKET_NAME); + } + + @Test(groups = "live", dependsOnMethods = "testDeleteBucketAcl") + public void testDeleteNotExistingBucketAccessControls() { + api().deleteDefaultObjectAccessControls(BUCKET_NAME, "allUsers"); + } + + private void deleteBucket(String bucketName) { + api.getBucketApi().deleteBucket(bucketName); + } +} diff --git a/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/ObjectAccessControlsApiExpectTest.java b/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/ObjectAccessControlsApiExpectTest.java new file mode 100644 index 0000000000..7f87e45e76 --- /dev/null +++ b/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/ObjectAccessControlsApiExpectTest.java @@ -0,0 +1,282 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.jclouds.googlecloudstorage.features; + +import static org.jclouds.googlecloudstorage.reference.GoogleCloudStorageConstants.STORAGE_FULLCONTROL_SCOPE; +import static org.testng.Assert.assertEquals; +import static org.testng.AssertJUnit.assertNull; + +import javax.ws.rs.core.MediaType; + +import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.ObjectRole; +import org.jclouds.googlecloudstorage.domain.ObjectAccessControlsTemplate; +import org.jclouds.googlecloudstorage.internal.BaseGoogleCloudStorageApiExpectTest; +import org.jclouds.googlecloudstorage.parse.ObjectAclGetTest; +import org.jclouds.googlecloudstorage.parse.ObjectAclInsertTest; +import org.jclouds.googlecloudstorage.parse.ObjectAclListTest; +import org.jclouds.googlecloudstorage.parse.ObjectAclUpdateTest; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.testng.annotations.Test; + +@Test(groups = "unit") +public class ObjectAccessControlsApiExpectTest extends BaseGoogleCloudStorageApiExpectTest { + + private static final String EXPECTED_TEST_BUCKET = "jcloudtestbucket"; + private static final String EXPECTED_TEST_OBJECT = "foo.txt"; + private static final String EXPECTED_TEST_GROUP_ENTITY = "group-00b4903a971ec6cff233284d6d24f5bf5cba904c4ade4d43ebd6a5d33800e68b"; + private static final String EXPECTED_TEST_USER_ENTITY = "user-00b4903a97adfde729f0650133a7379693099d8d85d6b1b18255ca70bf89e31d"; + + public static final HttpRequest GET_OBJECT_ACL_REQUEST = HttpRequest + .builder() + .method("GET") + .endpoint( + "https://www.googleapis.com/storage/v1/b/jcloudtestbucket/o/foo.txt/acl/group-00b4903a971ec6cff233284d6d24f5bf5cba904c4ade4d43ebd6a5d33800e68b") + .addHeader("Accept", "application/json").addHeader("Authorization", "Bearer " + TOKEN).build(); + + public static final HttpRequest GET_OBJECT_ACL_REQUEST_WITHOPTIONS = HttpRequest + .builder() + .method("GET") + .endpoint( + "https://www.googleapis.com/storage/v1/b/jcloudtestbucket/o/foo.txt/acl/group-00b4903a971ec6cff233284d6d24f5bf5cba904c4ade4d43ebd6a5d33800e68b") + .addQueryParam("generation", "100").addHeader("Accept", "application/json") + .addHeader("Authorization", "Bearer " + TOKEN).build(); + + public final HttpResponse GET_OBJECT_ACL_RESPONSE = HttpResponse.builder().statusCode(200) + .payload(staticPayloadFromResource("/objectacl_get.json")).build(); + + public final HttpResponse CREATE_OBJECT_ACL_RESPONSE = HttpResponse.builder().statusCode(200) + .payload(staticPayloadFromResource("/objectacl_insert_response.json")).build(); + + public final HttpRequest LIST_OBJECT_ACL_REQUEST = HttpRequest.builder().method("GET") + .endpoint("https://www.googleapis.com/storage/v1/b/jcloudtestbucket/o/foo.txt/acl") + .addHeader("Accept", "application/json").addHeader("Authorization", "Bearer " + TOKEN).build(); + + public final HttpRequest LIST_OBJECT_ACL_REQUEST_WITHOPTIONS = HttpRequest.builder().method("GET") + .endpoint("https://www.googleapis.com/storage/v1/b/jcloudtestbucket/o/foo.txt/acl") + .addQueryParam("generation", "100").addHeader("Accept", "application/json") + .addHeader("Authorization", "Bearer " + TOKEN).build(); + + public final HttpResponse LIST_OBJECT_ACL_RESPONSE = HttpResponse.builder().statusCode(200) + .payload(staticPayloadFromResource("/objectacl_list.json")).build(); + + // Test getObjectAccessControls + public void testGetObjectaclWithNoOptionsResponseIs2xx() throws Exception { + + ObjectAccessControlsApi api = requestsSendResponses(requestForScopes(STORAGE_FULLCONTROL_SCOPE), TOKEN_RESPONSE, + GET_OBJECT_ACL_REQUEST, GET_OBJECT_ACL_RESPONSE).getObjectAccessControlsApi(); + + assertEquals(api.getObjectAccessControls(EXPECTED_TEST_BUCKET, EXPECTED_TEST_OBJECT, EXPECTED_TEST_GROUP_ENTITY), + new ObjectAclGetTest().expected()); + } + + public void testGetObjectaclWithOptionsResponseIs2xx() throws Exception { + + ObjectAccessControlsApi api = requestsSendResponses(requestForScopes(STORAGE_FULLCONTROL_SCOPE), TOKEN_RESPONSE, + GET_OBJECT_ACL_REQUEST_WITHOPTIONS, GET_OBJECT_ACL_RESPONSE).getObjectAccessControlsApi(); + + assertEquals( + api.getObjectAccessControls(EXPECTED_TEST_BUCKET, EXPECTED_TEST_OBJECT, EXPECTED_TEST_GROUP_ENTITY, + Long.valueOf(100)), new ObjectAclGetTest().expected()); + } + + public void testGetObjectaclResponseIs4xx() throws Exception { + + HttpResponse getResponse = HttpResponse.builder().statusCode(404).build(); + + ObjectAccessControlsApi api = requestsSendResponses(requestForScopes(STORAGE_FULLCONTROL_SCOPE), TOKEN_RESPONSE, + GET_OBJECT_ACL_REQUEST, getResponse).getObjectAccessControlsApi(); + + assertNull(api.getObjectAccessControls(EXPECTED_TEST_BUCKET, EXPECTED_TEST_OBJECT, EXPECTED_TEST_GROUP_ENTITY)); + } + + // Test listObjectAccessControls + public void testListObjectaclWithNoOptionsResponseIs2xx() throws Exception { + + ObjectAccessControlsApi api = requestsSendResponses(requestForScopes(STORAGE_FULLCONTROL_SCOPE), TOKEN_RESPONSE, + LIST_OBJECT_ACL_REQUEST, LIST_OBJECT_ACL_RESPONSE).getObjectAccessControlsApi(); + + assertEquals(api.listObjectAccessControls(EXPECTED_TEST_BUCKET, EXPECTED_TEST_OBJECT), + new ObjectAclListTest().expected()); + + } + + // Test listObjectAccessControls + public void testListObjectaclWithOptionsResponseIs2xx() throws Exception { + + ObjectAccessControlsApi api = requestsSendResponses(requestForScopes(STORAGE_FULLCONTROL_SCOPE), TOKEN_RESPONSE, + LIST_OBJECT_ACL_REQUEST_WITHOPTIONS, LIST_OBJECT_ACL_RESPONSE).getObjectAccessControlsApi(); + + assertEquals(api.listObjectAccessControls(EXPECTED_TEST_BUCKET, EXPECTED_TEST_OBJECT, Long.valueOf(100)), + new ObjectAclListTest().expected()); + + } + + public void testListObjectaclResponseIs4xx() throws Exception { + + HttpResponse listResponse = HttpResponse.builder().statusCode(404).build(); + + ObjectAccessControlsApi api = requestsSendResponses(requestForScopes(STORAGE_FULLCONTROL_SCOPE), TOKEN_RESPONSE, + LIST_OBJECT_ACL_REQUEST, listResponse).getObjectAccessControlsApi(); + + assertNull(api.listObjectAccessControls(EXPECTED_TEST_BUCKET, EXPECTED_TEST_OBJECT)); + } + + // Test insertObjectAccessControls + public void testInsertObjectaclWithNoOptionsResponseIs2xx() throws Exception { + HttpRequest insertRequest = HttpRequest + .builder() + .method("POST") + .endpoint("https://www.googleapis.com/storage/v1/b/jcloudtestbucket/o/foo.txt/acl") + .addHeader("Accept", "application/json") + .addHeader("Authorization", "Bearer " + TOKEN) + .payload(payloadFromResourceWithContentType("/objectacl_insert_requestpayload.json", + MediaType.APPLICATION_JSON)).build(); + + ObjectAccessControlsApi api = requestsSendResponses(requestForScopes(STORAGE_FULLCONTROL_SCOPE), TOKEN_RESPONSE, + insertRequest, CREATE_OBJECT_ACL_RESPONSE).getObjectAccessControlsApi(); + + ObjectAccessControlsTemplate template = new ObjectAccessControlsTemplate().entity(EXPECTED_TEST_USER_ENTITY) + .role(ObjectRole.OWNER); + + assertEquals(api.createObjectAccessControls(EXPECTED_TEST_BUCKET, EXPECTED_TEST_OBJECT, template), + new ObjectAclInsertTest().expected()); + + } + + public void testInsertObjectaclWithOptionsResponseIs2xx() throws Exception { + HttpRequest insertRequest = HttpRequest + .builder() + .method("POST") + .endpoint("https://www.googleapis.com/storage/v1/b/jcloudtestbucket/o/foo.txt/acl") + .addHeader("Accept", "application/json") + .addHeader("Authorization", "Bearer " + TOKEN) + .addQueryParam("generation", "100") + .payload(payloadFromResourceWithContentType("/objectacl_insert_requestpayload.json", + MediaType.APPLICATION_JSON)).build(); + + ObjectAccessControlsApi api = requestsSendResponses(requestForScopes(STORAGE_FULLCONTROL_SCOPE), TOKEN_RESPONSE, + insertRequest, CREATE_OBJECT_ACL_RESPONSE).getObjectAccessControlsApi(); + + ObjectAccessControlsTemplate template = new ObjectAccessControlsTemplate().entity( + "user-00b4903a97adfde729f0650133a7379693099d8d85d6b1b18255ca70bf89e31d").role(ObjectRole.OWNER); + + assertEquals( + api.createObjectAccessControls(EXPECTED_TEST_BUCKET, EXPECTED_TEST_OBJECT, template, Long.valueOf(100)), + new ObjectAclInsertTest().expected()); + + } + + // Test updateObjectAccessControls + public void testUpdateObjectaclWithNoOptionsResponseIs2xx() throws Exception { + HttpRequest update = HttpRequest + .builder() + .method("PUT") + .endpoint("https://www.googleapis.com/storage/v1/b/jcloudtestbucket/o/foo.txt/acl/allUsers") + .addHeader("Accept", "application/json") + .addHeader("Authorization", "Bearer " + TOKEN) + .payload(payloadFromResourceWithContentType("/objectacl_request_payload.json", + MediaType.APPLICATION_JSON)).build(); + + HttpResponse updateResponse = HttpResponse.builder().statusCode(200) + .payload(staticPayloadFromResource("/objectacl_update_initial.json")).build(); + + ObjectAccessControlsApi api = requestsSendResponses(requestForScopes(STORAGE_FULLCONTROL_SCOPE), TOKEN_RESPONSE, + update, updateResponse).getObjectAccessControlsApi(); + + ObjectAccessControlsTemplate template = new ObjectAccessControlsTemplate().entity("allUsers").role( + ObjectRole.OWNER); + + assertEquals(api.updateObjectAccessControls(EXPECTED_TEST_BUCKET, EXPECTED_TEST_OBJECT, "allUsers", template), + new ObjectAclUpdateTest().expected()); + } + + public void testUpdateObjectaclWithOptionsResponseIs2xx() throws Exception { + HttpRequest update = HttpRequest + .builder() + .method("PUT") + .endpoint("https://www.googleapis.com/storage/v1/b/jcloudtestbucket/o/foo.txt/acl/allUsers") + .addQueryParam("generation", "100") + .addHeader("Accept", "application/json") + .addHeader("Authorization", "Bearer " + TOKEN) + .payload(payloadFromResourceWithContentType("/objectacl_request_payload.json", + MediaType.APPLICATION_JSON)).build(); + + HttpResponse updateResponse = HttpResponse.builder().statusCode(200) + .payload(staticPayloadFromResource("/objectacl_update_initial.json")).build(); + + ObjectAccessControlsApi api = requestsSendResponses(requestForScopes(STORAGE_FULLCONTROL_SCOPE), TOKEN_RESPONSE, + update, updateResponse).getObjectAccessControlsApi(); + + ObjectAccessControlsTemplate template = new ObjectAccessControlsTemplate().entity("allUsers").role( + ObjectRole.OWNER); + + assertEquals( + api.updateObjectAccessControls(EXPECTED_TEST_BUCKET, EXPECTED_TEST_OBJECT, "allUsers", template, + Long.valueOf(100)), new ObjectAclUpdateTest().expected()); + } + + // Test updateObjectAccessControls + public void testPatchObjectaclWithNoOptionsResponseIs2xx() throws Exception { + HttpRequest patchRequest = HttpRequest + .builder() + .method("PATCH") + .endpoint("https://www.googleapis.com/storage/v1/b/jcloudtestbucket/o/foo.txt/acl/allUsers") + .addHeader("Accept", "application/json") + .addHeader("Authorization", "Bearer " + TOKEN) + .payload(payloadFromResourceWithContentType("/objectacl_request_payload.json", + MediaType.APPLICATION_JSON)).build(); + + HttpResponse patchResponse = HttpResponse.builder().statusCode(200) + .payload(staticPayloadFromResource("/objectacl_update_initial.json")).build(); + + ObjectAccessControlsApi api = requestsSendResponses(requestForScopes(STORAGE_FULLCONTROL_SCOPE), TOKEN_RESPONSE, + patchRequest, patchResponse).getObjectAccessControlsApi(); + + ObjectAccessControlsTemplate template = new ObjectAccessControlsTemplate().entity("allUsers").role( + ObjectRole.OWNER); + + assertEquals(api.patchObjectAccessControls(EXPECTED_TEST_BUCKET, EXPECTED_TEST_OBJECT, "allUsers", template), + new ObjectAclUpdateTest().expected()); + } + + public void testPatchObjectaclWithOptionsResponseIs2xx() throws Exception { + HttpRequest patchRequest = HttpRequest + .builder() + .method("PATCH") + .endpoint("https://www.googleapis.com/storage/v1/b/jcloudtestbucket/o/foo.txt/acl/allUsers") + .addQueryParam("generation", "100") + .addHeader("Accept", "application/json") + .addHeader("Authorization", "Bearer " + TOKEN) + .payload(payloadFromResourceWithContentType("/objectacl_request_payload.json", + MediaType.APPLICATION_JSON)).build(); + + HttpResponse patchResponse = HttpResponse.builder().statusCode(200) + .payload(staticPayloadFromResource("/objectacl_update_initial.json")).build(); + + ObjectAccessControlsApi api = requestsSendResponses(requestForScopes(STORAGE_FULLCONTROL_SCOPE), TOKEN_RESPONSE, + patchRequest, patchResponse).getObjectAccessControlsApi(); + + ObjectAccessControlsTemplate template = new ObjectAccessControlsTemplate().entity("allUsers").role( + ObjectRole.OWNER); + assertEquals( + api.patchObjectAccessControls(EXPECTED_TEST_BUCKET, EXPECTED_TEST_OBJECT, "allUsers", template, + Long.valueOf(100)), new ObjectAclUpdateTest().expected()); + } + +} diff --git a/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/parse/BucketAclListTest.java b/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/parse/BucketAclListTest.java index 19a1e2776d..8bdb0f458e 100644 --- a/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/parse/BucketAclListTest.java +++ b/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/parse/BucketAclListTest.java @@ -42,7 +42,7 @@ public class BucketAclListTest extends BaseGoogleCloudStorageParseTest { + + @Override + public String resource() { + return "/objectacl_get.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public ObjectAccessControls expected() { + return ObjectAccessControls + .builder() + .bucket("jcloudtestbucket") + .object("foo.txt") + .generation(1394121608485000L) + .entity("project-owners-1082289308625") + .role(ObjectRole.OWNER) + .etag("CIix/dmj/rwCEAE=") + .projectTeam(ProjectTeam.builder().projectNumber("1082289308625").team(Team.OWNERS).build()) + .selfLink( + URI.create("https://www.googleapis.com/storage/v1/b/jcloudtestbucket/o/foo.txt/acl/project-owners-1082289308625")) + .id("jcloudtestbucket/foo.txt/1394121608485000/project-owners-1082289308625").build(); + } + +} diff --git a/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/parse/ObjectAclInsertTest.java b/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/parse/ObjectAclInsertTest.java new file mode 100644 index 0000000000..229dcde830 --- /dev/null +++ b/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/parse/ObjectAclInsertTest.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.jclouds.googlecloudstorage.parse; + +import java.net.URI; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.ObjectRole; +import org.jclouds.googlecloudstorage.domain.ObjectAccessControls; +import org.jclouds.googlecloudstorage.internal.BaseGoogleCloudStorageParseTest; + +public class ObjectAclInsertTest extends BaseGoogleCloudStorageParseTest { + + @Override + public String resource() { + return "/objectacl_insert_response.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public ObjectAccessControls expected() { + return ObjectAccessControls + .builder() + .selfLink( + URI.create("https://www.googleapis.com/storage/v1/b/jcloudtestbucket/o/foo.txt/acl/user-00b4903a97adfde729f0650133a7379693099d8d85d6b1b18255ca70bf89e31d")) + .bucket("jcloudtestbucket").object("foo.txt") + .entity("user-00b4903a97adfde729f0650133a7379693099d8d85d6b1b18255ca70bf89e31d") + .entityId("00b4903a97adfde729f0650133a7379693099d8d85d6b1b18255ca70bf89e31d").role(ObjectRole.OWNER) + .etag("CIix/dmj/rwCEAE=").build(); + + } + +} diff --git a/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/parse/ObjectAclListTest.java b/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/parse/ObjectAclListTest.java new file mode 100644 index 0000000000..6cd98ae34b --- /dev/null +++ b/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/parse/ObjectAclListTest.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.jclouds.googlecloudstorage.parse; + +import java.net.URI; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.ObjectRole; +import org.jclouds.googlecloudstorage.domain.ListObjectAccessControls; +import org.jclouds.googlecloudstorage.domain.ObjectAccessControls; +import org.jclouds.googlecloudstorage.domain.Resource.Kind; +import org.jclouds.googlecloudstorage.internal.BaseGoogleCloudStorageParseTest; + +import com.google.common.collect.ImmutableSet; + +public class ObjectAclListTest extends BaseGoogleCloudStorageParseTest { + + private ObjectAccessControls item1 = ObjectAccessControls + .builder() + .id("jcloudtestbucket/foo.txt/1394121608485000/user-00b4903a97adfde729f0650133a7379693099d8d85d6b1b18255ca70bf89e31d") + .selfLink( + URI.create("https://www.googleapis.com/storage/v1/b/jcloudtestbucket/o/foo.txt/acl/user-00b4903a97adfde729f0650133a7379693099d8d85d6b1b18255ca70bf89e31d")) + .bucket("jcloudtestbucket").object("foo.txt").generation(Long.valueOf("1394121608485000")) + .entity("user-00b4903a97adfde729f0650133a7379693099d8d85d6b1b18255ca70bf89e31d") + .entityId("00b4903a97adfde729f0650133a7379693099d8d85d6b1b18255ca70bf89e31d").role(ObjectRole.OWNER) + .etag("CIix/dmj/rwCEAE=").build(); + + @Override + public String resource() { + return "/objectacl_list.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public ListObjectAccessControls expected() { + return ListObjectAccessControls.builder().kind(Kind.OBJECT_ACCESS_CONTROLS).items(ImmutableSet.of(item1)).build(); + } + +} diff --git a/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/parse/ObjectAclUpdateTest.java b/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/parse/ObjectAclUpdateTest.java new file mode 100644 index 0000000000..7953f87af7 --- /dev/null +++ b/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/parse/ObjectAclUpdateTest.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.jclouds.googlecloudstorage.parse; + +import java.net.URI; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.googlecloudstorage.domain.DomainResourceRefferences.ObjectRole; +import org.jclouds.googlecloudstorage.domain.ObjectAccessControls; +import org.jclouds.googlecloudstorage.internal.BaseGoogleCloudStorageParseTest; + +public class ObjectAclUpdateTest extends BaseGoogleCloudStorageParseTest { + + @Override + public String resource() { + return "/objectacl_update_response.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public ObjectAccessControls expected() { + return ObjectAccessControls.builder() + .selfLink(URI.create("https://www.googleapis.com/storage/v1/b/jcloudtestbucket/o/foo.txt/acl/allUsers")) + .bucket("jcloudtestbucket").object("foo.txt").entity("allUsers").role(ObjectRole.OWNER) + .etag("CIix/dmj/rwCEAQ=").build(); + } + +} diff --git a/providers/google-cloud-storage/src/test/resources/objectacl_get.json b/providers/google-cloud-storage/src/test/resources/objectacl_get.json new file mode 100644 index 0000000000..dd2417d6c5 --- /dev/null +++ b/providers/google-cloud-storage/src/test/resources/objectacl_get.json @@ -0,0 +1,15 @@ +{ + "kind": "storage#objectAccessControl", + "id": "jcloudtestbucket/foo.txt/1394121608485000/project-owners-1082289308625", + "selfLink": "https://www.googleapis.com/storage/v1/b/jcloudtestbucket/o/foo.txt/acl/project-owners-1082289308625", + "bucket": "jcloudtestbucket", + "object": "foo.txt", + "generation": "1394121608485000", + "entity": "project-owners-1082289308625", + "role": "OWNER", + "projectTeam": { + "projectNumber": "1082289308625", + "team": "owners" + }, + "etag": "CIix/dmj/rwCEAE=" +} diff --git a/providers/google-cloud-storage/src/test/resources/objectacl_insert_requestpayload.json b/providers/google-cloud-storage/src/test/resources/objectacl_insert_requestpayload.json new file mode 100644 index 0000000000..393c571c35 --- /dev/null +++ b/providers/google-cloud-storage/src/test/resources/objectacl_insert_requestpayload.json @@ -0,0 +1,4 @@ +{ + "entity": "user-00b4903a97adfde729f0650133a7379693099d8d85d6b1b18255ca70bf89e31d", + "role": "OWNER" +} diff --git a/providers/google-cloud-storage/src/test/resources/objectacl_insert_response.json b/providers/google-cloud-storage/src/test/resources/objectacl_insert_response.json new file mode 100644 index 0000000000..1a477b889b --- /dev/null +++ b/providers/google-cloud-storage/src/test/resources/objectacl_insert_response.json @@ -0,0 +1,10 @@ +{ + "kind": "storage#objectAccessControl", + "selfLink": "https://www.googleapis.com/storage/v1/b/jcloudtestbucket/o/foo.txt/acl/user-00b4903a97adfde729f0650133a7379693099d8d85d6b1b18255ca70bf89e31d", + "bucket": "jcloudtestbucket", + "object": "foo.txt", + "entity": "user-00b4903a97adfde729f0650133a7379693099d8d85d6b1b18255ca70bf89e31d", + "role": "OWNER", + "entityId": "00b4903a97adfde729f0650133a7379693099d8d85d6b1b18255ca70bf89e31d", + "etag": "CIix/dmj/rwCEAE=" +} diff --git a/providers/google-cloud-storage/src/test/resources/objectacl_list.json b/providers/google-cloud-storage/src/test/resources/objectacl_list.json new file mode 100644 index 0000000000..9a7a677ea5 --- /dev/null +++ b/providers/google-cloud-storage/src/test/resources/objectacl_list.json @@ -0,0 +1,17 @@ +{ + "kind": "storage#objectAccessControls", + "items": [ + { + "kind": "storage#objectAccessControl", + "id": "jcloudtestbucket/foo.txt/1394121608485000/user-00b4903a97adfde729f0650133a7379693099d8d85d6b1b18255ca70bf89e31d", + "selfLink": "https://www.googleapis.com/storage/v1/b/jcloudtestbucket/o/foo.txt/acl/user-00b4903a97adfde729f0650133a7379693099d8d85d6b1b18255ca70bf89e31d", + "bucket": "jcloudtestbucket", + "object": "foo.txt", + "generation": "1394121608485000", + "entity": "user-00b4903a97adfde729f0650133a7379693099d8d85d6b1b18255ca70bf89e31d", + "role": "OWNER", + "entityId": "00b4903a97adfde729f0650133a7379693099d8d85d6b1b18255ca70bf89e31d", + "etag": "CIix/dmj/rwCEAE=" + } + ] +} diff --git a/providers/google-cloud-storage/src/test/resources/objectacl_request_payload.json b/providers/google-cloud-storage/src/test/resources/objectacl_request_payload.json new file mode 100644 index 0000000000..6bb36306c3 --- /dev/null +++ b/providers/google-cloud-storage/src/test/resources/objectacl_request_payload.json @@ -0,0 +1,4 @@ +{ + "entity": "allUsers", + "role": "OWNER" +} diff --git a/providers/google-cloud-storage/src/test/resources/objectacl_update_initial.json b/providers/google-cloud-storage/src/test/resources/objectacl_update_initial.json new file mode 100644 index 0000000000..c3ee980bb0 --- /dev/null +++ b/providers/google-cloud-storage/src/test/resources/objectacl_update_initial.json @@ -0,0 +1,9 @@ +{ + "kind": "storage#objectAccessControl", + "selfLink": "https://www.googleapis.com/storage/v1/b/jcloudtestbucket/o/foo.txt/acl/allUsers", + "bucket": "jcloudtestbucket", + "object": "foo.txt", + "entity": "allUsers", + "role": "OWNER", + "etag": "CIix/dmj/rwCEAQ=" +} diff --git a/providers/google-cloud-storage/src/test/resources/objectacl_update_response.json b/providers/google-cloud-storage/src/test/resources/objectacl_update_response.json new file mode 100644 index 0000000000..c3ee980bb0 --- /dev/null +++ b/providers/google-cloud-storage/src/test/resources/objectacl_update_response.json @@ -0,0 +1,9 @@ +{ + "kind": "storage#objectAccessControl", + "selfLink": "https://www.googleapis.com/storage/v1/b/jcloudtestbucket/o/foo.txt/acl/allUsers", + "bucket": "jcloudtestbucket", + "object": "foo.txt", + "entity": "allUsers", + "role": "OWNER", + "etag": "CIix/dmj/rwCEAQ=" +}