Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: customer managed keys (CMEK) (#249)
* feat: customer managed keys (CMEK) Implement customer managed keys (CMEK) feature. WIP. DO NOT MERGE. * Wrap Status. * Wrapper for Status, reorganize to avoid circular imports. * Blacken. * Make system tests in charge of their own key. * Consolidate system tests. Get KMS_KEY_NAME from user's environment. * Fix test. * Lint. * Put system tests where nox is expecting to find them. * Test backup with CMEK. * Differentiate instance and cluster names for cmek test, so tests aren't stepping on each other's toes. Remove bogus backup with cmek test. * rename `encryption.py` to `encryption_info.py` * make sure `kms_key_name` is set to `None` if `encryption_info` is not PB. * Fix typo. Use more realistic looking test strings.
- Loading branch information
Chris Rossi
committed
Apr 19, 2021
1 parent
05bc9aa
commit 93df829
Showing
11 changed files
with
724 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Copyright 2021 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. | ||
|
||
"""Class for encryption info for tables and backups.""" | ||
|
||
from google.cloud.bigtable.error import Status | ||
|
||
|
||
class EncryptionInfo: | ||
"""Encryption information for a given resource. | ||
If this resource is protected with customer managed encryption, the in-use Google | ||
Cloud Key Management Service (KMS) key versions will be specified along with their | ||
status. | ||
:type encryption_type: int | ||
:param encryption_type: See :class:`enums.EncryptionInfo.EncryptionType` | ||
:type encryption_status: google.cloud.bigtable.encryption.Status | ||
:param encryption_status: The encryption status. | ||
:type kms_key_version: str | ||
:param kms_key_version: The key version used for encryption. | ||
""" | ||
|
||
@classmethod | ||
def _from_pb(cls, info_pb): | ||
return cls( | ||
info_pb.encryption_type, | ||
Status(info_pb.encryption_status), | ||
info_pb.kms_key_version, | ||
) | ||
|
||
def __init__(self, encryption_type, encryption_status, kms_key_version): | ||
self.encryption_type = encryption_type | ||
self.encryption_status = encryption_status | ||
self.kms_key_version = kms_key_version | ||
|
||
def __eq__(self, other): | ||
if self is other: | ||
return True | ||
|
||
if not isinstance(other, type(self)): | ||
return NotImplemented | ||
|
||
return ( | ||
self.encryption_type == other.encryption_type | ||
and self.encryption_status == other.encryption_status | ||
and self.kms_key_version == other.kms_key_version | ||
) | ||
|
||
def __ne__(self, other): | ||
return not self == other |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Copyright 2021 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. | ||
|
||
"""Class for error status.""" | ||
|
||
|
||
class Status: | ||
"""A status, comprising a code and a message. | ||
See: `Cloud APIs Errors <https://cloud.google.com/apis/design/errors>`_ | ||
This is a thin wrapper for ``google.rpc.status_pb2.Status``. | ||
:type status_pb: google.rpc.status_pb2.Status | ||
:param status_pb: The status protocol buffer. | ||
""" | ||
|
||
def __init__(self, status_pb): | ||
self.status_pb = status_pb | ||
|
||
@property | ||
def code(self): | ||
"""The status code. | ||
Values are defined in ``google.rpc.code_pb2.Code``. | ||
See: `google.rpc.Code | ||
<https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto>`_ | ||
:rtype: int | ||
:returns: The status code. | ||
""" | ||
return self.status_pb.code | ||
|
||
@property | ||
def message(self): | ||
"""A human readable status message. | ||
:rypte: str | ||
:returns: The status message. | ||
""" | ||
return self.status_pb.message | ||
|
||
def __repr__(self): | ||
return repr(self.status_pb) | ||
|
||
def __eq__(self, other): | ||
if isinstance(other, type(self)): | ||
return self.status_pb == other.status_pb | ||
return NotImplemented | ||
|
||
def __ne__(self, other): | ||
return not self == other |
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
Oops, something went wrong.