Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better document Storage API #356

Merged
merged 9 commits into from
Nov 12, 2015
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
import java.util.Objects;

/**
* Access Control List on for buckets or blobs.
* Access Control List for buckets or blobs.
*
* @see <a href="https://cloud.google.com/storage/docs/access-control#About-Access-Control-Lists">
* About Access Control Lists</a>
*/
public final class Acl implements Serializable {

Expand All @@ -36,6 +39,9 @@ public enum Role {
OWNER, READER, WRITER
}

/**
* Base class for Access Control List entities.
*/
public abstract static class Entity implements Serializable {

private static final long serialVersionUID = -2707407252771255840L;
Expand All @@ -52,10 +58,16 @@ public enum Type {
this.value = value;
}

/**
* Returns the type of entity.
*/
public Type type() {
return type;
}

/**
* Returns the entity's value.
*/
protected String value() {
return value;
}
Expand Down Expand Up @@ -112,42 +124,75 @@ static Entity fromPb(String entity) {
}
}

/**
* Class for ACL Domain entities.
*/
public static final class Domain extends Entity {

private static final long serialVersionUID = -3033025857280447253L;

/**
* Creates a domain entity.
*
* @param domain the domain associated to this entity
*/
public Domain(String domain) {
super(Type.DOMAIN, domain);
}

/**
* Returns the domain associated to this entity.
*/
public String domain() {
return value();
}
}

/**
* Class for ACL Group entities.
*/
public static final class Group extends Entity {

private static final long serialVersionUID = -1660987136294408826L;

/**
* Creates a group entity.
*
* @param email the group email
*/
public Group(String email) {
super(Type.GROUP, email);
}

/**
* Returns the group email.
*/
public String email() {
return value();
}
}

/**
* Class for ACL User entities.
*/
public static final class User extends Entity {

private static final long serialVersionUID = 3076518036392737008L;
private static final String ALL_USERS = "allUsers";
private static final String ALL_AUTHENTICATED_USERS = "allAuthenticatedUsers";

/**
* Creates a user entity.
*
* @param email the user email
*/
public User(String email) {
super(Type.USER, email);
}

/**
* Returns the user email.
*/
public String email() {
return value();
}
Expand All @@ -174,6 +219,9 @@ public static User ofAllAuthenticatedUsers() {
}
}

/**
* Class for ACL Project entities.
*/
public static final class Project extends Entity {

private static final long serialVersionUID = 7933776866530023027L;
Expand All @@ -185,16 +233,28 @@ public enum ProjectRole {
OWNERS, EDITORS, VIEWERS
}

/**
* Creates a project entity.
*
* @param pRole a role in the project, used to select project's teams
* @param projectId id of the project
*/
public Project(ProjectRole pRole, String projectId) {
super(Type.PROJECT, pRole.name().toLowerCase() + "-" + projectId);
this.pRole = pRole;
this.projectId = projectId;
}

/**
* Returns the role in the project for this entity.
*/
public ProjectRole projectRole() {
return pRole;
}

/**
* Returns the project id for this entity.
*/
public String projectId() {
return projectId;
}
Expand All @@ -214,15 +274,27 @@ String toPb() {
}
}

/**
* Creats an ACL object.
*
* @param entity the entity for this ACL object
* @param role the role to associate to the {@code entity} object
*/
public Acl(Entity entity, Role role) {
this.entity = entity;
this.role = role;
}

/**
* Returns the entity for this ACL object.
*/
public Entity entity() {
return entity;
}

/**
* Returns the role associated to the entity in this ACL object.
*/
public Role role() {
return role;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public final class Blob {
private final Storage storage;
private final BlobInfo info;

/**
* Class for specifying blob source options when {@code Blob} methods are used.
*/
public static class BlobSourceOption extends Option {

private static final long serialVersionUID = 214616862061934846L;
Expand Down Expand Up @@ -88,18 +91,34 @@ private Storage.BlobGetOption toGetOption(BlobInfo blobInfo) {
}
}

/**
* Returns an option for blob's generation match. If this option is used the request will fail
* if generation does not match.
*/
public static BlobSourceOption generationMatch() {
return new BlobSourceOption(StorageRpc.Option.IF_GENERATION_MATCH);
}

/**
* Returns an option for blob's generation mismatch. If this option is used the request will
* fail if generation matches.
*/
public static BlobSourceOption generationNotMatch() {
return new BlobSourceOption(StorageRpc.Option.IF_GENERATION_NOT_MATCH);
}

/**
* Returns an option for blob's metageneration match. If this option is used the request will
* fail if metageneration does not match.
*/
public static BlobSourceOption metagenerationMatch() {
return new BlobSourceOption(StorageRpc.Option.IF_METAGENERATION_MATCH);
}

/**
* Returns an option for blob's metageneration mismatch. If this option is used the request will
* fail if metageneration matches.
*/
public static BlobSourceOption metagenerationNotMatch() {
return new BlobSourceOption(StorageRpc.Option.IF_METAGENERATION_NOT_MATCH);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,16 @@ private BlobId(String bucket, String name) {
this.name = name;
}

/**
* Returns the name of the bucket containing the blob.
*/
public String bucket() {
return bucket;
}

/**
* Returns the name of the blob.
*/
public String name() {
return name;
}
Expand Down Expand Up @@ -72,6 +78,12 @@ StorageObject toPb() {
return storageObject;
}

/**
* Creates a blob identifier.
*
* @param bucket the name of the bucket that contains the blob
* @param name the name of the blob
*/
public static BlobId of(String bucket, String name) {
return new BlobId(checkNotNull(bucket), checkNotNull(name));
}
Expand Down
Loading