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
feat: customer managed keys (CMEK) #249
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
5c9b61a
feat: customer managed keys (CMEK)
1f3bc49
Wrap Status.
ea5dde1
Wrapper for Status, reorganize to avoid circular imports.
47b84b6
Blacken.
20c8ba7
Make system tests in charge of their own key.
df7bdc5
Consolidate system tests. Get KMS_KEY_NAME from user's environment.
2e31436
Fix test.
cf0176e
Lint.
6601e03
Put system tests where nox is expecting to find them.
76e1651
Test backup with CMEK.
731efdd
Differentiate instance and cluster names for cmek test, so tests aren…
090080e
rename `encryption.py` to `encryption_info.py`
f1aae9d
make sure `kms_key_name` is set to `None` if `encryption_info` is not
e7a45ee
Fix typo. Use more realistic looking test strings.
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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``. | ||
kolea2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
: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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does this default to if this condition is not met?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops. If it's being called from the constructor, it will be None, but we can't assume that can we? I'll add an
else
here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
f1aae9d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh sorry missed that, makes sense thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, you correctly pointed out a logical error, which I corrected. Thank you!