Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: uses wrapper encryption info for backups
- Loading branch information
1 parent
4f5e296
commit e5867c5
Showing
4 changed files
with
95 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
google-cloud-spanner/src/main/java/com/google/cloud/spanner/EncryptionInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright 2020 Google LLC | ||
* | ||
* Licensed 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 com.google.cloud.spanner; | ||
|
||
import com.google.rpc.Status; | ||
import java.util.Objects; | ||
|
||
/** Represents the encryption information for a Cloud Spanner backup. */ | ||
public class EncryptionInfo { | ||
|
||
private final String kmsKeyVersion; | ||
private final com.google.spanner.admin.database.v1.EncryptionInfo.Type encryptionType; | ||
private final Status encryptionStatus; | ||
|
||
public EncryptionInfo(com.google.spanner.admin.database.v1.EncryptionInfo proto) { | ||
this.kmsKeyVersion = proto.getKmsKeyVersion(); | ||
this.encryptionType = proto.getEncryptionType(); | ||
this.encryptionStatus = proto.getEncryptionStatus(); | ||
} | ||
|
||
/** | ||
* Returns a {@link EncryptionInfo} instance from the given proto, or <code>null</code> if the | ||
* given proto is the default proto instance (i.e. there is no encryption info). | ||
*/ | ||
static EncryptionInfo fromProtoOrNullIfDefaultInstance( | ||
com.google.spanner.admin.database.v1.EncryptionInfo proto) { | ||
return proto.equals(com.google.spanner.admin.database.v1.EncryptionInfo.getDefaultInstance()) | ||
? null | ||
: new EncryptionInfo(proto); | ||
} | ||
|
||
public com.google.spanner.admin.database.v1.EncryptionInfo toProto() { | ||
return com.google.spanner.admin.database.v1.EncryptionInfo.newBuilder() | ||
.setKmsKeyVersion(kmsKeyVersion) | ||
.setEncryptionType(encryptionType) | ||
.setEncryptionStatus(encryptionStatus) | ||
.build(); | ||
} | ||
|
||
public String getKmsKeyVersion() { | ||
return kmsKeyVersion; | ||
} | ||
|
||
public com.google.spanner.admin.database.v1.EncryptionInfo.Type getEncryptionType() { | ||
return encryptionType; | ||
} | ||
|
||
public Status getEncryptionStatus() { | ||
return encryptionStatus; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
EncryptionInfo that = (EncryptionInfo) o; | ||
return Objects.equals(kmsKeyVersion, that.kmsKeyVersion) | ||
&& encryptionType == that.encryptionType | ||
&& Objects.equals(encryptionStatus, that.encryptionStatus); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(kmsKeyVersion, encryptionType, encryptionStatus); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format( | ||
"EncryptionInfo[kmsKeyVersion=%s,encryptionType=%s,encryptionStatus=%s]", | ||
kmsKeyVersion, encryptionType, encryptionStatus); | ||
} | ||
} |