Skip to content

Commit

Permalink
Samples and completion
Browse files Browse the repository at this point in the history
  • Loading branch information
majst01 committed Feb 9, 2024
1 parent f957e4f commit c68bacf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
16 changes: 16 additions & 0 deletions cmd/completion/firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,19 @@ 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
}
10 changes: 6 additions & 4 deletions cmd/firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ func newFirewallCmd(c *config) *cobra.Command {
CreateCmdMutateFn: func(cmd *cobra.Command) {
c.addMachineCreateFlags(cmd, "firewall")
cmd.Aliases = []string{"allocate"}
cmd.Flags().StringSlice("egress", nil, "egress firewall rule to deploy on creation")
cmd.Flags().StringSlice("ingress", nil, "ingress firewall rule to deploy on creation")
cmd.Flags().StringSlice("egress", nil, "egress firewall rule to deploy on creation format: tcp|udp@cidr#cidr@port#port@comment")
cmd.Flags().StringSlice("ingress", nil, "ingress firewall rule to deploy on creation format: tcp|udp@cidr#cidr@port#port@comment")
must(cmd.RegisterFlagCompletionFunc("egress", c.comp.FirewallEgressCompletion))
must(cmd.RegisterFlagCompletionFunc("ingress", c.comp.FirewallIngressCompletion))
},
ListCmdMutateFn: func(cmd *cobra.Command) {
cmd.Flags().String("id", "", "ID to filter [optional]")
Expand Down Expand Up @@ -213,8 +215,8 @@ func (c *firewallCmd) createRequestFromCLI() (*models.V1FirewallCreateRequest, e
}

// parseEgressFlags input must be in the form of
// proto@cidr;cidr@port;port;port@comment
// [email protected]/24;2.3.4.1/32@80#443#8080#8443@"Allow apt update"
// proto@cidr#cidr@port#port#port@comment
// [email protected]/24#2.3.4.1/32@80#443#8080#8443@"Allow apt update"
func parseEgressFlags(inputs []string) ([]*models.V1FirewallEgressRule, error) {
var rules []*models.V1FirewallEgressRule

Expand Down

0 comments on commit c68bacf

Please sign in to comment.