-
Notifications
You must be signed in to change notification settings - Fork 151
/
custom_logout.go
58 lines (49 loc) · 1.47 KB
/
custom_logout.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
package registry
import (
"context"
"os/exec"
"reflect"
"github.com/scaleway/scaleway-cli/v2/internal/core"
"github.com/scaleway/scaleway-sdk-go/scw"
)
type registryLogoutArgs struct {
Region scw.Region
Program string
}
func registryLogoutCommand() *core.Command {
return &core.Command{
Short: `Logout of a registry`,
Long: `This command will run the correct command in order to log you out of the registry with the chosen program.
You will need to have the chosen binary installed on your system and in your PATH.`,
Namespace: "registry",
Resource: "logout",
ArgsType: reflect.TypeOf(registryLogoutArgs{}),
ArgSpecs: []*core.ArgSpec{
{
Name: "program",
Short: "Program used to log in to the namespace",
Default: core.DefaultValueSetter(string(docker)),
EnumValues: availablePrograms.StringArray(),
},
core.RegionArgSpec(),
},
Run: registryLogoutRun,
}
}
func registryLogoutRun(ctx context.Context, argsI interface{}) (i interface{}, e error) {
args := argsI.(*registryLogoutArgs)
region := args.Region.String()
endpoint := endpointPrefix + region + endpointSuffix
cmdArgs := []string{"logout", endpoint}
cmd := exec.Command(args.Program, cmdArgs...) //nolint:gosec
exitCode, err := core.ExecCmd(ctx, cmd)
if err != nil {
return nil, err
}
if exitCode != 0 {
return nil, &core.CliError{Empty: true, Code: exitCode}
}
return &core.SuccessResult{
Empty: true, // the program will output the success message
}, nil
}