Skip to content

Commit

Permalink
feat(storage): add support for encryption
Browse files Browse the repository at this point in the history
  • Loading branch information
kangasta committed Jan 19, 2024
1 parent 2de2f21 commit 238b040
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 24 deletions.
9 changes: 5 additions & 4 deletions upcloud/request/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ func (s CreateServerIPAddressSlice) MarshalJSON() ([]byte, error) {

// CreateServerStorageDevice represents a storage device for a CreateServerRequest
type CreateServerStorageDevice struct {
Action string `json:"action"`
Address string `json:"address,omitempty"`
Storage string `json:"storage"`
Title string `json:"title,omitempty"`
Action string `json:"action"`
Address string `json:"address,omitempty"`
Encrypted upcloud.Boolean `json:"encrypted,omitempty"`
Storage string `json:"storage"`
Title string `json:"title,omitempty"`
// Storage size in gigabytes
Size int `json:"size,omitempty"`
Tier string `json:"tier,omitempty"`
Expand Down
8 changes: 5 additions & 3 deletions upcloud/request/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func (r *GetStorageDetailsRequest) RequestURL() string {
// CreateStorageRequest represents a request to create a storage device
type CreateStorageRequest struct {
Size int `json:"size,string"`
Encrypted upcloud.Boolean `json:"encrypted,omitempty"`
Tier string `json:"tier,omitempty"`
Title string `json:"title,omitempty"`
Zone string `json:"zone"`
Expand Down Expand Up @@ -186,9 +187,10 @@ func (r *DeleteStorageRequest) RequestURL() string {
type CloneStorageRequest struct {
UUID string `json:"-"`

Zone string `json:"zone"`
Tier string `json:"tier,omitempty"`
Title string `json:"title"`
Encrypted upcloud.Boolean `json:"encrypted,omitempty"`
Zone string `json:"zone"`
Tier string `json:"tier,omitempty"`
Title string `json:"title"`
}

// RequestURL implements the Request interface
Expand Down
10 changes: 6 additions & 4 deletions upcloud/request/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ func TestGetStorageDetailsRequest(t *testing.T) {
// TestCreateStorageRequest tests that CreateStorageRequest objects behave correctly
func TestCreateStorageRequest(t *testing.T) {
request := CreateStorageRequest{
Tier: upcloud.StorageTierMaxIOPS,
Title: "Test storage",
Size: 10,
Zone: "fi-hel2",
Encrypted: upcloud.FromBool(true),
Tier: upcloud.StorageTierMaxIOPS,
Title: "Test storage",
Size: 10,
Zone: "fi-hel2",
BackupRule: &upcloud.BackupRule{
Interval: upcloud.BackupRuleIntervalDaily,
Time: "0430",
Expand All @@ -73,6 +74,7 @@ func TestCreateStorageRequest(t *testing.T) {
expectedJSON := `
{
"storage": {
"encrypted": "yes",
"size": "10",
"tier": "maxiops",
"title": "Test storage",
Expand Down
2 changes: 2 additions & 0 deletions upcloud/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ func TestUnmarshalServerDetails(t *testing.T) {
"storage_device": [
{
"address": "virtio:0",
"storage_encrypted": "yes",
"part_of_plan" : "yes",
"storage": "012580a1-32a1-466e-a323-689ca16f2d43",
"storage_size": 20,
Expand Down Expand Up @@ -249,6 +250,7 @@ func TestUnmarshalServerDetails(t *testing.T) {
err := json.Unmarshal([]byte(originalJSON), &serverDetails)
assert.Nil(t, err)

assert.Equal(t, true, serverDetails.StorageDevices[0].Encrypted.Bool())
assert.Equal(t, "cdrom,disk", serverDetails.BootOrder)
assert.Equal(t, "on", serverDetails.Firewall)
assert.Len(t, serverDetails.IPAddresses, 3)
Expand Down
10 changes: 6 additions & 4 deletions upcloud/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ func (s *Storages) UnmarshalJSON(b []byte) error {

// Storage represents a storage device
type Storage struct {
Access string `json:"access"`
License float64 `json:"license"`
Access string `json:"access"`
Encrypted Boolean `json:"encrypted"`
License float64 `json:"license"`
// TODO: Convert to boolean
PartOfPlan string `json:"part_of_plan"`
Size int `json:"size"`
Expand Down Expand Up @@ -148,7 +149,8 @@ type BackupRule struct {

// ServerStorageDevice represents a storage device in the context of server requests or server details
type ServerStorageDevice struct {
Address string `json:"address"`
Address string `json:"address"`
Encrypted Boolean `json:"storage_encrypted"`
// TODO: Convert to boolean
PartOfPlan string `json:"part_of_plan"`
UUID string `json:"storage"`
Expand All @@ -159,7 +161,7 @@ type ServerStorageDevice struct {
BootDisk int `json:"boot_disk,string"`
}

// StorageImportDetails represents the details of an ongoing or completed storge import operation.
// StorageImportDetails represents the details of an ongoing or completed storage import operation.
type StorageImportDetails struct {
ClientContentLength int `json:"client_content_length"`
ClientContentType string `json:"client_content_type"`
Expand Down
21 changes: 12 additions & 9 deletions upcloud/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func TestUnmarshalStorage(t *testing.T) {
"storage": [
{
"access": "private",
"encrypted": "yes",
"license": 0,
"size": 10,
"state": "online",
Expand All @@ -27,6 +28,7 @@ func TestUnmarshalStorage(t *testing.T) {
},
{
"access" : "private",
"encrypted": "no",
"created" : "2019-09-17T14:34:43Z",
"license" : 0,
"origin" : "01eff7ad-168e-413e-83b0-054f6a28fa23",
Expand Down Expand Up @@ -66,15 +68,16 @@ func TestUnmarshalStorage(t *testing.T) {

testData := []Storage{
{
Access: StorageAccessPrivate,
License: 0.0,
Size: 10,
State: StorageStateOnline,
Tier: StorageTierHDD,
Title: "Operating system disk",
Type: StorageTypeNormal,
UUID: "01eff7ad-168e-413e-83b0-054f6a28fa23",
Zone: "uk-lon1",
Access: StorageAccessPrivate,
Encrypted: FromBool(true),
License: 0.0,
Size: 10,
State: StorageStateOnline,
Tier: StorageTierHDD,
Title: "Operating system disk",
Type: StorageTypeNormal,
UUID: "01eff7ad-168e-413e-83b0-054f6a28fa23",
Zone: "uk-lon1",
},
{
Access: StorageAccessPrivate,
Expand Down

0 comments on commit 238b040

Please sign in to comment.