forked from bizflycloud/gobizfly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloud_backup_storage_vault.go
93 lines (86 loc) · 2.96 KB
/
cloud_backup_storage_vault.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package gobizfly
import (
"context"
"encoding/json"
"net/http"
)
// CloudBackupStorageVault represents a Cloud Backup Storage Vault.
type CloudBackupStorageVault struct {
CreatedAt string `json:"created_at"`
CredentialType string `json:"credential_type"`
DataUsage string `json:"data_usage"`
Deleted bool `json:"deleted"`
EncryptionKey string `json:"encryption_key"`
Id string `json:"id"`
Name string `json:"name"`
SecretRef string `json:"secret_ref"`
StorageBucket string `json:"storage_bucket"`
StorageVaultType string `json:"storage_vault_type"`
TenantId string `json:"tenant_id"`
UpdatedAt string `json:"updated_at"`
}
// CloudBackupCreateStorageVaultPayload represents the payload for creating a Cloud Backup Storage Vault.
type CloudBackupCreateStorageVaultPayload struct {
AwsAccessKeyId string `json:"aws_access_key_id"`
AwsSecretAccessKey string `json:"aws_secret_access_key"`
EndpointUrl string `json:"endpoint_url"`
StorageVaultType string `json:"storage_vault_type"`
Name string `json:"name"`
StorageBucket string `json:"storage_bucket"`
CredentialType string `json:"credential_type"`
}
// ListStorageVaults lists all Cloud Backup Storage Vaults.
func (cb *cloudBackupService) ListStorageVaults(ctx context.Context) ([]*CloudBackupStorageVault, error) {
req, err := cb.client.NewRequest(ctx, http.MethodGet, cloudBackupServiceName,
cb.storageVaultsPath(), nil)
if err != nil {
return nil, err
}
resp, err := cb.client.Do(ctx, req)
if err != nil {
return nil, err
}
var data struct {
StorageVaults []*CloudBackupStorageVault `json:"storage_vaults"`
}
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
return nil, err
}
return data.StorageVaults, nil
}
// GetStorageVault gets a Cloud Backup Storage Vault.
func (cb *cloudBackupService) GetStorageVault(ctx context.Context, valutId string) (*CloudBackupStorageVault, error) {
req, err := cb.client.NewRequest(ctx, http.MethodGet, cloudBackupServiceName,
cb.itemStorageVaultPath(valutId), nil)
if err != nil {
return nil, err
}
resp, err := cb.client.Do(ctx, req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var vault *CloudBackupStorageVault
if err := json.NewDecoder(resp.Body).Decode(&vault); err != nil {
return nil, err
}
return vault, nil
}
// CreateStorageVault creates a Cloud Backup Storage Vault.
func (cb *cloudBackupService) CreateStorageVault(ctx context.Context, payload *CloudBackupCreateStorageVaultPayload) (*CloudBackupStorageVault, error) {
req, err := cb.client.NewRequest(ctx, http.MethodPost, cloudBackupServiceName,
cb.storageVaultsPath(), payload)
if err != nil {
return nil, err
}
resp, err := cb.client.Do(ctx, req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var vault *CloudBackupStorageVault
if err := json.NewDecoder(resp.Body).Decode(&vault); err != nil {
return nil, err
}
return vault, nil
}