Skip to content

Commit

Permalink
feat(rdb): add --wait prepareInstanceLogs (#3641)
Browse files Browse the repository at this point in the history
  • Loading branch information
Laure-di authored Feb 8, 2024
1 parent 5edcd4e commit 41d81dd
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ ARGS:

FLAGS:
-h, --help help for prepare
-w, --wait wait until the log is ready

GLOBAL FLAGS:
-c, --config string The path to the config file
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ require (
github.com/moby/buildkit v0.11.6
github.com/opencontainers/go-digest v1.0.0
github.com/pkg/errors v0.9.1
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.22.0.20240129152604-8520ae945b98
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.23.0.20240206155451-64fcc5bbab4d
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,8 @@ github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDN
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 h1:OkMGxebDjyw0ULyrTYWeN0UNCCkmCWfjPnIA2W6oviI=
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06/go.mod h1:+ePHsJ1keEjQtpvf9HHw0f4ZeJ0TLRsxhunSI2hYJSs=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.22.0.20240129152604-8520ae945b98 h1:u9TXjSnvqHXh3qyReJDLdafuQUP/5MQvKMeXohaUmfA=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.22.0.20240129152604-8520ae945b98/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.23.0.20240206155451-64fcc5bbab4d h1:F4MeCGwhzSBwEIdTNh8qtVg5o91qV2N7cFeDv5BBTyQ=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.23.0.20240206155451-64fcc5bbab4d/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg=
github.com/sclevine/spec v1.4.0 h1:z/Q9idDcay5m5irkZ28M7PtQM4aOISzOpj4bUPkDee8=
github.com/secure-systems-lab/go-securesystemslib v0.4.0 h1:b23VGrQhTA8cN2CbBw7/FulN9fTtqYUdS5+Oxzt+DUE=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
Expand Down
3 changes: 2 additions & 1 deletion internal/namespaces/rdb/v1/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func GetCommands() *core.Commands {
cmds.MustFind("rdb", "backup", "create").Override(backupCreateBuilder)
cmds.MustFind("rdb", "backup", "export").Override(backupExportBuilder)
cmds.MustFind("rdb", "backup", "restore").Override(backupRestoreBuilder)
cmds.MustFind("rdb", "backup", "list").Override(backupListBuilder)

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

cmds.MustFind("rdb", "backup", "list").Override(backupListBuilder)
cmds.MustFind("rdb", "log", "prepare").Override(logPrepareBuilder)

return cmds
}
27 changes: 27 additions & 0 deletions internal/namespaces/rdb/v1/custom_log.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package rdb

import (
"context"

"github.com/fatih/color"
"github.com/scaleway/scaleway-cli/v2/internal/core"
"github.com/scaleway/scaleway-cli/v2/internal/human"
"github.com/scaleway/scaleway-sdk-go/api/rdb/v1"
"github.com/scaleway/scaleway-sdk-go/scw"
)

var (
Expand All @@ -14,3 +18,26 @@ var (
rdb.InstanceLogStatusError: &human.EnumMarshalSpec{Attribute: color.FgRed, Value: "error"},
}
)

func logPrepareBuilder(c *core.Command) *core.Command {
c.WaitFunc = func(ctx context.Context, argsI, respI interface{}) (interface{}, error) {
getResp := respI.(*rdb.PrepareInstanceLogsResponse)
api := rdb.NewAPI(core.ExtractClient(ctx))
readyLogs := make([]*rdb.InstanceLog, len(getResp.InstanceLogs))
for i := range getResp.InstanceLogs {
logs, err := api.WaitForInstanceLog(&rdb.WaitForInstanceLogRequest{
InstanceLogID: getResp.InstanceLogs[i].ID,
Region: getResp.InstanceLogs[i].Region,
Timeout: scw.TimeDurationPtr(instanceActionTimeout),
RetryInterval: core.DefaultRetryInterval,
})
if err != nil {
return nil, err
}
readyLogs[i] = logs
}
respI.(*rdb.PrepareInstanceLogsResponse).InstanceLogs = readyLogs
return respI.(*rdb.PrepareInstanceLogsResponse), nil
}
return c
}

0 comments on commit 41d81dd

Please sign in to comment.