mirror of https://github.com/apache/jclouds.git
JCLOUDS-458: Ad Object Access Controls live tests
This commit is contained in:
parent
520432903e
commit
0dee4fd774
|
@ -23,6 +23,7 @@ import javax.ws.rs.Path;
|
||||||
import org.jclouds.googlecloudstorage.features.BucketAccessControlsApi;
|
import org.jclouds.googlecloudstorage.features.BucketAccessControlsApi;
|
||||||
import org.jclouds.googlecloudstorage.features.BucketApi;
|
import org.jclouds.googlecloudstorage.features.BucketApi;
|
||||||
import org.jclouds.googlecloudstorage.features.DefaultObjectAccessControlsApi;
|
import org.jclouds.googlecloudstorage.features.DefaultObjectAccessControlsApi;
|
||||||
|
import org.jclouds.googlecloudstorage.features.ObjectAccessControlsApi;
|
||||||
import org.jclouds.rest.annotations.Delegate;
|
import org.jclouds.rest.annotations.Delegate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -52,4 +53,11 @@ public interface GoogleCloudStorageApi extends Closeable {
|
||||||
@Delegate
|
@Delegate
|
||||||
@Path("")
|
@Path("")
|
||||||
BucketApi getBucketApi();
|
BucketApi getBucketApi();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides access to Object Access Control features
|
||||||
|
*/
|
||||||
|
@Delegate
|
||||||
|
@Path("")
|
||||||
|
ObjectAccessControlsApi getObjectAccessControlsApi();
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,7 +92,8 @@ public class BucketAccessControls extends Resource {
|
||||||
if (obj == null || getClass() != obj.getClass())
|
if (obj == null || getClass() != obj.getClass())
|
||||||
return false;
|
return false;
|
||||||
BucketAccessControls that = BucketAccessControls.class.cast(obj);
|
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() {
|
protected MoreObjects.ToStringHelper string() {
|
||||||
|
|
|
@ -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<ObjectAccessControls> items;
|
||||||
|
|
||||||
|
protected ListObjectAccessControls(Kind kind, Set<ObjectAccessControls> items) {
|
||||||
|
|
||||||
|
this.kind = checkNotNull(kind, "kind");
|
||||||
|
this.items = checkNotNull(items, "items");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Kind getKind() {
|
||||||
|
return kind;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<ObjectAccessControls> 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<ObjectAccessControls> 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<ObjectAccessControls> 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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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 <a href= "https://developers.google.com/storage/docs/json_api/v1/objectAccessControls"/>
|
||||||
|
*/
|
||||||
|
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<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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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 <a href= "https://developers.google.com/storage/docs/json_api/v1/objectAccessControls"/>
|
||||||
|
*/
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -46,17 +46,17 @@ public final class ProjectTeam {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final String projectId;
|
private final String projectNumber;
|
||||||
private final Team team;
|
private final Team team;
|
||||||
|
|
||||||
|
|
||||||
private ProjectTeam(String projectId, Team team) {
|
private ProjectTeam(String projectNumber, Team team) {
|
||||||
this.projectId = projectId;
|
this.projectNumber = projectNumber;
|
||||||
this.team = team;
|
this.team = team;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getProjectId() {
|
public String getProjectNumber() {
|
||||||
return projectId;
|
return projectNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Team getTeam() {
|
public Team getTeam() {
|
||||||
|
@ -65,7 +65,7 @@ public final class ProjectTeam {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hashCode(projectId, team);
|
return Objects.hashCode(projectNumber, team);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -75,11 +75,11 @@ public final class ProjectTeam {
|
||||||
if (obj == null || getClass() != obj.getClass())
|
if (obj == null || getClass() != obj.getClass())
|
||||||
return false;
|
return false;
|
||||||
ProjectTeam that = ProjectTeam.class.cast(obj);
|
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() {
|
protected MoreObjects.ToStringHelper string() {
|
||||||
return toStringHelper(this).add("projectId", projectId).add("team", team);
|
return toStringHelper(this).add("projectNumber", projectNumber).add("team", team);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -93,11 +93,11 @@ public final class ProjectTeam {
|
||||||
|
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
|
|
||||||
private String projectId;
|
private String projectNumber;
|
||||||
private Team team;
|
private Team team;
|
||||||
|
|
||||||
public Builder projectId(String projectId) {
|
public Builder projectNumber(String projectNumber) {
|
||||||
this.projectId = projectId;
|
this.projectNumber = projectNumber;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,11 +107,11 @@ public final class ProjectTeam {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProjectTeam build() {
|
public ProjectTeam build() {
|
||||||
return new ProjectTeam(this.projectId, this.team);
|
return new ProjectTeam(this.projectNumber, this.team);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder fromProjectTeam(ProjectTeam in) {
|
public Builder fromProjectTeam(ProjectTeam in) {
|
||||||
return this.projectId(in.getProjectId()).team(in.getTeam());
|
return this.projectNumber(in.getProjectNumber()).team(in.getTeam());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 <a href = " https://developers.google.com/storage/docs/json_api/v1/objectAccessControls "/>
|
||||||
|
*/
|
||||||
|
|
||||||
|
@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);
|
||||||
|
|
||||||
|
}
|
|
@ -41,6 +41,10 @@ public class GoogleCloudStorageErrorHandler implements HttpErrorHandler {
|
||||||
: new HttpResponseException(command, response);
|
: new HttpResponseException(command, response);
|
||||||
message = message != null ? message : String.format("%s -> %s", command.getCurrentRequest().getRequestLine(),
|
message = message != null ? message : String.format("%s -> %s", command.getCurrentRequest().getRequestLine(),
|
||||||
response.getStatusLine());
|
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()) {
|
switch (response.getStatusCode()) {
|
||||||
case 401:
|
case 401:
|
||||||
case 403:
|
case 403:
|
||||||
|
@ -52,6 +56,12 @@ public class GoogleCloudStorageErrorHandler implements HttpErrorHandler {
|
||||||
case 409:
|
case 409:
|
||||||
exception = new IllegalStateException(message, exception);
|
exception = new IllegalStateException(message, exception);
|
||||||
break;
|
break;
|
||||||
|
case 411:
|
||||||
|
exception = new IllegalStateException(message411 + message, exception);
|
||||||
|
break;
|
||||||
|
case 412:
|
||||||
|
exception = new IllegalStateException(message412 + message, exception);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
command.setException(exception);
|
command.setException(exception);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) throws IllegalArgumentException{
|
||||||
|
ObjectAccessControlsTemplate postBucket = (ObjectAccessControlsTemplate) postParams.get("template");
|
||||||
|
return bindToRequest(request, postBucket);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
|
||||||
|
return jsonBinder.bindToRequest(request, input);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -40,31 +40,31 @@ public class DefaultObjectAccessControlsApiExpectTest extends BaseGoogleCloudSto
|
||||||
private static final String EXPECTED_TEST_BUCKET = "jcloudtestbucket";
|
private static final String EXPECTED_TEST_BUCKET = "jcloudtestbucket";
|
||||||
private static final String EXPECTED_TEST_GROUP_ENTITY = "group-00b4903a971ec6cff233284d6d24f5bf5cba904c4ade4d43ebd6a5d33800e68b";
|
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()
|
.builder()
|
||||||
.method("GET")
|
.method("GET")
|
||||||
.endpoint(
|
.endpoint(
|
||||||
"https://www.googleapis.com/storage/v1/b/jcloudtestbucket/defaultObjectAcl/group-00b4903a971ec6cff233284d6d24f5bf5cba904c4ade4d43ebd6a5d33800e68b")
|
"https://www.googleapis.com/storage/v1/b/jcloudtestbucket/defaultObjectAcl/group-00b4903a971ec6cff233284d6d24f5bf5cba904c4ade4d43ebd6a5d33800e68b")
|
||||||
.addHeader("Accept", "application/json").addHeader("Authorization", "Bearer " + TOKEN).build();
|
.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();
|
.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();
|
.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")
|
.endpoint("https://www.googleapis.com/storage/v1/b/jcloudtestbucket/defaultObjectAcl")
|
||||||
.addHeader("Accept", "application/json").addHeader("Authorization", "Bearer " + TOKEN).build();
|
.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();
|
.payload(staticPayloadFromResource("/default_objectacl_list.json")).build();
|
||||||
|
|
||||||
// Test getDefaultObjectAccessControls
|
// Test getDefaultObjectAccessControls
|
||||||
public void testGetDefaultObjectAclResponseIs2xx() throws Exception {
|
public void testGetDefaultObjectAclResponseIs2xx() throws Exception {
|
||||||
|
|
||||||
DefaultObjectAccessControlsApi api = requestsSendResponses(requestForScopes(STORAGE_FULLCONTROL_SCOPE),
|
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();
|
.getDefaultObjectAccessControlsApi();
|
||||||
|
|
||||||
assertEquals(api.getDefaultObjectAccessControls(EXPECTED_TEST_BUCKET, EXPECTED_TEST_GROUP_ENTITY),
|
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();
|
HttpResponse getResponse = HttpResponse.builder().statusCode(404).build();
|
||||||
|
|
||||||
DefaultObjectAccessControlsApi api = requestsSendResponses(requestForScopes(STORAGE_FULLCONTROL_SCOPE),
|
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));
|
assertNull(api.getDefaultObjectAccessControls(EXPECTED_TEST_BUCKET, EXPECTED_TEST_GROUP_ENTITY));
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,7 @@ public class DefaultObjectAccessControlsApiExpectTest extends BaseGoogleCloudSto
|
||||||
public void testListDefaultObjectAclWithNoOptionsResponseIs2xx() throws Exception {
|
public void testListDefaultObjectAclWithNoOptionsResponseIs2xx() throws Exception {
|
||||||
|
|
||||||
DefaultObjectAccessControlsApi api = requestsSendResponses(requestForScopes(STORAGE_FULLCONTROL_SCOPE),
|
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();
|
.getDefaultObjectAccessControlsApi();
|
||||||
|
|
||||||
assertEquals(api.listDefaultObjectAccessControls(EXPECTED_TEST_BUCKET), new DefaultObjectAclListTest().expected());
|
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();
|
HttpResponse listResponse = HttpResponse.builder().statusCode(404).build();
|
||||||
|
|
||||||
DefaultObjectAccessControlsApi api = requestsSendResponses(requestForScopes(STORAGE_FULLCONTROL_SCOPE),
|
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));
|
assertNull(api.listDefaultObjectAccessControls(EXPECTED_TEST_BUCKET));
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,7 @@ public class DefaultObjectAccessControlsApiExpectTest extends BaseGoogleCloudSto
|
||||||
MediaType.APPLICATION_JSON)).build();
|
MediaType.APPLICATION_JSON)).build();
|
||||||
|
|
||||||
DefaultObjectAccessControlsApi api = requestsSendResponses(requestForScopes(STORAGE_FULLCONTROL_SCOPE),
|
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(
|
DefaultObjectAccessControlsTemplate template = new DefaultObjectAccessControlsTemplate().entity("allUsers").role(
|
||||||
ObjectRole.OWNER);
|
ObjectRole.OWNER);
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -42,7 +42,7 @@ public class BucketAclListTest extends BaseGoogleCloudStorageParseTest<ListBucke
|
||||||
.id("jcloudtestbucket/project-owners-1082289308625")
|
.id("jcloudtestbucket/project-owners-1082289308625")
|
||||||
.selfLink(
|
.selfLink(
|
||||||
URI.create("https://content.googleapis.com/storage/v1/b/jcloudtestbucket/acl/project-owners-1082289308625"))
|
URI.create("https://content.googleapis.com/storage/v1/b/jcloudtestbucket/acl/project-owners-1082289308625"))
|
||||||
.projectTeam(ProjectTeam.builder().projectId("1082289308625").team(Team.OWNERS).build())
|
.projectTeam(ProjectTeam.builder().projectNumber("1082289308625").team(Team.OWNERS).build())
|
||||||
.bucket("jcloudtestbucket").entity("project-owners-1082289308625").role(Role.OWNER).etag("CAc=").build();
|
.bucket("jcloudtestbucket").entity("project-owners-1082289308625").role(Role.OWNER).etag("CAc=").build();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -36,7 +36,7 @@ public class DefaultObjectAclGetTest extends BaseGoogleCloudStorageParseTest<Def
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
public DefaultObjectAccessControls expected() {
|
public DefaultObjectAccessControls expected() {
|
||||||
return DefaultObjectAccessControls.builder().entity("project-owners-1082289308625").role(ObjectRole.OWNER)
|
return DefaultObjectAccessControls.builder().entity("project-owners-1082289308625").role(ObjectRole.OWNER)
|
||||||
.etag("CAk=").projectTeam(ProjectTeam.builder().projectId("1082289308625").team(Team.OWNERS).build())
|
.etag("CAk=").projectTeam(ProjectTeam.builder().projectNumber("1082289308625").team(Team.OWNERS).build())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ public class DefaultObjectAclListTest extends BaseGoogleCloudStorageParseTest<Li
|
||||||
|
|
||||||
private DefaultObjectAccessControls item_1 = DefaultObjectAccessControls.builder()
|
private DefaultObjectAccessControls item_1 = DefaultObjectAccessControls.builder()
|
||||||
.entity("project-owners-1082289308625").role(ObjectRole.OWNER)
|
.entity("project-owners-1082289308625").role(ObjectRole.OWNER)
|
||||||
.projectTeam(ProjectTeam.builder().projectId("1082289308625").team(Team.OWNERS).build()).etag("CAk=")
|
.projectTeam(ProjectTeam.builder().projectNumber("1082289308625").team(Team.OWNERS).build()).etag("CAk=")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -43,7 +43,7 @@ public class FullBucketGetTest extends BaseGoogleCloudStorageParseTest<Bucket> {
|
||||||
.selfLink(
|
.selfLink(
|
||||||
URI.create("https://www.googleapis.com/storage/v1/b/jcloudtestbucket3500/acl/project-owners-1082289308625"))
|
URI.create("https://www.googleapis.com/storage/v1/b/jcloudtestbucket3500/acl/project-owners-1082289308625"))
|
||||||
.bucket("jcloudtestbucket3500").entity("project-owners-1082289308625").role(Role.OWNER)
|
.bucket("jcloudtestbucket3500").entity("project-owners-1082289308625").role(Role.OWNER)
|
||||||
.projectTeam(ProjectTeam.builder().projectId("1082289308625").team(Team.OWNERS).build()).etag("CAo=")
|
.projectTeam(ProjectTeam.builder().projectNumber("1082289308625").team(Team.OWNERS).build()).etag("CAo=")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
private final DefaultObjectAccessControls defObjectAcl = DefaultObjectAccessControls.builder()
|
private final DefaultObjectAccessControls defObjectAcl = DefaultObjectAccessControls.builder()
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
/*
|
||||||
|
* 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.domain.internal.ProjectTeam;
|
||||||
|
import org.jclouds.googlecloudstorage.domain.internal.ProjectTeam.Team;
|
||||||
|
import org.jclouds.googlecloudstorage.internal.BaseGoogleCloudStorageParseTest;
|
||||||
|
|
||||||
|
public class ObjectAclGetTest extends BaseGoogleCloudStorageParseTest<ObjectAccessControls> {
|
||||||
|
|
||||||
|
@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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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<ObjectAccessControls> {
|
||||||
|
|
||||||
|
@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();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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<ListObjectAccessControls> {
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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<ObjectAccessControls> {
|
||||||
|
|
||||||
|
@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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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="
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"entity": "user-00b4903a97adfde729f0650133a7379693099d8d85d6b1b18255ca70bf89e31d",
|
||||||
|
"role": "OWNER"
|
||||||
|
}
|
|
@ -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="
|
||||||
|
}
|
|
@ -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="
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"entity": "allUsers",
|
||||||
|
"role": "OWNER"
|
||||||
|
}
|
|
@ -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="
|
||||||
|
}
|
|
@ -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="
|
||||||
|
}
|
Loading…
Reference in New Issue