mirror of https://github.com/apache/jclouds.git
JCLOUDS-458: Added Default object access control
This commit is contained in:
parent
3be957c9cd
commit
b7441ba83b
|
@ -18,10 +18,23 @@ package org.jclouds.googlecloudstorage;
|
||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
|
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
|
||||||
|
import org.jclouds.googlecloudstorage.features.DefaultObjectAccessControlsApi;
|
||||||
|
import org.jclouds.rest.annotations.Delegate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provide access to GoogleCloudStorage
|
* Provide access to GoogleCloudStorage
|
||||||
*
|
*
|
||||||
* @see <a href="https://developers.google.com/storage/docs/json_api/v1/">api doc /a>
|
* @see <a href="https://developers.google.com/storage/docs/json_api/v1/">api doc /a>
|
||||||
*/
|
*/
|
||||||
public interface GoogleCloudStorageApi extends Closeable {
|
public interface GoogleCloudStorageApi extends Closeable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides access to Default Object Access Control features on bucket
|
||||||
|
*/
|
||||||
|
@Delegate
|
||||||
|
@Path("")
|
||||||
|
DefaultObjectAccessControlsApi getDefaultObjectAccessControlsApi();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,251 @@
|
||||||
|
/*
|
||||||
|
* 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.Objects.toStringHelper;
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.beans.ConstructorProperties;
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
import org.jclouds.googlecloudstorage.features.ApiResourceRefferences.ObjectRole;
|
||||||
|
|
||||||
|
import com.google.common.base.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a DefaultObjectAccessControls Resource
|
||||||
|
*
|
||||||
|
* @see <a href= "https://developers.google.com/storage/docs/json_api/v1/defaultObjectAccessControls"/>
|
||||||
|
*/
|
||||||
|
public class DefaultObjectAccessControls extends Resource {
|
||||||
|
|
||||||
|
protected final String bucket;
|
||||||
|
protected final String entity;
|
||||||
|
protected final ObjectRole role;
|
||||||
|
protected final String email;
|
||||||
|
protected final String entityId;
|
||||||
|
protected final String domain;
|
||||||
|
protected final ProjectTeam projectTeam;
|
||||||
|
|
||||||
|
protected DefaultObjectAccessControls(String id, URI selfLink, String etag, String bucket, String entity,
|
||||||
|
String entityId, ObjectRole role, String email, String domain, ProjectTeam projectTeam) {
|
||||||
|
super(Kind.OBJECT_ACCESS_CONTROL, id, selfLink, etag);
|
||||||
|
|
||||||
|
this.bucket = bucket;
|
||||||
|
this.entity = checkNotNull(entity, "entity");
|
||||||
|
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 getDomain() {
|
||||||
|
return domain;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEntityId() {
|
||||||
|
return entityId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProjectTeam getProjectTeam() {
|
||||||
|
return projectTeam;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ProjectTeam {
|
||||||
|
|
||||||
|
public enum Team {
|
||||||
|
owners, editors, viewers;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final String projectId;
|
||||||
|
private final Team team;
|
||||||
|
|
||||||
|
@ConstructorProperties({ "projectId", "team" })
|
||||||
|
public ProjectTeam(String projectId, Team team) {
|
||||||
|
this.projectId = projectId;
|
||||||
|
this.team = team;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProjectId() {
|
||||||
|
return projectId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Team getTeam() {
|
||||||
|
return team;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hashCode(projectId, team);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
if (obj == null || getClass() != obj.getClass())
|
||||||
|
return false;
|
||||||
|
ProjectTeam that = ProjectTeam.class.cast(obj);
|
||||||
|
return equal(this.projectId, that.projectId) && equal(this.team, that.team);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Objects.ToStringHelper string() {
|
||||||
|
return toStringHelper(this).add("projectId", projectId).add("team", team);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return string().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder {
|
||||||
|
|
||||||
|
private String projectId;
|
||||||
|
private Team team;
|
||||||
|
|
||||||
|
public Builder projectId(String projectId) {
|
||||||
|
this.projectId = projectId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder team(Team team) {
|
||||||
|
this.team = team;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProjectTeam build() {
|
||||||
|
return new ProjectTeam(this.projectId, this.team);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder fromProjectTeam(ProjectTeam in) {
|
||||||
|
return this.projectId(in.getProjectId()).team(in.getTeam());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
if (obj == null || getClass() != obj.getClass())
|
||||||
|
return false;
|
||||||
|
DefaultObjectAccessControls that = DefaultObjectAccessControls.class.cast(obj);
|
||||||
|
return equal(this.kind, that.kind) && equal(this.entity, that.entity) && equal(this.role, that.role);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Objects.ToStringHelper string() {
|
||||||
|
return super.string().omitNullValues().add("bucket", bucket).add("entity", entity).add("entityId", entityId)
|
||||||
|
.add("role", role).add("email", email).add("domain", domain);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hashCode(kind, 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 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 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 DefaultObjectAccessControls build() {
|
||||||
|
return new DefaultObjectAccessControls(super.id, super.selfLink, super.etag, bucket, entity, entityId, role,
|
||||||
|
email, domain, projectTeam);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder fromObjectAccessControls(DefaultObjectAccessControls in) {
|
||||||
|
return super.fromResource(in).bucket(in.getBucket()).entity(in.getEntity()).entityId(in.getEntityId())
|
||||||
|
.role(in.getRole()).email(in.getEmail()).domain(in.getDomain()).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.features.ApiResourceRefferences.ObjectRole;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a Object Access Control Resource
|
||||||
|
*
|
||||||
|
* @see <a href= "https://developers.google.com/storage/docs/json_api/v1/objectAccessControls"/>
|
||||||
|
*/
|
||||||
|
public class DefaultObjectAccessControlsTemplate {
|
||||||
|
|
||||||
|
protected String entity;
|
||||||
|
protected ObjectRole role;
|
||||||
|
|
||||||
|
public DefaultObjectAccessControlsTemplate role(ObjectRole role) {
|
||||||
|
this.role = role;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DefaultObjectAccessControlsTemplate 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 DefaultObjectAccessControlsTemplate fromObjectAccessControlsTemplate(
|
||||||
|
DefaultObjectAccessControlsTemplate objectAccessControlsTemplate) {
|
||||||
|
return Builder.fromObjectAccessControlsTemplate(objectAccessControlsTemplate);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder {
|
||||||
|
|
||||||
|
public static DefaultObjectAccessControlsTemplate fromObjectAccessControlsTemplate(
|
||||||
|
DefaultObjectAccessControlsTemplate in) {
|
||||||
|
return new DefaultObjectAccessControlsTemplate().role(in.getRole()).entity(in.getEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,113 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents the structure of a response from DefaultObjectAccessControls list operation
|
||||||
|
* @see <a href= "https://developers.google.com/storage/docs/json_api/v1/defaultObjectAccessControls/list"/>
|
||||||
|
*/
|
||||||
|
|
||||||
|
import static com.google.common.base.Objects.equal;
|
||||||
|
import static com.google.common.base.Objects.toStringHelper;
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.jclouds.googlecloudstorage.domain.Resource.Kind;
|
||||||
|
|
||||||
|
import com.google.common.base.Objects;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
|
public class ListDefaultObjectAccessControls {
|
||||||
|
|
||||||
|
protected final Kind kind;
|
||||||
|
protected final Set<DefaultObjectAccessControls> items;
|
||||||
|
|
||||||
|
protected ListDefaultObjectAccessControls(Kind kind, Set<DefaultObjectAccessControls> items) {
|
||||||
|
|
||||||
|
this.kind = checkNotNull(kind, "kind");
|
||||||
|
this.items = checkNotNull(items, "items");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Kind getKind() {
|
||||||
|
return kind;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<DefaultObjectAccessControls> getItems() {
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
if (obj == null || getClass() != obj.getClass())
|
||||||
|
return false;
|
||||||
|
ListDefaultObjectAccessControls that = ListDefaultObjectAccessControls.class.cast(obj);
|
||||||
|
return equal(this.kind, that.kind) && equal(this.items, that.items);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Objects.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().fromListDefaultObjectAccessControls(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class Builder {
|
||||||
|
|
||||||
|
private Kind kind;
|
||||||
|
private ImmutableSet.Builder<DefaultObjectAccessControls> items = ImmutableSet.builder();
|
||||||
|
|
||||||
|
public Builder kind(Kind kind) {
|
||||||
|
this.kind = kind;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder addItems(DefaultObjectAccessControls defaultObjectAccessControls) {
|
||||||
|
this.items.add(defaultObjectAccessControls);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder items(Set<DefaultObjectAccessControls> items) {
|
||||||
|
this.items.addAll(items);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ListDefaultObjectAccessControls build() {
|
||||||
|
return new ListDefaultObjectAccessControls(this.kind, items.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder fromListDefaultObjectAccessControls(ListDefaultObjectAccessControls in) {
|
||||||
|
return this.kind(in.getKind()).items(in.getItems());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,132 @@
|
||||||
|
/*
|
||||||
|
* 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.Objects.toStringHelper;
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.beans.ConstructorProperties;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import org.jclouds.collect.IterableWithMarker;
|
||||||
|
import org.jclouds.googlecloudstorage.domain.Resource.Kind;
|
||||||
|
|
||||||
|
import com.google.common.base.Objects;
|
||||||
|
import com.google.common.base.Optional;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The collection returned from any <code>listFirstPage()</code> method.
|
||||||
|
*/
|
||||||
|
public class ListPage<T> extends IterableWithMarker<T> {
|
||||||
|
|
||||||
|
private final Kind kind;
|
||||||
|
private final String nextPageToken;
|
||||||
|
private final Iterable<T> items;
|
||||||
|
|
||||||
|
@ConstructorProperties({ "kind", "nextPageToken", "items" })
|
||||||
|
protected ListPage(Kind kind, String nextPageToken, Iterable<T> items) {
|
||||||
|
|
||||||
|
this.kind = checkNotNull(kind, "kind");
|
||||||
|
this.nextPageToken = nextPageToken;
|
||||||
|
this.items = items != null ? ImmutableSet.copyOf(items) : ImmutableSet.<T> of();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Kind getKind() {
|
||||||
|
return kind;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<Object> nextMarker() {
|
||||||
|
return Optional.<Object> fromNullable(nextPageToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterator<T> iterator() {
|
||||||
|
return checkNotNull(items, "items").iterator();
|
||||||
|
}
|
||||||
|
|
||||||
|
@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;
|
||||||
|
ListPage<?> that = ListPage.class.cast(obj);
|
||||||
|
return equal(this.kind, that.kind) && equal(this.items, that.items);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Objects.ToStringHelper string() {
|
||||||
|
return toStringHelper(this).omitNullValues().add("kind", kind).add("nextPageToken", nextPageToken)
|
||||||
|
.add("items", items);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return string().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Builder<T> builder() {
|
||||||
|
return new Builder<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder<T> toBuilder() {
|
||||||
|
return new Builder<T>().fromPagedList(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class Builder<T> {
|
||||||
|
|
||||||
|
private Kind kind;
|
||||||
|
private String nextPageToken;
|
||||||
|
private ImmutableSet.Builder<T> items = ImmutableSet.builder();
|
||||||
|
|
||||||
|
public Builder<T> kind(Kind kind) {
|
||||||
|
this.kind = kind;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder<T> addItem(T item) {
|
||||||
|
this.items.add(item);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder<T> items(Iterable<T> items) {
|
||||||
|
this.items.addAll(items);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder<T> nextPageToken(String nextPageToken) {
|
||||||
|
this.nextPageToken = nextPageToken;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ListPage<T> build() {
|
||||||
|
return new ListPage<T>(kind, nextPageToken, items.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder<T> fromPagedList(ListPage<T> in) {
|
||||||
|
return this.kind(in.getKind()).nextPageToken((String) in.nextMarker().orNull()).items(in);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,165 @@
|
||||||
|
/*
|
||||||
|
* 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.ToStringHelper;
|
||||||
|
import static com.google.common.base.Objects.equal;
|
||||||
|
import static com.google.common.base.Objects.toStringHelper;
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.beans.ConstructorProperties;
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
import com.google.common.base.CaseFormat;
|
||||||
|
import com.google.common.base.Joiner;
|
||||||
|
import com.google.common.base.Objects;
|
||||||
|
import com.google.common.base.Splitter;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base class for Google Cloud Storage resources.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class Resource {
|
||||||
|
|
||||||
|
public enum Kind {
|
||||||
|
BUCKET_ACCESS_CONTROL, BUCKET_ACCESS_CONTROLS, BUCKET, BUCKETS, OBJECT_ACCESS_CONTROL, OBJECT_ACCESS_CONTROLS, OBJECT;
|
||||||
|
|
||||||
|
public String value() {
|
||||||
|
return Joiner.on("#").join("storage", CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return value();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Kind fromValue(String kind) {
|
||||||
|
return valueOf(CaseFormat.LOWER_CAMEL.to(CaseFormat
|
||||||
|
.UPPER_UNDERSCORE,
|
||||||
|
Iterables.getLast(Splitter.on("#").split(checkNotNull(kind,
|
||||||
|
"kind")))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final Kind kind;
|
||||||
|
protected final String id;
|
||||||
|
protected final URI selfLink;
|
||||||
|
protected final String etag;
|
||||||
|
|
||||||
|
@ConstructorProperties({ "kind", "id", "selfLink", "etag" })
|
||||||
|
protected Resource(Kind kind, String id, URI selfLink, String etag) {
|
||||||
|
this.kind = checkNotNull(kind, "kind");
|
||||||
|
this.id = id;
|
||||||
|
this.selfLink = selfLink;
|
||||||
|
this.etag = etag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Kind getKind() {
|
||||||
|
return kind;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public URI getSelfLink() {
|
||||||
|
return selfLink;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEtag() {
|
||||||
|
return etag;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hashCode(kind, id, selfLink, etag);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
if (obj == null || getClass() != obj.getClass())
|
||||||
|
return false;
|
||||||
|
Resource that = Resource.class.cast(obj);
|
||||||
|
return equal(this.kind, that.kind) && equal(this.id, that.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ToStringHelper string() {
|
||||||
|
return toStringHelper(this).omitNullValues().add("kind", kind).add("id", id).add("selfLink", selfLink)
|
||||||
|
.add("etag", etag);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return string().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Builder<?> builder() {
|
||||||
|
return new ConcreteBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder<?> toBuilder() {
|
||||||
|
return new ConcreteBuilder().fromResource(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract static class Builder<T extends Builder<T>> {
|
||||||
|
|
||||||
|
protected abstract T self();
|
||||||
|
|
||||||
|
protected Kind kind;
|
||||||
|
protected String id;
|
||||||
|
protected URI selfLink;
|
||||||
|
protected String etag;
|
||||||
|
|
||||||
|
protected T kind(Kind kind) {
|
||||||
|
this.kind = kind;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T id(String id) {
|
||||||
|
this.id = id;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T selfLink(URI selfLink) {
|
||||||
|
this.selfLink = selfLink;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T etag(String etag) {
|
||||||
|
this.etag = etag;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Resource build() {
|
||||||
|
return new Resource(kind, id, selfLink, etag);
|
||||||
|
}
|
||||||
|
|
||||||
|
public T fromResource(Resource in) {
|
||||||
|
return this.kind(in.getKind()).id(in.getId()).selfLink(in.getSelfLink()).etag(in.getEtag());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||||
|
@Override
|
||||||
|
protected ConcreteBuilder self() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,63 @@
|
||||||
|
/*
|
||||||
|
* 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 com.google.common.base.CaseFormat;
|
||||||
|
|
||||||
|
public final class ApiResourceRefferences {
|
||||||
|
|
||||||
|
private ApiResourceRefferences() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum ObjectRole {
|
||||||
|
READER, OWNER
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Projection {
|
||||||
|
NO_ACL, FULL;
|
||||||
|
|
||||||
|
public String value() {
|
||||||
|
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return value();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Projection fromValue(String projection) {
|
||||||
|
return valueOf(CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, projection));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum PredefinedAcl {
|
||||||
|
AUTHENTICATED_READ, PRIVATE, PROJEECT_PRIVATE, PUBLIC_READ, PUBLIC_READ_WRITE;
|
||||||
|
|
||||||
|
public String value() {
|
||||||
|
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return value();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PredefinedAcl fromValue(String predefinedAcl) {
|
||||||
|
return valueOf(CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, predefinedAcl));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,219 @@
|
||||||
|
/*
|
||||||
|
* 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.DefaultObjectAccessControls;
|
||||||
|
import org.jclouds.googlecloudstorage.domain.ListDefaultObjectAccessControls;
|
||||||
|
import org.jclouds.googlecloudstorage.domain.DefaultObjectAccessControlsTemplate;
|
||||||
|
import org.jclouds.googlecloudstorage.features.ApiResourceRefferences.ObjectRole;
|
||||||
|
import org.jclouds.googlecloudstorage.handlers.DefaultObjectAccessControlsBinder;
|
||||||
|
import org.jclouds.http.HttpResponse;
|
||||||
|
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 DefaultObjectAccessControl entities via their REST API.
|
||||||
|
*
|
||||||
|
* @see <a href = " https://developers.google.com/storage/docs/json_api/v1/defaultObjectAccessControls"/>
|
||||||
|
*/
|
||||||
|
|
||||||
|
@SkipEncoding({ '/', '=' })
|
||||||
|
@RequestFilters(OAuthAuthenticator.class)
|
||||||
|
public interface DefaultObjectAccessControlsApi {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the ACL entry for the specified entity on the specified object.
|
||||||
|
*
|
||||||
|
* @param bucketName
|
||||||
|
* Name of the bucket which contains the object
|
||||||
|
* @param entity
|
||||||
|
* The entity holding the permission. Can be user-userId, user-emailAddress, group-groupId,
|
||||||
|
* group-emailAddress, allUsers, or allAuthenticatedUsers
|
||||||
|
*
|
||||||
|
* @return an DefaultObjectAccessControls resource
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Named("DefaultObjectAccessControls:get")
|
||||||
|
@GET
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Path("/b/{bucket}/defaultObjectAcl/{entity}")
|
||||||
|
@OAuthScopes(STORAGE_FULLCONTROL_SCOPE)
|
||||||
|
@Fallback(NullOnNotFoundOr404.class)
|
||||||
|
@Nullable
|
||||||
|
DefaultObjectAccessControls getDefaultObjectAccessControls(@PathParam("bucket") String bucketName,
|
||||||
|
@PathParam("entity") String entity);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 DefaultObjectAccessControls
|
||||||
|
* resource with the following properties
|
||||||
|
*
|
||||||
|
* @return If successful, this method returns a DefaultObjectAccessControls resource
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Named("DefaultObjectAccessControls:insert")
|
||||||
|
@POST
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Path("/b/{bucket}/defaultObjectAcl")
|
||||||
|
@OAuthScopes(STORAGE_FULLCONTROL_SCOPE)
|
||||||
|
@MapBinder(DefaultObjectAccessControlsBinder.class)
|
||||||
|
DefaultObjectAccessControls createDefaultObjectAccessControls(@PathParam("bucket") String bucketName,
|
||||||
|
@PayloadParam("template") DefaultObjectAccessControlsTemplate template);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Permanently deletes the DefaultObjectAcessControl entry for the specified entity on the specified bucket.
|
||||||
|
*
|
||||||
|
* @param bucketName
|
||||||
|
* Name of the bucket which contains the object
|
||||||
|
* @param entity
|
||||||
|
* The entity holding the permission. Can be user-userId, user-emailAddress, group-groupId,
|
||||||
|
* group-emailAddress, allUsers, or allAuthenticatedUsers
|
||||||
|
*
|
||||||
|
* @return If successful, this method returns an empty response body
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Named("DefaultObjectAccessControls:delete")
|
||||||
|
@DELETE
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Path("/b/{bucket}/defaultObjectAcl/{entity}")
|
||||||
|
@OAuthScopes(STORAGE_FULLCONTROL_SCOPE)
|
||||||
|
@Fallback(NullOnNotFoundOr404.class)
|
||||||
|
@Nullable
|
||||||
|
HttpResponse deleteDefaultObjectAccessControls(@PathParam("bucket") String bucketName,
|
||||||
|
@PathParam("entity") String entity);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 ListObjectAccessControls resource
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Named("DefaultObjectAccessControls:list")
|
||||||
|
@GET
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Path("/b/{bucket}/defaultObjectAcl")
|
||||||
|
@OAuthScopes(STORAGE_FULLCONTROL_SCOPE)
|
||||||
|
@Fallback(NullOnNotFoundOr404.class)
|
||||||
|
@Nullable
|
||||||
|
ListDefaultObjectAccessControls listDefaultObjectAccessControls(@PathParam("bucket") String bucketName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves ACL entries on a specified object
|
||||||
|
*
|
||||||
|
* @param bucketName
|
||||||
|
* Name of the bucket which contains the object
|
||||||
|
* @param generation
|
||||||
|
* If present, selects a specific revision of this object
|
||||||
|
*
|
||||||
|
* @return DefaultObjectAccessControls resource
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Named("DefaultObjectAccessControls:update")
|
||||||
|
@PUT
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Path("/b/{bucket}/defaultObjectAcl/{entity}")
|
||||||
|
@OAuthScopes(STORAGE_FULLCONTROL_SCOPE)
|
||||||
|
@Fallback(NullOnNotFoundOr404.class)
|
||||||
|
DefaultObjectAccessControls updateDefaultObjectAccessControls(@PathParam("bucket") String bucketName,
|
||||||
|
@PathParam("entity") String entity,
|
||||||
|
@BinderParam(BindToJsonPayload.class) DefaultObjectAccessControls payload);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves ACL entries on a specified object
|
||||||
|
*
|
||||||
|
* @param bucketName
|
||||||
|
* Name of the bucket which contains the object
|
||||||
|
* @param generation
|
||||||
|
* If present, selects a specific revision of this object
|
||||||
|
*
|
||||||
|
* @return DefaultObjectAccessControls resource
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Named("DefaultObjectAccessControls:update")
|
||||||
|
@PUT
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Path("/b/{bucket}/defaultObjectAcl/{entity}")
|
||||||
|
@OAuthScopes(STORAGE_FULLCONTROL_SCOPE)
|
||||||
|
@Fallback(NullOnNotFoundOr404.class)
|
||||||
|
DefaultObjectAccessControls updateDefaultObjectAccessControls(@PathParam("bucket") String bucketName,
|
||||||
|
@PathParam("entity") String entity,
|
||||||
|
@BinderParam(BindToJsonPayload.class) DefaultObjectAccessControls payload,
|
||||||
|
@QueryParam("role") ObjectRole role);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves ACL entries on a specified object
|
||||||
|
*
|
||||||
|
* @param bucketName
|
||||||
|
* Name of the bucket which contains the object
|
||||||
|
* @param generation
|
||||||
|
* If present, selects a specific revision of this object
|
||||||
|
*
|
||||||
|
* @return DefaultObjectAccessControls resource
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Named("DefaultObjectAccessControls:patch")
|
||||||
|
@PATCH
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Path("/b/{bucket}/defaultObjectAcl/{entity}")
|
||||||
|
@OAuthScopes(STORAGE_FULLCONTROL_SCOPE)
|
||||||
|
@Fallback(NullOnNotFoundOr404.class)
|
||||||
|
DefaultObjectAccessControls patchDefaultObjectAccessControls(@PathParam("bucket") String bucketName,
|
||||||
|
@PathParam("entity") String entity,
|
||||||
|
@BinderParam(BindToJsonPayload.class) DefaultObjectAccessControls payload);
|
||||||
|
}
|
|
@ -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.DefaultObjectAccessControlsTemplate;
|
||||||
|
import org.jclouds.http.HttpRequest;
|
||||||
|
import org.jclouds.rest.MapBinder;
|
||||||
|
import org.jclouds.rest.binders.BindToJsonPayload;
|
||||||
|
|
||||||
|
public class DefaultObjectAccessControlsBinder implements MapBinder {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private BindToJsonPayload jsonBinder;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
|
||||||
|
DefaultObjectAccessControlsTemplate template = (DefaultObjectAccessControlsTemplate) postParams.get("template");
|
||||||
|
return bindToRequest(request, template);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
|
||||||
|
return jsonBinder.bindToRequest(request, input);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,224 @@
|
||||||
|
/*
|
||||||
|
* 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.DefaultObjectAccessControls;
|
||||||
|
import org.jclouds.googlecloudstorage.domain.DefaultObjectAccessControlsTemplate;
|
||||||
|
import org.jclouds.googlecloudstorage.features.ApiResourceRefferences.ObjectRole;
|
||||||
|
import org.jclouds.googlecloudstorage.internal.BaseGoogleCloudStorageApiExpectTest;
|
||||||
|
import org.jclouds.googlecloudstorage.parse.DefaultObjectAclGetTest;
|
||||||
|
import org.jclouds.googlecloudstorage.parse.DefaultObjectAclInsertTest;
|
||||||
|
import org.jclouds.googlecloudstorage.parse.DefaultObjectAclListTest;
|
||||||
|
import org.jclouds.http.HttpRequest;
|
||||||
|
import org.jclouds.http.HttpResponse;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@Test(groups = "unit")
|
||||||
|
public class DefaultObjectAccessControlsApiExpectTest extends BaseGoogleCloudStorageApiExpectTest {
|
||||||
|
|
||||||
|
private static final String EXPECTED_TEST_BUCKET = "jcloudtestbucket";
|
||||||
|
private static final String EXPECTED_TEST_GROUP_ENTITY = "group-00b4903a971ec6cff233284d6d24f5bf5cba904c4ade4d43ebd6a5d33800e68b";
|
||||||
|
|
||||||
|
private static final HttpRequest GET_DEFAULT_OBJECTACL_REQUEST = HttpRequest
|
||||||
|
.builder()
|
||||||
|
.method("GET")
|
||||||
|
.endpoint(
|
||||||
|
"https://www.googleapis.com/storage/v1/b/jcloudtestbucket/defaultObjectAcl/group-00b4903a971ec6cff233284d6d24f5bf5cba904c4ade4d43ebd6a5d33800e68b")
|
||||||
|
.addHeader("Accept", "application/json").addHeader("Authorization", "Bearer " + TOKEN).build();
|
||||||
|
|
||||||
|
private final HttpResponse GET_DEFAULT_OBJECTACL_RESPONSE = HttpResponse.builder().statusCode(200)
|
||||||
|
.payload(staticPayloadFromResource("/default_objectacl_get.json")).build();
|
||||||
|
|
||||||
|
private final HttpResponse CREATE_DEFAULT_OBJECTACL_RESPONSE = HttpResponse.builder().statusCode(200)
|
||||||
|
.payload(staticPayloadFromResource("/default_objectacl_insert_response.json")).build();
|
||||||
|
|
||||||
|
public final HttpRequest LIST_DEFAULT_OBJECTACL_REQUEST = HttpRequest.builder().method("GET")
|
||||||
|
.endpoint("https://www.googleapis.com/storage/v1/b/jcloudtestbucket/defaultObjectAcl")
|
||||||
|
.addHeader("Accept", "application/json").addHeader("Authorization", "Bearer " + TOKEN).build();
|
||||||
|
|
||||||
|
private final HttpResponse LIST_DEFAULT_OBJECTACL_RESPONSE = HttpResponse.builder().statusCode(200)
|
||||||
|
.payload(staticPayloadFromResource("/default_objectacl_list.json")).build();
|
||||||
|
|
||||||
|
// Test getDefaultObjectAccessControls
|
||||||
|
public void testGetDefaultObjectAclResponseIs2xx() throws Exception {
|
||||||
|
|
||||||
|
DefaultObjectAccessControlsApi api = requestsSendResponses(requestForScopes(STORAGE_FULLCONTROL_SCOPE),
|
||||||
|
TOKEN_RESPONSE, GET_DEFAULT_OBJECTACL_REQUEST, GET_DEFAULT_OBJECTACL_RESPONSE)
|
||||||
|
.getDefaultObjectAccessControlsApi();
|
||||||
|
|
||||||
|
assertEquals(api.getDefaultObjectAccessControls(EXPECTED_TEST_BUCKET, EXPECTED_TEST_GROUP_ENTITY),
|
||||||
|
new DefaultObjectAclGetTest().expected());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetDefaultObjectAclResponseIs4xx() throws Exception {
|
||||||
|
|
||||||
|
HttpResponse getResponse = HttpResponse.builder().statusCode(404).build();
|
||||||
|
|
||||||
|
DefaultObjectAccessControlsApi api = requestsSendResponses(requestForScopes(STORAGE_FULLCONTROL_SCOPE),
|
||||||
|
TOKEN_RESPONSE, GET_DEFAULT_OBJECTACL_REQUEST, getResponse).getDefaultObjectAccessControlsApi();
|
||||||
|
|
||||||
|
assertNull(api.getDefaultObjectAccessControls(EXPECTED_TEST_BUCKET, EXPECTED_TEST_GROUP_ENTITY));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test listDefaultObjectAccessControls
|
||||||
|
public void testListDefaultObjectAclWithNoOptionsResponseIs2xx() throws Exception {
|
||||||
|
|
||||||
|
DefaultObjectAccessControlsApi api = requestsSendResponses(requestForScopes(STORAGE_FULLCONTROL_SCOPE),
|
||||||
|
TOKEN_RESPONSE, LIST_DEFAULT_OBJECTACL_REQUEST, LIST_DEFAULT_OBJECTACL_RESPONSE)
|
||||||
|
.getDefaultObjectAccessControlsApi();
|
||||||
|
|
||||||
|
assertEquals(api.listDefaultObjectAccessControls(EXPECTED_TEST_BUCKET), new DefaultObjectAclListTest().expected());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testListDefaultObjectAclResponseIs4xx() throws Exception {
|
||||||
|
|
||||||
|
HttpResponse listResponse = HttpResponse.builder().statusCode(404).build();
|
||||||
|
|
||||||
|
DefaultObjectAccessControlsApi api = requestsSendResponses(requestForScopes(STORAGE_FULLCONTROL_SCOPE),
|
||||||
|
TOKEN_RESPONSE, LIST_DEFAULT_OBJECTACL_REQUEST, listResponse).getDefaultObjectAccessControlsApi();
|
||||||
|
|
||||||
|
assertNull(api.listDefaultObjectAccessControls(EXPECTED_TEST_BUCKET));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test insertDefaultObjectAccessControls
|
||||||
|
public void testInsertDefaultObjectAclResponseIs2xx() throws Exception {
|
||||||
|
HttpRequest insertRequest = HttpRequest
|
||||||
|
.builder()
|
||||||
|
.method("POST")
|
||||||
|
.endpoint("https://www.googleapis.com/storage/v1/b/jcloudtestbucket/defaultObjectAcl")
|
||||||
|
.addHeader("Accept", "application/json")
|
||||||
|
.addHeader("Authorization", "Bearer " + TOKEN)
|
||||||
|
.payload(payloadFromResourceWithContentType("/default_objectacl_insert_requestpayload.json",
|
||||||
|
MediaType.APPLICATION_JSON)).build();
|
||||||
|
|
||||||
|
DefaultObjectAccessControlsApi api = requestsSendResponses(requestForScopes(STORAGE_FULLCONTROL_SCOPE),
|
||||||
|
TOKEN_RESPONSE, insertRequest, CREATE_DEFAULT_OBJECTACL_RESPONSE).getDefaultObjectAccessControlsApi();
|
||||||
|
|
||||||
|
DefaultObjectAccessControlsTemplate template = new DefaultObjectAccessControlsTemplate().entity("allUsers").role(
|
||||||
|
ObjectRole.OWNER);
|
||||||
|
|
||||||
|
assertEquals(api.createDefaultObjectAccessControls(EXPECTED_TEST_BUCKET, template),
|
||||||
|
new DefaultObjectAclInsertTest().expected());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test deleteDefaultObjectAccessControls
|
||||||
|
public void testDeleteDefaultObjectAclResponseIs2xx() throws Exception {
|
||||||
|
HttpRequest delete = HttpRequest.builder().method("DELETE")
|
||||||
|
.endpoint("https://www.googleapis.com/storage/v1/b/jcloudtestbucket/defaultObjectAcl/allUsers")
|
||||||
|
.addHeader("Accept", "application/json").addHeader("Authorization", "Bearer " + TOKEN).build();
|
||||||
|
|
||||||
|
HttpResponse deleteResponse = HttpResponse.builder().statusCode(204).build();
|
||||||
|
|
||||||
|
DefaultObjectAccessControlsApi api = requestsSendResponses(requestForScopes(STORAGE_FULLCONTROL_SCOPE),
|
||||||
|
TOKEN_RESPONSE, delete, deleteResponse).getDefaultObjectAccessControlsApi();
|
||||||
|
|
||||||
|
assertEquals(api.deleteDefaultObjectAccessControls(EXPECTED_TEST_BUCKET, "allUsers"), deleteResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testDeleteObjectAclResponseIs4xx() throws Exception {
|
||||||
|
HttpRequest delete = HttpRequest.builder().method("DELETE")
|
||||||
|
.endpoint("https://www.googleapis.com/storage/v1/b/jcloudtestbucket/defaultObjectAcl/allUsers")
|
||||||
|
.addHeader("Accept", "application/json").addHeader("Authorization", "Bearer " + TOKEN).build();
|
||||||
|
|
||||||
|
HttpResponse deleteResponse = HttpResponse.builder().statusCode(404).build();
|
||||||
|
|
||||||
|
DefaultObjectAccessControlsApi api = requestsSendResponses(requestForScopes(STORAGE_FULLCONTROL_SCOPE),
|
||||||
|
TOKEN_RESPONSE, delete, deleteResponse).getDefaultObjectAccessControlsApi();
|
||||||
|
|
||||||
|
assertNull(api.deleteDefaultObjectAccessControls(EXPECTED_TEST_BUCKET, "allUsers"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test updateDefaultObjectAccessControls
|
||||||
|
public void testUpdateDefaultObjectAclWithNoOptionsResponseIs2xx() throws Exception {
|
||||||
|
HttpRequest update = HttpRequest
|
||||||
|
.builder()
|
||||||
|
.method("PUT")
|
||||||
|
.endpoint("https://www.googleapis.com/storage/v1/b/jcloudtestbucket/defaultObjectAcl/allUsers")
|
||||||
|
.addHeader("Accept", "application/json")
|
||||||
|
.addHeader("Authorization", "Bearer " + TOKEN)
|
||||||
|
.payload(payloadFromResourceWithContentType("/default_objectacl_update_requestpayload.json",
|
||||||
|
MediaType.APPLICATION_JSON)).build();
|
||||||
|
|
||||||
|
HttpResponse updateResponse = HttpResponse.builder().statusCode(200)
|
||||||
|
.payload(staticPayloadFromResource("/default_objectacl_update_initial.json")).build();
|
||||||
|
|
||||||
|
DefaultObjectAccessControlsApi api = requestsSendResponses(requestForScopes(STORAGE_FULLCONTROL_SCOPE),
|
||||||
|
TOKEN_RESPONSE, update, updateResponse).getDefaultObjectAccessControlsApi();
|
||||||
|
|
||||||
|
DefaultObjectAccessControls options = DefaultObjectAccessControls.builder().entity("allUsers")
|
||||||
|
.role(ObjectRole.OWNER).build();
|
||||||
|
|
||||||
|
assertEquals(api.updateDefaultObjectAccessControls(EXPECTED_TEST_BUCKET, "allUsers", options),
|
||||||
|
new DefaultObjectAclInsertTest().expected());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test updateDefaultObjectAccessControls
|
||||||
|
public void testUpdateDefaultObjectAclWithOptionsResponseIs2xx() throws Exception {
|
||||||
|
HttpRequest update = HttpRequest
|
||||||
|
.builder()
|
||||||
|
.method("PUT")
|
||||||
|
.endpoint("https://www.googleapis.com/storage/v1/b/jcloudtestbucket/defaultObjectAcl/allUsers")
|
||||||
|
.addHeader("Accept", "application/json")
|
||||||
|
.addHeader("Authorization", "Bearer " + TOKEN)
|
||||||
|
.addQueryParam("role", ObjectRole.OWNER.toString())
|
||||||
|
.payload(payloadFromResourceWithContentType("/default_objectacl_update_requestpayload.json",
|
||||||
|
MediaType.APPLICATION_JSON)).build();
|
||||||
|
|
||||||
|
HttpResponse updateResponse = HttpResponse.builder().statusCode(200)
|
||||||
|
.payload(staticPayloadFromResource("/default_objectacl_update_initial.json")).build();
|
||||||
|
|
||||||
|
DefaultObjectAccessControlsApi api = requestsSendResponses(requestForScopes(STORAGE_FULLCONTROL_SCOPE),
|
||||||
|
TOKEN_RESPONSE, update, updateResponse).getDefaultObjectAccessControlsApi();
|
||||||
|
|
||||||
|
DefaultObjectAccessControls options = DefaultObjectAccessControls.builder().entity("allUsers")
|
||||||
|
.role(ObjectRole.OWNER).build();
|
||||||
|
|
||||||
|
assertEquals(api.updateDefaultObjectAccessControls(EXPECTED_TEST_BUCKET, "allUsers", options, ObjectRole.OWNER),
|
||||||
|
new DefaultObjectAclInsertTest().expected());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test patchDefaultObjectAccessControls
|
||||||
|
public void testPatchDefaultObjectAclWithNoOptionsResponseIs2xx() throws Exception {
|
||||||
|
HttpRequest update = HttpRequest
|
||||||
|
.builder()
|
||||||
|
.method("PATCH")
|
||||||
|
.endpoint("https://www.googleapis.com/storage/v1/b/jcloudtestbucket/defaultObjectAcl/allUsers")
|
||||||
|
.addHeader("Accept", "application/json")
|
||||||
|
.addHeader("Authorization", "Bearer " + TOKEN)
|
||||||
|
.payload(payloadFromResourceWithContentType("/default_objectacl_update_requestpayload.json",
|
||||||
|
MediaType.APPLICATION_JSON)).build();
|
||||||
|
|
||||||
|
HttpResponse updateResponse = HttpResponse.builder().statusCode(200)
|
||||||
|
.payload(staticPayloadFromResource("/default_objectacl_update_initial.json")).build();
|
||||||
|
|
||||||
|
DefaultObjectAccessControlsApi api = requestsSendResponses(requestForScopes(STORAGE_FULLCONTROL_SCOPE),
|
||||||
|
TOKEN_RESPONSE, update, updateResponse).getDefaultObjectAccessControlsApi();
|
||||||
|
|
||||||
|
DefaultObjectAccessControls options = DefaultObjectAccessControls.builder().entity("allUsers")
|
||||||
|
.role(ObjectRole.OWNER).build();
|
||||||
|
|
||||||
|
assertEquals(api.patchDefaultObjectAccessControls(EXPECTED_TEST_BUCKET, "allUsers", options),
|
||||||
|
new DefaultObjectAclInsertTest().expected());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
/*
|
||||||
|
* 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.internal;
|
||||||
|
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.jclouds.googlecloudstorage.GoogleCloudStorageApi;
|
||||||
|
|
||||||
|
public class BaseGoogleCloudStorageApiExpectTest extends BaseGoogleCloudStorageExpectTest<GoogleCloudStorageApi> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Properties setupProperties() {
|
||||||
|
Properties properties = super.setupProperties();
|
||||||
|
properties.put("google-cloud-storage.identity", "JcloudTest");
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* 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.internal;
|
||||||
|
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.jclouds.apis.BaseApiLiveTest;
|
||||||
|
import org.jclouds.googlecloudstorage.GoogleCloudStorageApi;
|
||||||
|
|
||||||
|
import com.google.inject.Injector;
|
||||||
|
|
||||||
|
import com.google.inject.Module;
|
||||||
|
|
||||||
|
public class BaseGoogleCloudStorageApiLiveTest extends BaseApiLiveTest<GoogleCloudStorageApi> {
|
||||||
|
|
||||||
|
public BaseGoogleCloudStorageApiLiveTest() {
|
||||||
|
provider = "google-cloud-storage";
|
||||||
|
}
|
||||||
|
|
||||||
|
protected GoogleCloudStorageApi create(Properties props, Iterable<Module> modules) {
|
||||||
|
Injector injector = newBuilder().modules(modules).overrides(props).buildInjector();
|
||||||
|
return injector.getInstance(GoogleCloudStorageApi.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,171 @@
|
||||||
|
/*
|
||||||
|
* 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.internal;
|
||||||
|
|
||||||
|
import static com.google.common.base.Charsets.UTF_8;
|
||||||
|
import static com.google.common.base.Throwables.propagate;
|
||||||
|
import static com.google.common.io.BaseEncoding.base64Url;
|
||||||
|
import static org.easymock.EasyMock.createMock;
|
||||||
|
import static org.easymock.EasyMock.expect;
|
||||||
|
import static org.easymock.EasyMock.expectLastCall;
|
||||||
|
import static org.easymock.EasyMock.replay;
|
||||||
|
import static org.jclouds.crypto.Pems.privateKeySpec;
|
||||||
|
import static org.jclouds.crypto.Pems.publicKeySpec;
|
||||||
|
import static org.jclouds.crypto.PemsTest.PRIVATE_KEY;
|
||||||
|
import static org.jclouds.crypto.PemsTest.PUBLIC_KEY;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.security.KeyFactory;
|
||||||
|
import java.security.KeyPair;
|
||||||
|
import java.security.KeyPairGenerator;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.security.PrivateKey;
|
||||||
|
import java.security.PublicKey;
|
||||||
|
import java.security.SecureRandom;
|
||||||
|
import java.security.interfaces.RSAPublicKey;
|
||||||
|
import java.security.spec.InvalidKeySpecException;
|
||||||
|
import java.util.Properties;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
|
import org.jclouds.crypto.Crypto;
|
||||||
|
import org.jclouds.http.HttpRequest;
|
||||||
|
import org.jclouds.http.HttpResponse;
|
||||||
|
import org.jclouds.io.Payload;
|
||||||
|
import org.jclouds.io.payloads.ByteSourcePayload;
|
||||||
|
import org.jclouds.oauth.v2.OAuthConstants;
|
||||||
|
import org.jclouds.oauth.v2.config.OAuthProperties;
|
||||||
|
import org.jclouds.rest.internal.BaseRestApiExpectTest;
|
||||||
|
import org.jclouds.ssh.SshKeys;
|
||||||
|
import com.google.common.base.Joiner;
|
||||||
|
import com.google.common.base.Supplier;
|
||||||
|
import com.google.common.base.Suppliers;
|
||||||
|
import com.google.common.io.ByteSource;
|
||||||
|
import com.google.common.io.Resources;
|
||||||
|
import com.google.inject.Binder;
|
||||||
|
import com.google.inject.Module;
|
||||||
|
import com.google.inject.TypeLiteral;
|
||||||
|
|
||||||
|
public class BaseGoogleCloudStorageExpectTest<T> extends BaseRestApiExpectTest<T> {
|
||||||
|
|
||||||
|
private static final String header = "{\"alg\":\"none\",\"typ\":\"JWT\"}";
|
||||||
|
|
||||||
|
private static final String CLAIMS_TEMPLATE = "{" + "\"iss\":\"JcloudTest\"," + "\"scope\":\"%s\","
|
||||||
|
+ "\"aud\":\"https://accounts.google.com/o/oauth2/token\"," + "\"exp\":3600," + "\"iat\":0}";
|
||||||
|
|
||||||
|
protected static final String TOKEN = "1/8xbJqaOZXSUZbHLl5EOtu1pxz3fmmetKx9W8CV4t79M";
|
||||||
|
|
||||||
|
protected static final HttpResponse TOKEN_RESPONSE = HttpResponse
|
||||||
|
.builder()
|
||||||
|
.statusCode(200)
|
||||||
|
.payload(payloadFromString("{\n" + " \"access_token\" : \"" + TOKEN + "\",\n"
|
||||||
|
+ " \"token_type\" : \"Bearer\",\n" + " \"expires_in\" : 3600\n" + "}")).build();
|
||||||
|
|
||||||
|
protected String openSshKey;
|
||||||
|
|
||||||
|
public BaseGoogleCloudStorageExpectTest() {
|
||||||
|
provider = "google-cloud-storage";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Module createModule() {
|
||||||
|
|
||||||
|
return new Module() {
|
||||||
|
@Override
|
||||||
|
public void configure(Binder binder) {
|
||||||
|
// Predicatable time
|
||||||
|
binder.bind(new TypeLiteral<Supplier<Long>>() {
|
||||||
|
}).toInstance(Suppliers.ofInstance(0L));
|
||||||
|
try {
|
||||||
|
KeyFactory keyfactory = KeyFactory.getInstance("RSA");
|
||||||
|
PrivateKey privateKey = keyfactory.generatePrivate(privateKeySpec(ByteSource.wrap(PRIVATE_KEY
|
||||||
|
.getBytes(UTF_8))));
|
||||||
|
PublicKey publicKey = keyfactory
|
||||||
|
.generatePublic(publicKeySpec(ByteSource.wrap(PUBLIC_KEY.getBytes(UTF_8))));
|
||||||
|
KeyPair keyPair = new KeyPair(publicKey, privateKey);
|
||||||
|
openSshKey = SshKeys.encodeAsOpenSSH(RSAPublicKey.class.cast(publicKey));
|
||||||
|
final Crypto crypto = createMock(Crypto.class);
|
||||||
|
KeyPairGenerator rsaKeyPairGenerator = createMock(KeyPairGenerator.class);
|
||||||
|
final SecureRandom secureRandom = createMock(SecureRandom.class);
|
||||||
|
expect(crypto.rsaKeyPairGenerator()).andReturn(rsaKeyPairGenerator).anyTimes();
|
||||||
|
rsaKeyPairGenerator.initialize(2048, secureRandom);
|
||||||
|
expectLastCall().anyTimes();
|
||||||
|
expect(rsaKeyPairGenerator.genKeyPair()).andReturn(keyPair).anyTimes();
|
||||||
|
replay(crypto, rsaKeyPairGenerator, secureRandom);
|
||||||
|
binder.bind(Crypto.class).toInstance(crypto);
|
||||||
|
binder.bind(SecureRandom.class).toInstance(secureRandom);
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
propagate(e);
|
||||||
|
} catch (InvalidKeySpecException e) {
|
||||||
|
propagate(e);
|
||||||
|
} catch (IOException e) {
|
||||||
|
propagate(e);
|
||||||
|
}
|
||||||
|
// predictable node names
|
||||||
|
final AtomicInteger suffix = new AtomicInteger();
|
||||||
|
binder.bind(new TypeLiteral<Supplier<String>>() {
|
||||||
|
}).toInstance(new Supplier<String>() {
|
||||||
|
@Override
|
||||||
|
public String get() {
|
||||||
|
return suffix.getAndIncrement() + "";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Properties setupProperties() {
|
||||||
|
Properties props = super.setupProperties();
|
||||||
|
// use no sig algorithm for expect tests (means no credential is required either)
|
||||||
|
props.put(OAuthProperties.SIGNATURE_OR_MAC_ALGORITHM, OAuthConstants.NO_ALGORITHM);
|
||||||
|
return props;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected HttpRequestComparisonType compareHttpRequestAsType(HttpRequest input) {
|
||||||
|
HttpRequestComparisonType reqType = HttpRequestComparisonType.DEFAULT;
|
||||||
|
if (input.getPayload() != null) {
|
||||||
|
if (MediaType.APPLICATION_JSON.toString().equals(input.getPayload().getContentMetadata().getContentType())) {
|
||||||
|
reqType = HttpRequestComparisonType.JSON;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return reqType;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected HttpRequest requestForScopes(String... scopes) {
|
||||||
|
String claims = String.format(CLAIMS_TEMPLATE, Joiner.on(",").join(scopes));
|
||||||
|
|
||||||
|
String payload = "grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&" +
|
||||||
|
// Base64 Encoded Header
|
||||||
|
"assertion=" + base64Url().omitPadding().encode(header.getBytes(UTF_8)) + "." +
|
||||||
|
// Base64 Encoded Claims
|
||||||
|
base64Url().omitPadding().encode(claims.getBytes(UTF_8)) + ".";
|
||||||
|
|
||||||
|
return HttpRequest.builder().method("POST").endpoint(URI.create("https://accounts.google.com/o/oauth2/token"))
|
||||||
|
.addHeader("Accept", MediaType.APPLICATION_JSON)
|
||||||
|
.payload(payloadFromStringWithContentType(payload, "application/x-www-form-urlencoded")).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Payload staticPayloadFromResource(String resource) {
|
||||||
|
return new ByteSourcePayload(Resources.asByteSource(Resources.getResource(getClass(), resource)));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
/*
|
||||||
|
* 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.internal;
|
||||||
|
|
||||||
|
import org.jclouds.googlecloudstorage.config.GoogleCloudStorageParserModule;
|
||||||
|
import org.jclouds.json.BaseItemParserTest;
|
||||||
|
import org.jclouds.json.config.GsonModule;
|
||||||
|
|
||||||
|
import com.google.inject.Guice;
|
||||||
|
import com.google.inject.Injector;
|
||||||
|
|
||||||
|
public abstract class BaseGoogleCloudStorageParseTest<T> extends BaseItemParserTest<T> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Injector injector() {
|
||||||
|
return Guice.createInjector(new GsonModule(), new GoogleCloudStorageParserModule());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
/*
|
||||||
|
* 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 javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
|
import org.jclouds.googlecloudstorage.domain.DefaultObjectAccessControls;
|
||||||
|
import org.jclouds.googlecloudstorage.domain.DefaultObjectAccessControls.ProjectTeam;
|
||||||
|
import org.jclouds.googlecloudstorage.domain.DefaultObjectAccessControls.ProjectTeam.Team;
|
||||||
|
import org.jclouds.googlecloudstorage.features.ApiResourceRefferences.ObjectRole;
|
||||||
|
import org.jclouds.googlecloudstorage.internal.BaseGoogleCloudStorageParseTest;
|
||||||
|
|
||||||
|
public class DefaultObjectAclGetTest extends BaseGoogleCloudStorageParseTest<DefaultObjectAccessControls> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String resource() {
|
||||||
|
return "/default_objectacl_get.json";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
public DefaultObjectAccessControls expected() {
|
||||||
|
return DefaultObjectAccessControls.builder().entity("project-owners-1082289308625").role(ObjectRole.OWNER)
|
||||||
|
.etag("CAk=").projectTeam(new ProjectTeam("1082289308625", Team.owners)).build();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* 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 javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
|
import org.jclouds.googlecloudstorage.domain.DefaultObjectAccessControls;
|
||||||
|
import org.jclouds.googlecloudstorage.features.ApiResourceRefferences.ObjectRole;
|
||||||
|
import org.jclouds.googlecloudstorage.internal.BaseGoogleCloudStorageParseTest;
|
||||||
|
|
||||||
|
public class DefaultObjectAclInsertTest extends BaseGoogleCloudStorageParseTest<DefaultObjectAccessControls> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String resource() {
|
||||||
|
return "/default_objectacl_insert_response.json";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
public DefaultObjectAccessControls expected() {
|
||||||
|
return DefaultObjectAccessControls.builder().entity("allUsers").role(ObjectRole.OWNER).etag("CAo=").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 javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
|
import org.jclouds.googlecloudstorage.domain.DefaultObjectAccessControls;
|
||||||
|
import org.jclouds.googlecloudstorage.domain.DefaultObjectAccessControls.ProjectTeam;
|
||||||
|
import org.jclouds.googlecloudstorage.domain.DefaultObjectAccessControls.ProjectTeam.Team;
|
||||||
|
import org.jclouds.googlecloudstorage.domain.ListDefaultObjectAccessControls;
|
||||||
|
import org.jclouds.googlecloudstorage.domain.Resource.Kind;
|
||||||
|
import org.jclouds.googlecloudstorage.features.ApiResourceRefferences.ObjectRole;
|
||||||
|
import org.jclouds.googlecloudstorage.internal.BaseGoogleCloudStorageParseTest;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
|
public class DefaultObjectAclListTest extends BaseGoogleCloudStorageParseTest<ListDefaultObjectAccessControls> {
|
||||||
|
|
||||||
|
private DefaultObjectAccessControls item_1 = DefaultObjectAccessControls.builder()
|
||||||
|
.entity("project-owners-1082289308625").role(ObjectRole.OWNER)
|
||||||
|
.projectTeam(new ProjectTeam("1082289308625", Team.owners)).etag("CAk=").build();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String resource() {
|
||||||
|
return "/default_objectacl_list.json";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
public ListDefaultObjectAccessControls expected() {
|
||||||
|
return ListDefaultObjectAccessControls.builder().kind(Kind.OBJECT_ACCESS_CONTROLS).items(ImmutableSet.of(item_1))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"kind": "storage#objectAccessControl",
|
||||||
|
"entity": "project-owners-1082289308625",
|
||||||
|
"role": "OWNER",
|
||||||
|
"projectTeam": {
|
||||||
|
"projectNumber": "1082289308625",
|
||||||
|
"team": "owners"
|
||||||
|
},
|
||||||
|
"etag": "CAk="
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"entity": "allUsers",
|
||||||
|
"role": "OWNER"
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"kind": "storage#objectAccessControl",
|
||||||
|
"entity": "allUsers",
|
||||||
|
"role": "OWNER",
|
||||||
|
"etag": "CAo="
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
{
|
||||||
|
"kind": "storage#objectAccessControls",
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"kind": "storage#objectAccessControl",
|
||||||
|
"entity": "project-owners-1082289308625",
|
||||||
|
"role": "OWNER",
|
||||||
|
"projectTeam": {
|
||||||
|
"projectNumber": "1082289308625",
|
||||||
|
"team": "owners"
|
||||||
|
},
|
||||||
|
"etag": "CAk="
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"kind": "storage#objectAccessControl",
|
||||||
|
"entity": "allUsers",
|
||||||
|
"role": "OWNER",
|
||||||
|
"etag": "CAo="
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"kind": "storage#objectAccessControl",
|
||||||
|
"entity": "allUsers",
|
||||||
|
"role": "OWNER"
|
||||||
|
}
|
Loading…
Reference in New Issue