-
Notifications
You must be signed in to change notification settings - Fork 151
/
custom_gateway.go
64 lines (58 loc) · 1.97 KB
/
custom_gateway.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
package vpcgw
import (
"context"
"time"
"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/vpcgw/v1"
"github.com/scaleway/scaleway-sdk-go/scw"
)
const (
gatewayActionTimeout = 60 * time.Minute
)
var (
gatewayStatusMarshalSpecs = human.EnumMarshalSpecs{
vpcgw.GatewayStatusAllocating: &human.EnumMarshalSpec{Attribute: color.FgBlue},
vpcgw.GatewayStatusConfiguring: &human.EnumMarshalSpec{Attribute: color.FgBlue},
vpcgw.GatewayStatusDeleted: &human.EnumMarshalSpec{Attribute: color.FgRed},
vpcgw.GatewayStatusDeleting: &human.EnumMarshalSpec{Attribute: color.FgBlue},
vpcgw.GatewayStatusFailed: &human.EnumMarshalSpec{Attribute: color.FgRed},
vpcgw.GatewayStatusRunning: &human.EnumMarshalSpec{Attribute: color.FgGreen},
vpcgw.GatewayStatusStopped: &human.EnumMarshalSpec{Attribute: color.FgRed},
vpcgw.GatewayStatusStopping: &human.EnumMarshalSpec{Attribute: color.FgBlue},
vpcgw.GatewayStatusUnknown: &human.EnumMarshalSpec{Attribute: color.Faint},
}
)
func gatewayCreateBuilder(c *core.Command) *core.Command {
c.WaitFunc = func(ctx context.Context, _, respI interface{}) (interface{}, error) {
getResp := respI.(*vpcgw.Gateway)
api := vpcgw.NewAPI(core.ExtractClient(ctx))
return api.WaitForGateway(&vpcgw.WaitForGatewayRequest{
GatewayID: getResp.ID,
Zone: getResp.Zone,
Timeout: scw.TimeDurationPtr(gatewayActionTimeout),
RetryInterval: core.DefaultRetryInterval,
})
}
return c
}
func gatewayMarshalerFunc(i interface{}, opt *human.MarshalOpt) (string, error) {
type tmp vpcgw.Gateway
vpcgtw := tmp(i.(vpcgw.Gateway))
opt.Sections = []*human.MarshalSection{
{
FieldName: "IP",
Title: "IP",
},
{
FieldName: "GatewayNetworks",
Title: "GatewayNetworks",
},
}
str, err := human.Marshal(vpcgtw, opt)
if err != nil {
return "", err
}
return str, nil
}