Skip to content

Commit

Permalink
feat(storage): support for encryption at rest flag (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
villevsv-upcloud authored May 27, 2024
1 parent 726b0ab commit 634bd24
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 4 deletions.
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

- Added `encrypted` boolean flag to Storage for encryption at rest support

## [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=False
)

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
5 changes: 5 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,17 @@ def create_storage(
"""
if backup_rule is None:
backup_rule = {}

encrypted_str = 'yes' if encrypted else 'no'

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 kwargs.get('encrypted') == 'yes':
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, 'encrypted') and isinstance(self.encrypted, bool):
body['encrypted'] = "yes" if self.encrypted else "no"

return body

@staticmethod
Expand Down

0 comments on commit 634bd24

Please sign in to comment.