-
Notifications
You must be signed in to change notification settings - Fork 16
/
s3key.go
147 lines (127 loc) · 3.53 KB
/
s3key.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package profitbricks
import (
"context"
"github.com/ionos-cloud/sdk-go/v5"
"net/http"
)
// S3Keys type
type S3Keys struct {
// Enum: [backupunits]
// Read Only: true
ID string `json:"id,omitempty"`
// Enum: [collection]
// Read Only: true
Type string `json:"type,omitempty"`
// Format: uri
Href string `json:"href"`
// Read Only: true
Items []S3Key `json:"items"`
}
// S3Key Object
type S3Key struct {
// URL to the object representation (absolute path)
// Read Only: true
// Format: uri
Href string `json:"href,omitempty"`
// The resource's unique identifier.
// Read Only: true
ID string `json:"id,omitempty"`
// The type of object. In this case s3key
// Read Only: true
Type string `json:"type,omitempty"`
// The metadata for the S3 key
// Read Only: true
Metadata *Metadata `json:"metadata,omitempty"`
// The properties of the S3 key
// Read Only: false
Properties *S3KeyProperties `json:"properties,omitempty"`
}
// S3KeyProperties object
type S3KeyProperties struct {
// Read only: yes
SecretKey string `json:"secretKey,omitempty"`
// Required: yes
// Read only: no
Active bool `json:"active"`
}
// CreateS3Key creates an S3 Key for an user
func (c *Client) CreateS3Key(userID string) (*S3Key, error) {
ctx, cancel := c.GetContext()
if cancel != nil {
defer cancel()
}
rsp, _, err := c.CoreSdk.UserManagementApi.UmUsersS3keysPost(ctx, userID).Execute()
ret := S3Key{}
if errConvert := convertToCompat(&rsp, &ret); errConvert != nil {
return nil, errConvert
}
return &ret, err
/*
rsp := &S3Key{}
var requestBody interface{}
err := c.Post(s3KeysPath(userID), requestBody, rsp, http.StatusCreated)
return rsp, err
*/
}
// ListS3Keys lists all available S3 keys for an user
func (c *Client) ListS3Keys(userID string) (*S3Keys, error) {
ctx, cancel := c.GetContext()
if cancel != nil {
defer cancel()
}
rsp, _, err := c.CoreSdk.UserManagementApi.UmUsersS3keysGet(ctx, userID).Execute()
ret := S3Keys{}
if errConvert := convertToCompat(&rsp, &ret); errConvert != nil {
return nil, errConvert
}
return &ret, err
/*
rsp := &S3Keys{}
return rsp, c.GetOK(s3KeysListPath(userID), rsp)
*/
}
// UpdateS3Key updates an existing S3 key
func (c *Client) UpdateS3Key(userID string, s3KeyID string, s3Key S3Key) (*S3Key, error) {
input := ionoscloud.S3Key{}
if errConvert := convertToCore(&s3Key, &input); errConvert != nil {
return nil, errConvert
}
rsp, _, err := c.CoreSdk.UserManagementApi.UmUsersS3keysPut(
context.TODO(), userID, s3KeyID).S3Key(input).Execute()
ret := S3Key{}
if errConvert := convertToCompat(&rsp, &ret); errConvert != nil {
return nil, errConvert
}
return &ret, err
/*
rsp := &S3Key{}
return rsp, c.PutAcc(s3KeyPath(userID, s3KeyID), s3Key, rsp)
*/
}
// DeleteS3Key deletes an existing S3 key
func (c *Client) DeleteS3Key(userID string, s3KeyID string) (*http.Header, error) {
ctx, cancel := c.GetContext()
if cancel != nil {
defer cancel()
}
_, apiResponse, err := c.CoreSdk.UserManagementApi.UmUsersS3keysDelete(ctx, userID, s3KeyID).Execute()
if apiResponse != nil {
return &apiResponse.Header, err
} else {
return nil, err
}
}
// GetS3Key retrieves an existing S3 key
func (c *Client) GetS3Key(userID string, s3KeyID string) (*S3Key, error) {
rsp, _, err := c.CoreSdk.UserManagementApi.UmUsersS3keysFindByKeyId(
context.TODO(), userID, s3KeyID).Execute()
ret := S3Key{}
if errConvert := convertToCompat(&rsp, &ret); errConvert != nil {
return nil, errConvert
}
return &ret, err
/*
rsp := &S3Key{}
return rsp, c.GetOK(s3KeyPath(userID, s3KeyID), rsp)
*/
}