Skip to content

Commit 1953a69

Browse files
Monitobremyleone
andauthored
fix(rdb): add missing fields on backup builder (#2586)
Co-authored-by: Rémy Léone <[email protected]>
1 parent d19e6ad commit 1953a69

File tree

3 files changed

+99
-29
lines changed

3 files changed

+99
-29
lines changed

internal/namespaces/rdb/v1/custom.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func GetCommands() *core.Commands {
2323

2424
human.RegisterMarshalerFunc(rdb.Instance{}, instanceMarshalerFunc)
2525
human.RegisterMarshalerFunc(rdb.BackupSchedule{}, backupScheduleMarshalerFunc)
26-
human.RegisterMarshalerFunc(backupDownloadResult{}, backupResultMarshalerFunc)
26+
human.RegisterMarshalerFunc(backupDownloadResult{}, backupResultMarshallerFunc)
2727

2828
human.RegisterMarshalerFunc(rdb.InstanceStatus(""), human.EnumMarshalFunc(instanceStatusMarshalSpecs))
2929
human.RegisterMarshalerFunc(rdb.DatabaseBackupStatus(""), human.EnumMarshalFunc(backupStatusMarshalSpecs))

internal/namespaces/rdb/v1/custom_backup.go

Lines changed: 71 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,20 @@ func backupRestoreBuilder(c *core.Command) *core.Command {
121121

122122
func backupListBuilder(c *core.Command) *core.Command {
123123
type customBackup struct {
124-
ID string `json:"ID"`
125-
Name string `json:"name"`
126-
InstanceID string `json:"instance_ID"`
127-
Exported bool `json:"exported"`
128-
Status rdb.DatabaseBackupStatus `json:"status"`
124+
ID string `json:"ID"`
125+
InstanceID string `json:"instance_ID"`
126+
DatabaseName string `json:"database_name"`
127+
Name string `json:"name"`
128+
Status rdb.DatabaseBackupStatus `json:"status"`
129+
Size *scw.Size `json:"size"`
130+
ExpiresAt *time.Time `json:"expires_at"`
131+
CreatedAt *time.Time `json:"created_at"`
132+
UpdatedAt *time.Time `json:"updated_at"`
133+
InstanceName string `json:"instance_name"`
134+
DownloadURL string `json:"download_url"`
135+
URLExpired bool `json:"url_expired"`
136+
Region scw.Region `json:"region"`
137+
SameRegion bool `json:"same_region"`
129138
}
130139

131140
c.View = &core.View{
@@ -138,6 +147,14 @@ func backupListBuilder(c *core.Command) *core.Command {
138147
Label: "Name",
139148
FieldName: "Name",
140149
},
150+
{
151+
Label: "Database Name",
152+
FieldName: "DatabaseName",
153+
},
154+
{
155+
Label: "Size",
156+
FieldName: "Size",
157+
},
141158
{
142159
Label: "Status",
143160
FieldName: "Status",
@@ -147,8 +164,32 @@ func backupListBuilder(c *core.Command) *core.Command {
147164
FieldName: "InstanceID",
148165
},
149166
{
150-
Label: "Exported",
151-
FieldName: "Exported",
167+
Label: "URL Expired",
168+
FieldName: "URLExpired",
169+
},
170+
{
171+
Label: "Download URL",
172+
FieldName: "DownloadURL",
173+
},
174+
{
175+
Label: "Expires At",
176+
FieldName: "ExpiresAt",
177+
},
178+
{
179+
Label: "Created At",
180+
FieldName: "CreatedAt",
181+
},
182+
{
183+
Label: "Updated At",
184+
FieldName: "UpdatedAt",
185+
},
186+
{
187+
Label: "Region",
188+
FieldName: "Region",
189+
},
190+
{
191+
Label: "Same Region",
192+
FieldName: "SameRegion",
152193
},
153194
},
154195
}
@@ -161,12 +202,25 @@ func backupListBuilder(c *core.Command) *core.Command {
161202
backupList := listBackupResp.([]*rdb.DatabaseBackup)
162203
var res []customBackup
163204
for _, backup := range backupList {
205+
downloadURL := ""
206+
if backup.DownloadURL != nil {
207+
downloadURL = *backup.DownloadURL
208+
}
164209
res = append(res, customBackup{
165-
ID: backup.ID,
166-
Name: backup.Name,
167-
Status: backup.Status,
168-
InstanceID: backup.InstanceID,
169-
Exported: isExported(backup.DownloadURLExpiresAt),
210+
ID: backup.ID,
211+
InstanceID: backup.InstanceID,
212+
DatabaseName: backup.DatabaseName,
213+
Name: backup.Name,
214+
Status: backup.Status,
215+
Size: backup.Size,
216+
ExpiresAt: backup.ExpiresAt,
217+
CreatedAt: backup.CreatedAt,
218+
UpdatedAt: backup.UpdatedAt,
219+
InstanceName: backup.InstanceName,
220+
DownloadURL: downloadURL,
221+
URLExpired: urlExpired(backup.DownloadURLExpiresAt),
222+
Region: backup.Region,
223+
SameRegion: backup.SameRegion,
170224
})
171225
}
172226
return res, nil
@@ -175,14 +229,12 @@ func backupListBuilder(c *core.Command) *core.Command {
175229
return c
176230
}
177231

178-
func isExported(expirationDate *time.Time) bool {
179-
var exported bool
232+
// urlExpired: indicates if the backup url is still valid after the indicated date.
233+
func urlExpired(expirationDate *time.Time) bool {
180234
if expirationDate == nil {
181-
exported = false
182-
} else {
183-
exported = time.Now().Before(*expirationDate)
235+
return true
184236
}
185-
return exported
237+
return time.Now().After(*expirationDate)
186238
}
187239

188240
func getDefaultFileName(rawURL string) (string, error) {
@@ -200,7 +252,7 @@ type backupDownloadResult struct {
200252
FileName string `json:"file_name"`
201253
}
202254

203-
func backupResultMarshalerFunc(i interface{}, opt *human.MarshalOpt) (string, error) {
255+
func backupResultMarshallerFunc(i interface{}, opt *human.MarshalOpt) (string, error) {
204256
backupResult := i.(backupDownloadResult)
205257
sizeStr, err := human.Marshal(backupResult.Size, nil)
206258
if err != nil {
Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,40 @@
11
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
22
🟩🟩🟩 STDOUT️ 🟩🟩🟩️
3-
ID Name Status Instance ID Exported
4-
da73454a-8232-4d91-b773-8f16ad50a7e1 will_be_exported ready e3678a86-fc68-43ae-90b1-d267b2369576 true
5-
65ce3352-def6-4376-a9d2-cb063a3ce973 will_not_be_exported ready e3678a86-fc68-43ae-90b1-d267b2369576 false
3+
ID Name Database Name Size Status Instance ID URL Expired Download URL Expires At Created At Updated At Region Same Region
4+
da73454a-8232-4d91-b773-8f16ad50a7e1 will_be_exported rdb 2.1 kB ready e3678a86-fc68-43ae-90b1-d267b2369576 false https://s3.nl-ams.scw.cloud/65940610-0e5e-4a98-9306-568aa4eb3673/e3678a86-fc68-43ae-90b1-d267b2369576/da73454a-8232-4d91-b773-8f16ad50a7e1.custom?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=SCWBTK7RYYS1750DS37K%2F20220901%2Fnl-ams%2Fs3%2Faws4_request&X-Amz-Date=20220901T134254Z&X-Amz-Expires=86400&X-Amz-SignedHeaders=host&X-Amz-Signature=4c1622ddf93fa720d38e9a7ba365c16ae07e9d731ba6f6182c95847214d7e21d few seconds ago few seconds ago few seconds ago fr-par false
5+
65ce3352-def6-4376-a9d2-cb063a3ce973 will_not_be_exported rdb 2.1 kB ready e3678a86-fc68-43ae-90b1-d267b2369576 true - few seconds ago few seconds ago few seconds ago fr-par false
66
🟩🟩🟩 JSON STDOUT 🟩🟩🟩
77
[
88
{
99
"ID": "da73454a-8232-4d91-b773-8f16ad50a7e1",
10-
"name": "will_be_exported",
1110
"instance_ID": "e3678a86-fc68-43ae-90b1-d267b2369576",
12-
"exported": true,
13-
"status": "ready"
11+
"database_name": "rdb",
12+
"name": "will_be_exported",
13+
"status": "ready",
14+
"size": 2107,
15+
"expires_at": "2999-01-02T22:04:05Z",
16+
"created_at": "1970-01-01T00:00:00.0Z",
17+
"updated_at": "1970-01-01T00:00:00.0Z",
18+
"instance_name": "cli-test",
19+
"download_url": "https://s3.nl-ams.scw.cloud/65940610-0e5e-4a98-9306-568aa4eb3673/e3678a86-fc68-43ae-90b1-d267b2369576/da73454a-8232-4d91-b773-8f16ad50a7e1.custom?X-Amz-Algorithm=AWS4-HMAC-SHA256\u0026X-Amz-Credential=SCWBTK7RYYS1750DS37K%2F20220901%2Fnl-ams%2Fs3%2Faws4_request\u0026X-Amz-Date=20220901T134254Z\u0026X-Amz-Expires=86400\u0026X-Amz-SignedHeaders=host\u0026X-Amz-Signature=4c1622ddf93fa720d38e9a7ba365c16ae07e9d731ba6f6182c95847214d7e21d",
20+
"url_expired": false,
21+
"region": "fr-par",
22+
"same_region": false
1423
},
1524
{
1625
"ID": "65ce3352-def6-4376-a9d2-cb063a3ce973",
17-
"name": "will_not_be_exported",
1826
"instance_ID": "e3678a86-fc68-43ae-90b1-d267b2369576",
19-
"exported": false,
20-
"status": "ready"
27+
"database_name": "rdb",
28+
"name": "will_not_be_exported",
29+
"status": "ready",
30+
"size": 2107,
31+
"expires_at": "2999-01-02T22:04:05Z",
32+
"created_at": "1970-01-01T00:00:00.0Z",
33+
"updated_at": "1970-01-01T00:00:00.0Z",
34+
"instance_name": "cli-test",
35+
"download_url": "",
36+
"url_expired": true,
37+
"region": "fr-par",
38+
"same_region": false
2139
}
2240
]

0 commit comments

Comments
 (0)