-
Notifications
You must be signed in to change notification settings - Fork 16
/
backupunit.go
178 lines (150 loc) · 4.48 KB
/
backupunit.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package profitbricks
import (
"github.com/ionos-cloud/sdk-go/v5"
"net/http"
)
// BackupUnits type
type BackupUnits 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 []BackupUnit `json:"items"`
}
// BackupUnit Object
type BackupUnit 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 backupunit
// Read Only: true
Type string `json:"type,omitempty"`
// The metadata for the backup unit
// Read Only: true
Metadata *Metadata `json:"metadata,omitempty"`
Properties *BackupUnitProperties `json:"properties,omitempty"`
}
// BackupUnitProperties object
type BackupUnitProperties struct {
// Required: on create
// Read only: yes
Name string `json:"name,omitempty"`
// Required: yes
Password string `json:"password,omitempty"`
// Required: yes
Email string `json:"email,omitempty"`
}
// BackupUnitSSOURL object
type BackupUnitSSOURL struct {
// The type of object. In this case backupunit
// Read Only: true
Type string `json:"type,omitempty"`
// SSO URL
// Read Only: true
SSOUrl string `json:"ssoURL,omitempty"`
}
//
// CreateBackupUnit creates a Backup Unit
func (c *Client) CreateBackupUnit(backupUnit BackupUnit) (*BackupUnit, error) {
// rsp := &BackupUnit{}
input := ionoscloud.BackupUnit{}
err := convertToCore(&backupUnit, &input)
ctx, cancel := c.GetContext()
if cancel != nil {
defer cancel()
}
rsp, _, err := c.CoreSdk.BackupUnitApi.BackupunitsPost(ctx).BackupUnit(input).Execute()
ret := BackupUnit{}
errConvert := convertToCompat(&rsp, &ret)
if errConvert != nil {
return nil, errConvert
}
return &ret, err
// return rsp, c.PostAcc(backupUnitsPath(), backupUnit, rsp)
}
// ListBackupUnits lists all available backup units
func (c *Client) ListBackupUnits() (*BackupUnits, error) {
ctx, cancel := c.GetContext()
if cancel != nil {
defer cancel()
}
rsp, _, err := c.CoreSdk.BackupUnitApi.BackupunitsGet(ctx).Execute()
ret := BackupUnits{}
if errConvert := convertToCompat(&rsp, &ret); errConvert != nil {
return nil, errConvert
}
return &ret, err
}
// UpdateBackupUnit updates an existing backup unit
func (c *Client) UpdateBackupUnit(backupUnitID string, backupUnit BackupUnit) (*BackupUnit, error) {
input := ionoscloud.BackupUnit{}
if errConv := convertToCore(&backupUnit, &input); errConv != nil {
return nil, errConv
}
ctx, cancel := c.GetContext()
if cancel != nil {
defer cancel()
}
rsp, _, err := c.CoreSdk.BackupUnitApi.BackupunitsPut(ctx, backupUnitID).BackupUnit(input).Execute()
ret := BackupUnit{}
if errConv := convertToCompat(&rsp, &ret); errConv != nil {
return nil, errConv
}
return &ret, err
// rsp := &BackupUnit{}
// return rsp, c.PutAcc(backupUnitPath(backupUnitID), backupUnit, rsp)
}
// DeleteBackupUnit deletes an existing backup unit
func (c *Client) DeleteBackupUnit(backupUnitID string) (*http.Header, error) {
ctx, cancel := c.GetContext()
if cancel != nil {
defer cancel()
}
_, httpResponse, err := c.CoreSdk.BackupUnitApi.BackupunitsDelete(ctx, backupUnitID).Execute()
if httpResponse == nil || err != nil {
return nil, err
}
return &httpResponse.Header, err
// return c.DeleteAcc(backupUnitPath(backupUnitID))
}
// GetBackupUnit retrieves an existing backup unit
func (c *Client) GetBackupUnit(backupUnitID string) (*BackupUnit, error) {
ctx, cancel := c.GetContext()
if cancel != nil {
defer cancel()
}
rsp, _, err := c.CoreSdk.BackupUnitApi.BackupunitsFindById(ctx, backupUnitID).Execute()
ret := BackupUnit{}
if errConv := convertToCompat(&rsp, &ret); errConv != nil {
return nil, errConv
}
return &ret, err
// rsp := &BackupUnit{}
// return rsp, c.GetOK(backupUnitPath(backupUnitID), rsp)
}
// GetBackupUnitSSOURL retrieves the SSO URL for an existing backup unit
func (c *Client) GetBackupUnitSSOURL(backupUnitID string) (*BackupUnitSSOURL, error) {
ctx, cancel := c.GetContext()
if cancel != nil {
defer cancel()
}
rsp, _, err := c.CoreSdk.BackupUnitApi.BackupunitsSsourlGet(ctx, backupUnitID).Execute()
if err != nil {
return nil, err
}
return &BackupUnitSSOURL{
Type: "backupunit",
SSOUrl: *rsp.SsoUrl,
}, err
// rsp := &BackupUnitSSOURL{}
// return rsp, c.GetOK(backupUnitSSOURLPath(backupUnitID), rsp)
}