Skip to content
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(storage): support for encryption at rest flag #141

Merged
merged 7 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

----
### Added

- Storage encryption at rest support via `encrypted`
villevsv-upcloud marked this conversation as resolved.
Show resolved Hide resolved

## [2.5.1] - 2023-09-19

Expand Down
3 changes: 2 additions & 1 deletion docs/Storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ storage1 = manager.create_storage(
zone='fi-hel1',
size=10,
tier="maxiops",
title="my storage disk"
title="my storage disk",
encrypted=True
villevsv-upcloud marked this conversation as resolved.
Show resolved Hide resolved
)

storage2 = manager.create_storage(zone='de-fra1', size=100)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"backups" : {
"backup" : []
},
"encrypted": "yes",
"labels": [
{
"key": "role",
Expand Down
1 change: 1 addition & 0 deletions test/json_data/storage_post.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"backups": {
"backup": []
},
"encrypted": "yes",
"labels": [
{
"key": "role",
Expand Down
4 changes: 3 additions & 1 deletion test/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ def test_get_templates(self, manager):
def test_storage_create(self, manager):
Mock.mock_post("storage")
storage = manager.create_storage(
zone="fi-hel1", size=666, tier="maxiops", title="My data collection"
zone="fi-hel1", encrypted=True, size=666, tier="maxiops", title="My data collection"
)
assert type(storage).__name__ == "Storage"
assert storage.encrypted
assert storage.size == 666
assert storage.tier == "maxiops"
assert storage.title == "My data collection"
Expand All @@ -47,6 +48,7 @@ def test_clone_storage(self, manager):
Mock.mock_post("storage/01d4fcd4-e446-433b-8a9c-551a1284952e/clone")
cloned_storage = storage.clone('cloned-storage-test', 'fi-hel1')
assert type(cloned_storage).__name__ == "Storage"
assert not cloned_storage.encrypted
assert cloned_storage.size == 666
assert cloned_storage.tier == "maxiops"
assert cloned_storage.title == "cloned-storage-test"
Expand Down
8 changes: 8 additions & 0 deletions upcloud_api/cloud_manager/storage_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def create_storage(
size: int = 10,
tier: str = 'maxiops',
title: str = 'Storage disk',
encrypted: bool = False,
*,
backup_rule: Optional[dict] = None,
) -> Storage:
Expand All @@ -53,13 +54,20 @@ def create_storage(
"""
if backup_rule is None:
backup_rule = {}

if encrypted:
encrypted_str = 'yes'
else:
encrypted_str = 'no'
villevsv-upcloud marked this conversation as resolved.
Show resolved Hide resolved

body = {
'storage': {
'size': size,
'tier': tier,
'title': title,
'zone': zone,
'backup_rule': backup_rule,
'encrypted': encrypted_str,
}
}
res = self.api.post_request('/storage', body)
Expand Down
20 changes: 19 additions & 1 deletion upcloud_api/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Storage(UpCloudResource):
ATTRIBUTES = {
'access': None,
'address': None,
'encrypted': None,
'labels': None,
'license': None,
'state': None,
Expand Down Expand Up @@ -55,12 +56,26 @@ def _reset(self, **kwargs) -> None:
elif 'storage_size' in kwargs:
self.size = kwargs['storage_size']

if 'encrypted' in kwargs and kwargs['encrypted'] == 'yes':
villevsv-upcloud marked this conversation as resolved.
Show resolved Hide resolved
self.encrypted = True
else:
self.encrypted = False

# send the rest to super._reset

filtered_kwargs = {
key: val
for key, val in kwargs.items()
if key not in ['uuid', 'storage', 'title', 'storage_title', 'size', 'storage_size']
if key
not in [
'uuid',
'storage',
'title',
'storage_title',
'size',
'storage_size',
'encrypted',
]
}
super()._reset(**filtered_kwargs)

Expand Down Expand Up @@ -153,6 +168,9 @@ def to_dict(self):
dict_labels.append(label.to_dict())
body['labels'] = dict_labels

if hasattr(self, 'enrypted') and isinstance(self.enrypted, bool):
body['server']['enrypted'] = "yes" if self.enrypted else "no"
villevsv-upcloud marked this conversation as resolved.
Show resolved Hide resolved

return body

@staticmethod
Expand Down
Loading