-
Notifications
You must be signed in to change notification settings - Fork 20
/
security_group_source_remove.go
67 lines (51 loc) · 1.96 KB
/
security_group_source_remove.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
65
66
67
package cmd
import (
"fmt"
"strings"
"github.com/exoscale/cli/pkg/account"
"github.com/exoscale/cli/pkg/globalstate"
"github.com/exoscale/cli/pkg/output"
exoapi "github.com/exoscale/egoscale/v2/api"
"github.com/spf13/cobra"
)
type securityGroupRemoveSourceCmd struct {
cliCommandSettings `cli-cmd:"-"`
_ bool `cli-cmd:"remove"`
SecurityGroup string `cli-arg:"#" cli-usage:"SECURITY-GROUP-ID|NAME"`
Cidr string `cli-arg:"#" cli-usage:"CIDR"`
}
func (c *securityGroupRemoveSourceCmd) cmdAliases() []string { return gRemoveAlias }
func (c *securityGroupRemoveSourceCmd) cmdShort() string {
return "Remove an external source from a Security Group"
}
func (c *securityGroupRemoveSourceCmd) cmdLong() string {
return fmt.Sprintf(`This command removes an external source from a Compute instance Security Group.
Supported output template annotations: %s`,
strings.Join(output.TemplateAnnotations(&securityGroupShowOutput{}), ", "))
}
func (c *securityGroupRemoveSourceCmd) cmdPreRun(cmd *cobra.Command, args []string) error {
return cliCommandDefaultPreRun(c, cmd, args)
}
func (c *securityGroupRemoveSourceCmd) cmdRun(_ *cobra.Command, _ []string) error {
zone := account.CurrentAccount.DefaultZone
ctx := exoapi.WithEndpoint(gContext, exoapi.NewReqEndpoint(account.CurrentAccount.Environment, zone))
securityGroup, err := globalstate.EgoscaleClient.FindSecurityGroup(ctx, zone, c.SecurityGroup)
if err != nil {
return err
}
decorateAsyncOperation(fmt.Sprintf("Removing Security Group source %s...", c.Cidr), func() {
err = globalstate.EgoscaleClient.RemoveExternalSourceFromSecurityGroup(ctx, zone, securityGroup, c.Cidr)
})
if err != nil {
return err
}
return (&securityGroupShowCmd{
cliCommandSettings: c.cliCommandSettings,
SecurityGroup: *securityGroup.ID,
}).cmdRun(nil, nil)
}
func init() {
cobra.CheckErr(registerCLICommand(securityGroupSourceCmd, &securityGroupRemoveSourceCmd{
cliCommandSettings: defaultCLICmdSettings(),
}))
}