From 0ca3a686f5a7fe373bef2bc91f4e9cc3422ca063 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 21 Nov 2010 18:37:47 +0100 Subject: [PATCH] encryption properties are not mutable except during creation requests --- .../domain/CreateDriveRequest.java | 63 +++++++++++++++++-- .../elastichosts/domain/DriveInfo.java | 22 +++++-- .../domain/internal/BaseDrive.java | 31 +-------- .../functions/BaseDriveToMap.java | 2 - .../functions/CreateDriveRequestToMap.java | 2 + .../functions/BaseDriveToMapTest.java | 4 +- .../src/test/resources/create_drive.txt | 4 +- 7 files changed, 82 insertions(+), 46 deletions(-) diff --git a/sandbox/elastichosts/src/main/java/org/jclouds/elastichosts/domain/CreateDriveRequest.java b/sandbox/elastichosts/src/main/java/org/jclouds/elastichosts/domain/CreateDriveRequest.java index 656d6bb503..49123531b9 100644 --- a/sandbox/elastichosts/src/main/java/org/jclouds/elastichosts/domain/CreateDriveRequest.java +++ b/sandbox/elastichosts/src/main/java/org/jclouds/elastichosts/domain/CreateDriveRequest.java @@ -36,8 +36,12 @@ import com.google.common.collect.ImmutableSet; */ public class CreateDriveRequest extends BaseDrive { public static class Builder extends BaseDrive.Builder { + private Set avoid = ImmutableSet.of(); + @Nullable + private String encryptionCipher; + public Builder avoid(Iterable avoid) { this.avoid = ImmutableSet.copyOf(checkNotNull(avoid, "avoid")); return this; @@ -51,12 +55,9 @@ public class CreateDriveRequest extends BaseDrive { return Builder.class.cast(super.claimType(claimType)); } - /** - * {@inheritDoc} - */ - @Override public Builder encryptionCipher(String encryptionCipher) { - return Builder.class.cast(super.encryptionCipher(encryptionCipher)); + this.encryptionCipher = encryptionCipher; + return this; } /** @@ -105,11 +106,14 @@ public class CreateDriveRequest extends BaseDrive { } private final Set avoid; + @Nullable + private final String encryptionCipher; public CreateDriveRequest(String name, long size, @Nullable ClaimType claimType, Iterable readers, Iterable tags, Map userMetadata, @Nullable String encryptionCipher, Iterable avoid) { - super(name, size, claimType, readers, tags, userMetadata, encryptionCipher); + super(name, size, claimType, readers, tags, userMetadata); + this.encryptionCipher = encryptionCipher; this.avoid = ImmutableSet.copyOf(checkNotNull(avoid, "avoid")); } @@ -122,4 +126,51 @@ public class CreateDriveRequest extends BaseDrive { return avoid; } + /** + * + * @return either 'none' or 'aes-xts-plain' (the default) + */ + @Nullable + public String getEncryptionCipher() { + return encryptionCipher; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((avoid == null) ? 0 : avoid.hashCode()); + result = prime * result + ((encryptionCipher == null) ? 0 : encryptionCipher.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + CreateDriveRequest other = (CreateDriveRequest) obj; + if (avoid == null) { + if (other.avoid != null) + return false; + } else if (!avoid.equals(other.avoid)) + return false; + if (encryptionCipher == null) { + if (other.encryptionCipher != null) + return false; + } else if (!encryptionCipher.equals(other.encryptionCipher)) + return false; + return true; + } + + @Override + public String toString() { + return "[name=" + name + ", size=" + size + ", claimType=" + claimType + ", readers=" + readers + ", tags=" + + tags + ", userMetadata=" + userMetadata + ", avoid=" + avoid + ", encryptionCipher=" + encryptionCipher + + "]"; + } + } \ No newline at end of file diff --git a/sandbox/elastichosts/src/main/java/org/jclouds/elastichosts/domain/DriveInfo.java b/sandbox/elastichosts/src/main/java/org/jclouds/elastichosts/domain/DriveInfo.java index c065d5f9dd..112b68ee30 100644 --- a/sandbox/elastichosts/src/main/java/org/jclouds/elastichosts/domain/DriveInfo.java +++ b/sandbox/elastichosts/src/main/java/org/jclouds/elastichosts/domain/DriveInfo.java @@ -42,6 +42,7 @@ public class DriveInfo extends BaseDrive { private Boolean autoexpanding; private Integer bits; private Set claimed = ImmutableSet.of(); + private String encryptionCipher; private String description; private String uuid; private Set driveType = ImmutableSet.of(); @@ -166,12 +167,9 @@ public class DriveInfo extends BaseDrive { return Builder.class.cast(super.claimType(claimType)); } - /** - * {@inheritDoc} - */ - @Override public Builder encryptionCipher(String encryptionCipher) { - return Builder.class.cast(super.encryptionCipher(encryptionCipher)); + this.encryptionCipher = encryptionCipher; + return this; } /** @@ -239,6 +237,8 @@ public class DriveInfo extends BaseDrive { @Nullable private final Set driveType; @Nullable + private final String encryptionCipher; + @Nullable private final String encryptionKey; @Nullable private final Boolean free; @@ -268,7 +268,7 @@ public class DriveInfo extends BaseDrive { String encryptionKey, Boolean free, String imaging, String installNotes, String name, String os, Iterable readers, Long readBytes, Long readRequests, Long size, Iterable tags, DriveType type, URI url, Iterable use, Map userMetadata, Long writeBytes, Long writeRequests) { - super(name, size, claimType, readers, tags, userMetadata, encryptionCipher); + super(name, size, claimType, readers, tags, userMetadata); this.status = status; this.user = user; this.autoexpanding = autoexpanding; @@ -277,6 +277,7 @@ public class DriveInfo extends BaseDrive { this.description = description; this.uuid = drive; this.driveType = ImmutableSet.copyOf(driveType); + this.encryptionCipher = encryptionCipher; this.encryptionKey = encryptionKey; this.free = free; this.imaging = imaging; @@ -343,6 +344,15 @@ public class DriveInfo extends BaseDrive { return driveType; } + /** + * + * @return either 'none' or 'aes-xts-plain' (the default) + */ + @Nullable + public String getEncryptionCipher() { + return encryptionCipher; + } + // TODO public String getEncryptionKey() { return encryptionKey; diff --git a/sandbox/elastichosts/src/main/java/org/jclouds/elastichosts/domain/internal/BaseDrive.java b/sandbox/elastichosts/src/main/java/org/jclouds/elastichosts/domain/internal/BaseDrive.java index 836c189579..00039824dd 100644 --- a/sandbox/elastichosts/src/main/java/org/jclouds/elastichosts/domain/internal/BaseDrive.java +++ b/sandbox/elastichosts/src/main/java/org/jclouds/elastichosts/domain/internal/BaseDrive.java @@ -43,19 +43,12 @@ public class BaseDrive { protected Set readers = ImmutableSet.of(); protected Set tags = ImmutableSet.of(); protected Map userMetadata = ImmutableMap.of(); - @Nullable - protected String encryptionCipher; public Builder claimType(ClaimType claimType) { this.claimType = claimType; return this; } - public Builder encryptionCipher(String encryptionCipher) { - this.encryptionCipher = encryptionCipher; - return this; - } - public Builder name(String name) { this.name = name; return this; @@ -82,7 +75,7 @@ public class BaseDrive { } public BaseDrive build() { - return new BaseDrive(name, size, claimType, readers, tags, userMetadata, encryptionCipher); + return new BaseDrive(name, size, claimType, readers, tags, userMetadata); } } @@ -92,18 +85,15 @@ public class BaseDrive { protected final Set readers; protected final Set tags; protected final Map userMetadata; - @Nullable - protected final String encryptionCipher; public BaseDrive(String name, long size, @Nullable ClaimType claimType, Iterable readers, - Iterable tags, Map userMetadata, @Nullable String encryptionCipher) { + Iterable tags, Map userMetadata) { this.name = checkNotNull(name, "name"); this.size = size; this.claimType = checkNotNull(claimType, "set claimType to exclusive, not null"); this.readers = ImmutableSet.copyOf(checkNotNull(readers, "readers")); this.tags = ImmutableSet.copyOf(checkNotNull(tags, "tags")); this.userMetadata = ImmutableMap.copyOf(checkNotNull(userMetadata, "userMetadata")); - this.encryptionCipher = encryptionCipher; } /** @@ -116,15 +106,6 @@ public class BaseDrive { return claimType; } - /** - * - * @return either 'none' or 'aes-xts-plain' (the default) - */ - @Nullable - public String getEncryptionCipher() { - return encryptionCipher; - } - /** * * @return Drive name @@ -171,7 +152,6 @@ public class BaseDrive { final int prime = 31; int result = 1; result = prime * result + ((claimType == null) ? 0 : claimType.hashCode()); - result = prime * result + ((encryptionCipher == null) ? 0 : encryptionCipher.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((readers == null) ? 0 : readers.hashCode()); result = prime * result + (int) (size ^ (size >>> 32)); @@ -191,11 +171,6 @@ public class BaseDrive { BaseDrive other = (BaseDrive) obj; if (claimType != other.claimType) return false; - if (encryptionCipher == null) { - if (other.encryptionCipher != null) - return false; - } else if (!encryptionCipher.equals(other.encryptionCipher)) - return false; if (name == null) { if (other.name != null) return false; @@ -224,7 +199,7 @@ public class BaseDrive { @Override public String toString() { return "[name=" + name + ", size=" + size + ", claimType=" + claimType + ", readers=" + readers + ", tags=" - + tags + ", userMetadata=" + userMetadata + ", encryptionCipher=" + encryptionCipher + "]"; + + tags + ", userMetadata=" + userMetadata + "]"; } } \ No newline at end of file diff --git a/sandbox/elastichosts/src/main/java/org/jclouds/elastichosts/functions/BaseDriveToMap.java b/sandbox/elastichosts/src/main/java/org/jclouds/elastichosts/functions/BaseDriveToMap.java index dfce426dcd..d73ae03bab 100644 --- a/sandbox/elastichosts/src/main/java/org/jclouds/elastichosts/functions/BaseDriveToMap.java +++ b/sandbox/elastichosts/src/main/java/org/jclouds/elastichosts/functions/BaseDriveToMap.java @@ -53,8 +53,6 @@ public class BaseDriveToMap implements Function> builder.put("tags", Joiner.on(' ').join(from.getTags())); for (Entry entry : from.getUserMetadata().entrySet()) builder.put("user:" + entry.getKey(), entry.getValue()); - if (from.getEncryptionCipher() != null) - builder.put("encryption:cipher", from.getEncryptionCipher()); return builder.build(); } } \ No newline at end of file diff --git a/sandbox/elastichosts/src/main/java/org/jclouds/elastichosts/functions/CreateDriveRequestToMap.java b/sandbox/elastichosts/src/main/java/org/jclouds/elastichosts/functions/CreateDriveRequestToMap.java index 8a8d81fed1..5a64bc857e 100644 --- a/sandbox/elastichosts/src/main/java/org/jclouds/elastichosts/functions/CreateDriveRequestToMap.java +++ b/sandbox/elastichosts/src/main/java/org/jclouds/elastichosts/functions/CreateDriveRequestToMap.java @@ -49,6 +49,8 @@ public class CreateDriveRequestToMap implements Function