|
| 1 | +/* |
| 2 | + * Copyright 2021 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package com.google.cloud.bigtable.admin.v2.models; |
| 17 | + |
| 18 | +import com.google.bigtable.admin.v2.EncryptionInfo.EncryptionType; |
| 19 | +import com.google.cloud.bigtable.common.Status; |
| 20 | +import com.google.common.base.Objects; |
| 21 | + |
| 22 | +/** |
| 23 | + * Encryption information for a given resource. |
| 24 | + * |
| 25 | + * <p>If this resource is protected with customer managed encryption, the in-use Google Cloud Key |
| 26 | + * Management Service (KMS) key versions will be specified along with their status. |
| 27 | + */ |
| 28 | +public final class EncryptionInfo { |
| 29 | + public enum Type { |
| 30 | + /** Encryption type was not specified, though data at rest remains encrypted. */ |
| 31 | + ENCRYPTION_TYPE_UNSPECIFIED( |
| 32 | + com.google.bigtable.admin.v2.EncryptionInfo.EncryptionType.ENCRYPTION_TYPE_UNSPECIFIED), |
| 33 | + /** |
| 34 | + * The data backing this resource is encrypted at rest with a key that is fully managed by |
| 35 | + * Google. No key version or status will be populated. |
| 36 | + */ |
| 37 | + GOOGLE_DEFAULT_ENCRYPTION( |
| 38 | + com.google.bigtable.admin.v2.EncryptionInfo.EncryptionType.GOOGLE_DEFAULT_ENCRYPTION), |
| 39 | + /** |
| 40 | + * The data backing this resource is encrypted at rest with a key that is fully managed by |
| 41 | + * Google. No key version or status will be populated. This is the default state. |
| 42 | + */ |
| 43 | + CUSTOMER_MANAGED_ENCRYPTION( |
| 44 | + com.google.bigtable.admin.v2.EncryptionInfo.EncryptionType.CUSTOMER_MANAGED_ENCRYPTION), |
| 45 | + /** Type not known by the client, please upgrade your client */ |
| 46 | + UNRECOGNIZED(com.google.bigtable.admin.v2.EncryptionInfo.EncryptionType.UNRECOGNIZED); |
| 47 | + |
| 48 | + private final com.google.bigtable.admin.v2.EncryptionInfo.EncryptionType proto; |
| 49 | + |
| 50 | + Type(EncryptionType proto) { |
| 51 | + this.proto = proto; |
| 52 | + } |
| 53 | + |
| 54 | + /** Wraps the EncryptionInfo protobuf. */ |
| 55 | + public static Type fromProto(com.google.bigtable.admin.v2.EncryptionInfo.EncryptionType proto) { |
| 56 | + for (Type type : values()) { |
| 57 | + if (Objects.equal(type.proto, proto)) { |
| 58 | + return type; |
| 59 | + } |
| 60 | + } |
| 61 | + return UNRECOGNIZED; |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + private com.google.bigtable.admin.v2.EncryptionInfo proto; |
| 66 | + |
| 67 | + public static EncryptionInfo fromProto(com.google.bigtable.admin.v2.EncryptionInfo proto) { |
| 68 | + return new EncryptionInfo(proto); |
| 69 | + } |
| 70 | + |
| 71 | + private EncryptionInfo(com.google.bigtable.admin.v2.EncryptionInfo proto) { |
| 72 | + this.proto = proto; |
| 73 | + } |
| 74 | + |
| 75 | + public Type getType() { |
| 76 | + return EncryptionInfo.Type.fromProto(proto.getEncryptionType()); |
| 77 | + } |
| 78 | + |
| 79 | + public String getKmsKeyVersion() { |
| 80 | + return proto.getKmsKeyVersion(); |
| 81 | + } |
| 82 | + |
| 83 | + public Status getStatus() { |
| 84 | + return Status.fromProto(proto.getEncryptionStatus()); |
| 85 | + } |
| 86 | + |
| 87 | + @Override |
| 88 | + public boolean equals(Object o) { |
| 89 | + if (this == o) { |
| 90 | + return true; |
| 91 | + } |
| 92 | + if (o == null || getClass() != o.getClass()) { |
| 93 | + return false; |
| 94 | + } |
| 95 | + EncryptionInfo that = (EncryptionInfo) o; |
| 96 | + return Objects.equal(proto, that.proto); |
| 97 | + } |
| 98 | + |
| 99 | + @Override |
| 100 | + public int hashCode() { |
| 101 | + return Objects.hashCode(proto); |
| 102 | + } |
| 103 | + |
| 104 | + @Override |
| 105 | + public String toString() { |
| 106 | + return proto.toString(); |
| 107 | + } |
| 108 | +} |
0 commit comments