Skip to content

Commit

Permalink
Revert completion changes
Browse files Browse the repository at this point in the history
  • Loading branch information
majst01 committed Feb 16, 2024
1 parent b13c9a8 commit 5968451
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 39 deletions.
16 changes: 0 additions & 16 deletions cmd/completion/firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,3 @@ func (c *Completion) FirewallListCompletion(cmd *cobra.Command, args []string, t
}
return names, cobra.ShellCompDirectiveNoFileComp
}

func (c *Completion) FirewallEgressCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
egressrules := []string{
"[email protected]/0@443@\"allow outgoing https\"\tdefault outgoing https",
"[email protected]/0@53@\"allow outgoing dns via tcp\"\tdefault outgoing dns via tcp",
"[email protected]/0@53#123@\"allow outgoing dns and ntp via udp\"\tdefault outgoing dns and ntp via udp",
}
return egressrules, cobra.ShellCompDirectiveNoFileComp
}

func (c *Completion) FirewallIngressCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
ingressrules := []string{
"[email protected]/0@22@\"allow incoming ssh\"\tallow incoming ssh",
}
return ingressrules, cobra.ShellCompDirectiveNoFileComp
}
20 changes: 2 additions & 18 deletions cmd/completion/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@ package completion

import (
"errors"
"slices"
"strings"
"time"

"github.com/metal-stack/metal-go/api/client/image"
"github.com/metal-stack/metal-go/api/models"
"github.com/metal-stack/metal-lib/pkg/pointer"
"github.com/spf13/cobra"
)

Expand All @@ -23,19 +20,12 @@ func (c *Completion) ImageClassificationCompletion(cmd *cobra.Command, args []st
func (c *Completion) ImageFeatureCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return []string{"machine", "firewall"}, cobra.ShellCompDirectiveNoFileComp
}
func (c *Completion) FirewallImageListCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return c.listValidImages(pointer.Pointer(models.V1MachineAllocationRoleFirewall))
}

func (c *Completion) MachineImageListCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return c.listValidImages(pointer.Pointer(models.V1MachineAllocationRoleMachine))
}

func (c *Completion) ImageListCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return c.listValidImages(nil)
return c.listValidImages()
}

func (c *Completion) listValidImages(role *string) ([]string, cobra.ShellCompDirective) {
func (c *Completion) listValidImages() ([]string, cobra.ShellCompDirective) {
resp, err := c.client.Image().ListImages(image.NewListImagesParams(), nil)
if err != nil {
return nil, cobra.ShellCompDirectiveError
Expand All @@ -45,12 +35,6 @@ func (c *Completion) listValidImages(role *string) ([]string, cobra.ShellCompDir
if i.ID == nil {
continue
}
if role != nil && !slices.Contains(i.Features, *role) {
continue
}
if i.ExpirationDate != nil && time.Now().After(time.Time(*i.ExpirationDate)) {
continue
}
names = append(names, *i.ID)
}
return names, cobra.ShellCompDirectiveNoFileComp
Expand Down
2 changes: 1 addition & 1 deletion cmd/firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ ingress:
must(cmd.RegisterFlagCompletionFunc("size", c.comp.SizeListCompletion))
must(cmd.RegisterFlagCompletionFunc("project", c.comp.ProjectListCompletion))
must(cmd.RegisterFlagCompletionFunc("id", c.comp.FirewallListCompletion))
must(cmd.RegisterFlagCompletionFunc("image", c.comp.FirewallImageListCompletion))
must(cmd.RegisterFlagCompletionFunc("image", c.comp.ImageListCompletion))
},
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (c *machineCmd) listCmdFlags(cmd *cobra.Command, lastEventErrorThresholdDef
{flagName: "size", f: c.comp.SizeListCompletion},
{flagName: "project", f: c.comp.ProjectListCompletion},
{flagName: "id", f: c.comp.MachineListCompletion},
{flagName: "image", f: c.comp.MachineImageListCompletion},
{flagName: "image", f: c.comp.ImageListCompletion},
{flagName: "state", f: cobra.FixedCompletions([]string{
// empty does not work:
// models.V1FirewallFindRequestStateValueEmpty,
Expand Down Expand Up @@ -530,7 +530,7 @@ MODE can be omitted or one of:
must(cmd.RegisterFlagCompletionFunc("size", c.comp.SizeListCompletion))
must(cmd.RegisterFlagCompletionFunc("project", c.comp.ProjectListCompletion))
must(cmd.RegisterFlagCompletionFunc("id", c.comp.MachineListCompletion))
must(cmd.RegisterFlagCompletionFunc("image", c.comp.MachineImageListCompletion))
must(cmd.RegisterFlagCompletionFunc("image", c.comp.ImageListCompletion))
must(cmd.RegisterFlagCompletionFunc("filesystemlayout", c.comp.FilesystemLayoutListCompletion))
}

Expand Down
4 changes: 2 additions & 2 deletions docs/metalctl_firewall_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ metalctl firewall create [flags]
to:
- 0.0.0.0/0
ingress:
- comment: allow incoming ssh
- comment: allow incoming ssh only to one ip
ports:
- 22
protocol: TCP
Expand All @@ -62,7 +62,7 @@ metalctl firewall create [flags]
- 1.2.3.4/32
to:
- 212.34.83.19/32
- comment: allow incoming https
- comment: allow incoming https to all targets
ports:
- 80
- 433
Expand Down

0 comments on commit 5968451

Please sign in to comment.