Skip to content

Commit 41d81dd

Browse files
authored
feat(rdb): add --wait prepareInstanceLogs (#3641)
1 parent 5edcd4e commit 41d81dd

File tree

5 files changed

+33
-4
lines changed

5 files changed

+33
-4
lines changed

cmd/scw/testdata/test-all-usage-rdb-log-prepare-usage.golden

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ ARGS:
1313

1414
FLAGS:
1515
-h, --help help for prepare
16+
-w, --wait wait until the log is ready
1617

1718
GLOBAL FLAGS:
1819
-c, --config string The path to the config file

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ require (
2424
github.com/moby/buildkit v0.11.6
2525
github.com/opencontainers/go-digest v1.0.0
2626
github.com/pkg/errors v0.9.1
27-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.22.0.20240129152604-8520ae945b98
27+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.23.0.20240206155451-64fcc5bbab4d
2828
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
2929
github.com/spf13/cobra v1.8.0
3030
github.com/spf13/pflag v1.0.5

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,8 @@ github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDN
392392
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
393393
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 h1:OkMGxebDjyw0ULyrTYWeN0UNCCkmCWfjPnIA2W6oviI=
394394
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06/go.mod h1:+ePHsJ1keEjQtpvf9HHw0f4ZeJ0TLRsxhunSI2hYJSs=
395-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.22.0.20240129152604-8520ae945b98 h1:u9TXjSnvqHXh3qyReJDLdafuQUP/5MQvKMeXohaUmfA=
396-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.22.0.20240129152604-8520ae945b98/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg=
395+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.23.0.20240206155451-64fcc5bbab4d h1:F4MeCGwhzSBwEIdTNh8qtVg5o91qV2N7cFeDv5BBTyQ=
396+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.23.0.20240206155451-64fcc5bbab4d/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg=
397397
github.com/sclevine/spec v1.4.0 h1:z/Q9idDcay5m5irkZ28M7PtQM4aOISzOpj4bUPkDee8=
398398
github.com/secure-systems-lab/go-securesystemslib v0.4.0 h1:b23VGrQhTA8cN2CbBw7/FulN9fTtqYUdS5+Oxzt+DUE=
399399
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=

internal/namespaces/rdb/v1/custom.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func GetCommands() *core.Commands {
4040
cmds.MustFind("rdb", "backup", "create").Override(backupCreateBuilder)
4141
cmds.MustFind("rdb", "backup", "export").Override(backupExportBuilder)
4242
cmds.MustFind("rdb", "backup", "restore").Override(backupRestoreBuilder)
43+
cmds.MustFind("rdb", "backup", "list").Override(backupListBuilder)
4344

4445
cmds.MustFind("rdb", "instance", "create").Override(instanceCreateBuilder)
4546
cmds.MustFind("rdb", "instance", "clone").Override(instanceCloneBuilder)
@@ -54,7 +55,7 @@ func GetCommands() *core.Commands {
5455
cmds.MustFind("rdb", "user", "create").Override(userCreateBuilder)
5556
cmds.MustFind("rdb", "user", "update").Override(userUpdateBuilder)
5657

57-
cmds.MustFind("rdb", "backup", "list").Override(backupListBuilder)
58+
cmds.MustFind("rdb", "log", "prepare").Override(logPrepareBuilder)
5859

5960
return cmds
6061
}

internal/namespaces/rdb/v1/custom_log.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package rdb
22

33
import (
4+
"context"
5+
46
"github.com/fatih/color"
7+
"github.com/scaleway/scaleway-cli/v2/internal/core"
58
"github.com/scaleway/scaleway-cli/v2/internal/human"
69
"github.com/scaleway/scaleway-sdk-go/api/rdb/v1"
10+
"github.com/scaleway/scaleway-sdk-go/scw"
711
)
812

913
var (
@@ -14,3 +18,26 @@ var (
1418
rdb.InstanceLogStatusError: &human.EnumMarshalSpec{Attribute: color.FgRed, Value: "error"},
1519
}
1620
)
21+
22+
func logPrepareBuilder(c *core.Command) *core.Command {
23+
c.WaitFunc = func(ctx context.Context, argsI, respI interface{}) (interface{}, error) {
24+
getResp := respI.(*rdb.PrepareInstanceLogsResponse)
25+
api := rdb.NewAPI(core.ExtractClient(ctx))
26+
readyLogs := make([]*rdb.InstanceLog, len(getResp.InstanceLogs))
27+
for i := range getResp.InstanceLogs {
28+
logs, err := api.WaitForInstanceLog(&rdb.WaitForInstanceLogRequest{
29+
InstanceLogID: getResp.InstanceLogs[i].ID,
30+
Region: getResp.InstanceLogs[i].Region,
31+
Timeout: scw.TimeDurationPtr(instanceActionTimeout),
32+
RetryInterval: core.DefaultRetryInterval,
33+
})
34+
if err != nil {
35+
return nil, err
36+
}
37+
readyLogs[i] = logs
38+
}
39+
respI.(*rdb.PrepareInstanceLogsResponse).InstanceLogs = readyLogs
40+
return respI.(*rdb.PrepareInstanceLogsResponse), nil
41+
}
42+
return c
43+
}

0 commit comments

Comments
 (0)