Skip to content

Commit 40065c0

Browse files
authored
feat(storage): add support for encryption (#287)
1 parent 148c897 commit 40065c0

File tree

7 files changed

+37
-24
lines changed

7 files changed

+37
-24
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ See updating [Changelog example here](https://keepachangelog.com/en/1.0.0/)
77

88
### Added
99
- Server groups: Add `AddServerToServerGroup` and `RemoveServerFromServerGroup` methods.
10+
- Storages: Add support for encryption at rest
1011

1112
### Fixed
1213
- Managed Object Storage: use correct path for `GetManagedObjectStorageBucketMetricsRequest`

upcloud/request/server.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,11 @@ func (s CreateServerIPAddressSlice) MarshalJSON() ([]byte, error) {
7474

7575
// CreateServerStorageDevice represents a storage device for a CreateServerRequest
7676
type CreateServerStorageDevice struct {
77-
Action string `json:"action"`
78-
Address string `json:"address,omitempty"`
79-
Storage string `json:"storage"`
80-
Title string `json:"title,omitempty"`
77+
Action string `json:"action"`
78+
Address string `json:"address,omitempty"`
79+
Encrypted upcloud.Boolean `json:"encrypted,omitempty"`
80+
Storage string `json:"storage"`
81+
Title string `json:"title,omitempty"`
8182
// Storage size in gigabytes
8283
Size int `json:"size,omitempty"`
8384
Tier string `json:"tier,omitempty"`

upcloud/request/storage.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ func (r *GetStorageDetailsRequest) RequestURL() string {
6666
// CreateStorageRequest represents a request to create a storage device
6767
type CreateStorageRequest struct {
6868
Size int `json:"size,string"`
69+
Encrypted upcloud.Boolean `json:"encrypted,omitempty"`
6970
Tier string `json:"tier,omitempty"`
7071
Title string `json:"title,omitempty"`
7172
Zone string `json:"zone"`
@@ -186,9 +187,10 @@ func (r *DeleteStorageRequest) RequestURL() string {
186187
type CloneStorageRequest struct {
187188
UUID string `json:"-"`
188189

189-
Zone string `json:"zone"`
190-
Tier string `json:"tier,omitempty"`
191-
Title string `json:"title"`
190+
Encrypted upcloud.Boolean `json:"encrypted,omitempty"`
191+
Zone string `json:"zone"`
192+
Tier string `json:"tier,omitempty"`
193+
Title string `json:"title"`
192194
}
193195

194196
// RequestURL implements the Request interface

upcloud/request/storage_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,11 @@ func TestGetStorageDetailsRequest(t *testing.T) {
5959
// TestCreateStorageRequest tests that CreateStorageRequest objects behave correctly
6060
func TestCreateStorageRequest(t *testing.T) {
6161
request := CreateStorageRequest{
62-
Tier: upcloud.StorageTierMaxIOPS,
63-
Title: "Test storage",
64-
Size: 10,
65-
Zone: "fi-hel2",
62+
Encrypted: upcloud.FromBool(true),
63+
Tier: upcloud.StorageTierMaxIOPS,
64+
Title: "Test storage",
65+
Size: 10,
66+
Zone: "fi-hel2",
6667
BackupRule: &upcloud.BackupRule{
6768
Interval: upcloud.BackupRuleIntervalDaily,
6869
Time: "0430",
@@ -73,6 +74,7 @@ func TestCreateStorageRequest(t *testing.T) {
7374
expectedJSON := `
7475
{
7576
"storage": {
77+
"encrypted": "yes",
7678
"size": "10",
7779
"tier": "maxiops",
7880
"title": "Test storage",

upcloud/server_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ func TestUnmarshalServerDetails(t *testing.T) {
215215
"storage_device": [
216216
{
217217
"address": "virtio:0",
218+
"storage_encrypted": "yes",
218219
"part_of_plan" : "yes",
219220
"storage": "012580a1-32a1-466e-a323-689ca16f2d43",
220221
"storage_size": 20,
@@ -249,6 +250,7 @@ func TestUnmarshalServerDetails(t *testing.T) {
249250
err := json.Unmarshal([]byte(originalJSON), &serverDetails)
250251
assert.Nil(t, err)
251252

253+
assert.Equal(t, true, serverDetails.StorageDevices[0].Encrypted.Bool())
252254
assert.Equal(t, "cdrom,disk", serverDetails.BootOrder)
253255
assert.Equal(t, "on", serverDetails.Firewall)
254256
assert.Len(t, serverDetails.IPAddresses, 3)

upcloud/storage.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@ func (s *Storages) UnmarshalJSON(b []byte) error {
7474

7575
// Storage represents a storage device
7676
type Storage struct {
77-
Access string `json:"access"`
78-
License float64 `json:"license"`
77+
Access string `json:"access"`
78+
Encrypted Boolean `json:"encrypted"`
79+
License float64 `json:"license"`
7980
// TODO: Convert to boolean
8081
PartOfPlan string `json:"part_of_plan"`
8182
Size int `json:"size"`
@@ -148,7 +149,8 @@ type BackupRule struct {
148149

149150
// ServerStorageDevice represents a storage device in the context of server requests or server details
150151
type ServerStorageDevice struct {
151-
Address string `json:"address"`
152+
Address string `json:"address"`
153+
Encrypted Boolean `json:"storage_encrypted"`
152154
// TODO: Convert to boolean
153155
PartOfPlan string `json:"part_of_plan"`
154156
UUID string `json:"storage"`
@@ -159,7 +161,7 @@ type ServerStorageDevice struct {
159161
BootDisk int `json:"boot_disk,string"`
160162
}
161163

162-
// StorageImportDetails represents the details of an ongoing or completed storge import operation.
164+
// StorageImportDetails represents the details of an ongoing or completed storage import operation.
163165
type StorageImportDetails struct {
164166
ClientContentLength int `json:"client_content_length"`
165167
ClientContentType string `json:"client_content_type"`

upcloud/storage_test.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ func TestUnmarshalStorage(t *testing.T) {
1616
"storage": [
1717
{
1818
"access": "private",
19+
"encrypted": "yes",
1920
"license": 0,
2021
"size": 10,
2122
"state": "online",
@@ -27,6 +28,7 @@ func TestUnmarshalStorage(t *testing.T) {
2728
},
2829
{
2930
"access" : "private",
31+
"encrypted": "no",
3032
"created" : "2019-09-17T14:34:43Z",
3133
"license" : 0,
3234
"origin" : "01eff7ad-168e-413e-83b0-054f6a28fa23",
@@ -66,15 +68,16 @@ func TestUnmarshalStorage(t *testing.T) {
6668

6769
testData := []Storage{
6870
{
69-
Access: StorageAccessPrivate,
70-
License: 0.0,
71-
Size: 10,
72-
State: StorageStateOnline,
73-
Tier: StorageTierHDD,
74-
Title: "Operating system disk",
75-
Type: StorageTypeNormal,
76-
UUID: "01eff7ad-168e-413e-83b0-054f6a28fa23",
77-
Zone: "uk-lon1",
71+
Access: StorageAccessPrivate,
72+
Encrypted: FromBool(true),
73+
License: 0.0,
74+
Size: 10,
75+
State: StorageStateOnline,
76+
Tier: StorageTierHDD,
77+
Title: "Operating system disk",
78+
Type: StorageTypeNormal,
79+
UUID: "01eff7ad-168e-413e-83b0-054f6a28fa23",
80+
Zone: "uk-lon1",
7881
},
7982
{
8083
Access: StorageAccessPrivate,

0 commit comments

Comments
 (0)