-
Notifications
You must be signed in to change notification settings - Fork 151
/
custom_acl.go
46 lines (39 loc) · 1.3 KB
/
custom_acl.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
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"
)
var (
aclRuleActionMarshalSpecs = human.EnumMarshalSpecs{
rdb.ACLRuleActionAllow: &human.EnumMarshalSpec{Attribute: color.FgGreen, Value: "allow"},
rdb.ACLRuleActionDeny: &human.EnumMarshalSpec{Attribute: color.FgRed, Value: "deny"},
}
)
func aclAddBuilder(c *core.Command) *core.Command {
c.Interceptor = func(ctx context.Context, argsI interface{}, runner core.CommandRunner) (interface{}, error) {
aclAddResponseI, err := runner(ctx, argsI)
if err != nil {
return nil, err
}
aclAddResponse := aclAddResponseI.(*rdb.AddInstanceACLRulesResponse)
return aclAddResponse.Rules, nil
}
return c
}
func aclDeleteBuilder(c *core.Command) *core.Command {
c.Interceptor = func(ctx context.Context, argsI interface{}, runner core.CommandRunner) (interface{}, error) {
aclDeleteResponseI, err := runner(ctx, argsI)
if err != nil {
return nil, err
}
aclDeleteResponse := aclDeleteResponseI.(*rdb.DeleteInstanceACLRulesResponse)
return rdb.ListInstanceACLRulesResponse{
Rules: aclDeleteResponse.Rules,
TotalCount: uint32(len(aclDeleteResponse.Rules)),
}, nil
}
return c
}