Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:

go-build:
uses: metal-stack/actions-common/.github/workflows/go-build.yaml@v1
secrets: inherit
with:
build: false

Expand Down
17 changes: 3 additions & 14 deletions cmd/api/v2/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ func newIPCmd(c *config.Config) *cobra.Command {
cmd.Flags().StringP("addressfamily", "", "", "addressfamily, can be either IPv4|IPv6, defaults to IPv4 (optional)")

genericcli.Must(cmd.RegisterFlagCompletionFunc("project", c.Completion.Project))
genericcli.Must(cmd.RegisterFlagCompletionFunc("network", c.Completion.Network))
genericcli.Must(cmd.RegisterFlagCompletionFunc("addressfamily", c.Completion.AddressFamily))
},
UpdateCmdMutateFn: func(cmd *cobra.Command) {
cmd.Flags().StringP("project", "p", "", "project of the ip")
Expand Down Expand Up @@ -88,7 +90,7 @@ func (c *ip) createFromCLI() (*apiv2.IPServiceCreateRequest, error) {
Description: pointer.PointerOrNil(viper.GetString("description")),
Labels: labels,
Type: new(ipStaticToType(viper.GetBool("static"))),
AddressFamily: addressFamilyToType(viper.GetString("addressfamily")),
AddressFamily: helpers.IPAddressFamilyToType(viper.GetString("addressfamily")),
}, nil
}

Expand Down Expand Up @@ -257,16 +259,3 @@ func ipStaticToType(b bool) apiv2.IPType {
}
return apiv2.IPType_IP_TYPE_EPHEMERAL
}

func addressFamilyToType(af string) *apiv2.IPAddressFamily {
switch af {
case "":
return nil
case "ipv4", "IPv4":
return apiv2.IPAddressFamily_IP_ADDRESS_FAMILY_V4.Enum()
case "ipv6", "IPv6":
return apiv2.IPAddressFamily_IP_ADDRESS_FAMILY_V6.Enum()
default:
return apiv2.IPAddressFamily_IP_ADDRESS_FAMILY_UNSPECIFIED.Enum()
}
}
11 changes: 2 additions & 9 deletions cmd/completion/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,8 @@ import (
)

type Completion struct {
client client.Client
project string
}

func New(c client.Client, project string) *Completion {
return &Completion{
client: c,
project: project,
}
Client client.Client
Proj string
}

func OutputFormat(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
Expand Down
19 changes: 17 additions & 2 deletions cmd/completion/ip.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package completion

import (
"github.com/metal-stack/api/go/enum"
apiv2 "github.com/metal-stack/api/go/metalstack/api/v2"
"github.com/spf13/cobra"
)

func (c *Completion) Ip(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
req := &apiv2.IPServiceListRequest{
Project: c.project,
Project: c.Proj,
}
resp, err := c.client.Apiv2().IP().List(cmd.Context(), req)
resp, err := c.Client.Apiv2().IP().List(cmd.Context(), req)
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
Expand All @@ -19,3 +20,17 @@ func (c *Completion) Ip(cmd *cobra.Command, args []string, toComplete string) ([
}
return names, cobra.ShellCompDirectiveNoFileComp
}
func (c *Completion) AddressFamily(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
var afs []string
for _, af := range []apiv2.IPAddressFamily{
apiv2.IPAddressFamily_IP_ADDRESS_FAMILY_V4,
apiv2.IPAddressFamily_IP_ADDRESS_FAMILY_V6} {
stringValue, err := enum.GetStringValue(af)
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
afs = append(afs, *stringValue)
}

return afs, cobra.ShellCompDirectiveNoFileComp
}
10 changes: 5 additions & 5 deletions cmd/completion/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import (
)

func (c *Completion) Network(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
ownNetworks, err := c.client.Apiv2().Network().List(cmd.Context(), &apiv2.NetworkServiceListRequest{
Project: c.project,
ownNetworks, err := c.Client.Apiv2().Network().List(cmd.Context(), &apiv2.NetworkServiceListRequest{
Project: c.Proj,
})
if err != nil {
return nil, cobra.ShellCompDirectiveError
}

baseNetworks, err := c.client.Apiv2().Network().ListBaseNetworks(cmd.Context(), &apiv2.NetworkServiceListBaseNetworksRequest{
Project: c.project,
baseNetworks, err := c.Client.Apiv2().Network().ListBaseNetworks(cmd.Context(), &apiv2.NetworkServiceListBaseNetworksRequest{
Project: c.Proj,
})
if err != nil {
return nil, cobra.ShellCompDirectiveError
Expand Down Expand Up @@ -71,7 +71,7 @@ func (c *Completion) NetworkAddressFamily(cmd *cobra.Command, args []string, toC
}

func (c *Completion) NetworkAdmin(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
networks, err := c.client.Adminv2().Network().List(cmd.Context(), &adminv2.NetworkServiceListRequest{})
networks, err := c.Client.Adminv2().Network().List(cmd.Context(), &adminv2.NetworkServiceListRequest{})
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/completion/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

func (c *Completion) Partition(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
req := &apiv2.PartitionServiceListRequest{}
resp, err := c.client.Apiv2().Partition().List(cmd.Context(), req)
resp, err := c.Client.Apiv2().Partition().List(cmd.Context(), req)
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
Expand Down
10 changes: 5 additions & 5 deletions cmd/completion/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

func (c *Completion) Project(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
req := &apiv2.ProjectServiceListRequest{}
resp, err := c.client.Apiv2().Project().List(cmd.Context(), req)
resp, err := c.Client.Apiv2().Project().List(cmd.Context(), req)
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
Expand Down Expand Up @@ -36,8 +36,8 @@ func (c *Completion) ProjectRole(cmd *cobra.Command, args []string, toComplete s
}

func (c *Completion) ProjectInvite(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
resp, err := c.client.Apiv2().Project().InvitesList(cmd.Context(), &apiv2.ProjectServiceInvitesListRequest{
Project: c.project,
resp, err := c.Client.Apiv2().Project().InvitesList(cmd.Context(), &apiv2.ProjectServiceInvitesListRequest{
Project: c.Proj,
})
if err != nil {
return nil, cobra.ShellCompDirectiveError
Expand All @@ -53,8 +53,8 @@ func (c *Completion) ProjectInvite(cmd *cobra.Command, args []string, toComplete
}

func (c *Completion) ProjectMember(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
resp, err := c.client.Apiv2().Project().Get(cmd.Context(), &apiv2.ProjectServiceGetRequest{
Project: c.project,
resp, err := c.Client.Apiv2().Project().Get(cmd.Context(), &apiv2.ProjectServiceGetRequest{
Project: c.Proj,
})
if err != nil {
return nil, cobra.ShellCompDirectiveError
Expand Down
2 changes: 1 addition & 1 deletion cmd/completion/size.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

func (c *Completion) Size(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
req := &apiv2.SizeServiceListRequest{}
resp, err := c.client.Apiv2().Size().List(cmd.Context(), req)
resp, err := c.Client.Apiv2().Size().List(cmd.Context(), req)
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
Expand Down
12 changes: 6 additions & 6 deletions cmd/completion/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func (c *Completion) Switch(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
resp, err := c.client.Adminv2().Switch().List(cmd.Context(), &adminv2.SwitchServiceListRequest{})
resp, err := c.Client.Adminv2().Switch().List(cmd.Context(), &adminv2.SwitchServiceListRequest{})
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
Expand All @@ -21,7 +21,7 @@ func (c *Completion) Switch(cmd *cobra.Command, args []string, toComplete string
}

func (c *Completion) SwitchPartition(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
resp, err := c.client.Adminv2().Switch().List(cmd.Context(), &adminv2.SwitchServiceListRequest{})
resp, err := c.Client.Adminv2().Switch().List(cmd.Context(), &adminv2.SwitchServiceListRequest{})
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
Expand All @@ -35,7 +35,7 @@ func (c *Completion) SwitchPartition(cmd *cobra.Command, args []string, toComple
}

func (c *Completion) SwitchRack(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
resp, err := c.client.Adminv2().Switch().List(cmd.Context(), &adminv2.SwitchServiceListRequest{})
resp, err := c.Client.Adminv2().Switch().List(cmd.Context(), &adminv2.SwitchServiceListRequest{})
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
Expand All @@ -49,7 +49,7 @@ func (c *Completion) SwitchRack(cmd *cobra.Command, args []string, toComplete st
}

func (c *Completion) SwitchOSVendor(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
resp, err := c.client.Adminv2().Switch().List(cmd.Context(), &adminv2.SwitchServiceListRequest{})
resp, err := c.Client.Adminv2().Switch().List(cmd.Context(), &adminv2.SwitchServiceListRequest{})
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
Expand All @@ -63,7 +63,7 @@ func (c *Completion) SwitchOSVendor(cmd *cobra.Command, args []string, toComplet
}

func (c *Completion) SwitchOSVersion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
resp, err := c.client.Adminv2().Switch().List(cmd.Context(), &adminv2.SwitchServiceListRequest{})
resp, err := c.Client.Adminv2().Switch().List(cmd.Context(), &adminv2.SwitchServiceListRequest{})
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
Expand All @@ -82,7 +82,7 @@ func (c *Completion) SwitchPorts(cmd *cobra.Command, args []string, toComplete s
return nil, cobra.ShellCompDirectiveNoFileComp
}

resp, err := c.client.Adminv2().Switch().Get(cmd.Context(), &adminv2.SwitchServiceGetRequest{
resp, err := c.Client.Adminv2().Switch().Get(cmd.Context(), &adminv2.SwitchServiceGetRequest{
Id: args[0],
})
if err != nil {
Expand Down
16 changes: 8 additions & 8 deletions cmd/completion/tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

func (c *Completion) Tenant(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
req := &apiv2.TenantServiceListRequest{}
resp, err := c.client.Apiv2().Tenant().List(cmd.Context(), req)
resp, err := c.Client.Apiv2().Tenant().List(cmd.Context(), req)
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
Expand All @@ -35,14 +35,14 @@ func (c *Completion) TenantRole(cmd *cobra.Command, args []string, toComplete st
}

func (c *Completion) TenantInvite(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
projectResp, err := c.client.Apiv2().Project().Get(cmd.Context(), &apiv2.ProjectServiceGetRequest{
Project: c.project,
projectResp, err := c.Client.Apiv2().Project().Get(cmd.Context(), &apiv2.ProjectServiceGetRequest{
Project: c.Proj,
})
if err != nil {
return nil, cobra.ShellCompDirectiveError
}

resp, err := c.client.Apiv2().Tenant().InvitesList(cmd.Context(), &apiv2.TenantServiceInvitesListRequest{
resp, err := c.Client.Apiv2().Tenant().InvitesList(cmd.Context(), &apiv2.TenantServiceInvitesListRequest{
Login: projectResp.Project.Tenant,
})
if err != nil {
Expand All @@ -59,14 +59,14 @@ func (c *Completion) TenantInvite(cmd *cobra.Command, args []string, toComplete
}

func (c *Completion) TenantMember(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
projectResp, err := c.client.Apiv2().Project().Get(cmd.Context(), &apiv2.ProjectServiceGetRequest{
Project: c.project,
projectResp, err := c.Client.Apiv2().Project().Get(cmd.Context(), &apiv2.ProjectServiceGetRequest{
Project: c.Proj,
})
if err != nil {
return nil, cobra.ShellCompDirectiveError
}

resp, err := c.client.Apiv2().Tenant().Get(cmd.Context(), &apiv2.TenantServiceGetRequest{
resp, err := c.Client.Apiv2().Tenant().Get(cmd.Context(), &apiv2.TenantServiceGetRequest{
Login: projectResp.Project.Tenant,
})
if err != nil {
Expand All @@ -84,7 +84,7 @@ func (c *Completion) TenantMember(cmd *cobra.Command, args []string, toComplete

func (c *Completion) AdminTenant(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
req := &adminv2.TenantServiceListRequest{}
resp, err := c.client.Adminv2().Tenant().List(cmd.Context(), req)
resp, err := c.Client.Adminv2().Tenant().List(cmd.Context(), req)
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
Expand Down
10 changes: 5 additions & 5 deletions cmd/completion/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func (c *Completion) Token(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
req := &apiv2.TokenServiceListRequest{}
resp, err := c.client.Apiv2().Token().List(cmd.Context(), req)
resp, err := c.Client.Apiv2().Token().List(cmd.Context(), req)
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
Expand All @@ -24,7 +24,7 @@ func (c *Completion) Token(cmd *cobra.Command, args []string, toComplete string)
}

func (c *Completion) TokenProjectRoles(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
methods, err := c.client.Apiv2().Method().TokenScopedList(cmd.Context(), &apiv2.MethodServiceTokenScopedListRequest{})
methods, err := c.Client.Apiv2().Method().TokenScopedList(cmd.Context(), &apiv2.MethodServiceTokenScopedListRequest{})
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
Expand All @@ -42,7 +42,7 @@ func (c *Completion) TokenProjectRoles(cmd *cobra.Command, args []string, toComp
}

func (c *Completion) TokenTenantRoles(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
methods, err := c.client.Apiv2().Method().TokenScopedList(cmd.Context(), &apiv2.MethodServiceTokenScopedListRequest{})
methods, err := c.Client.Apiv2().Method().TokenScopedList(cmd.Context(), &apiv2.MethodServiceTokenScopedListRequest{})
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
Expand All @@ -60,7 +60,7 @@ func (c *Completion) TokenTenantRoles(cmd *cobra.Command, args []string, toCompl
}

func (c *Completion) TokenMachineRoles(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
methods, err := c.client.Apiv2().Method().TokenScopedList(cmd.Context(), &apiv2.MethodServiceTokenScopedListRequest{})
methods, err := c.Client.Apiv2().Method().TokenScopedList(cmd.Context(), &apiv2.MethodServiceTokenScopedListRequest{})
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
Expand Down Expand Up @@ -104,7 +104,7 @@ func (c *Completion) TokenInfraRole(cmd *cobra.Command, args []string, toComplet
}

func (c *Completion) TokenPermissions(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
methods, err := c.client.Apiv2().Method().List(cmd.Context(), &apiv2.MethodServiceListRequest{})
methods, err := c.Client.Apiv2().Method().List(cmd.Context(), &apiv2.MethodServiceListRequest{})
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
Expand Down
12 changes: 7 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ import (

func Execute() {
cfg := &config.Config{
Fs: afero.NewOsFs(),
Out: os.Stdout,
PromptOut: os.Stdout,
In: os.Stdin,
Fs: afero.NewOsFs(),
Out: os.Stdout,
PromptOut: os.Stdout,
In: os.Stdin,
Completion: &completion.Completion{},
}

cmd := NewRootCmd(cfg)
Expand Down Expand Up @@ -127,7 +128,8 @@ func initConfigWithViperCtx(c *config.Config) error {
}

c.Client = mc
c.Completion = completion.New(mc, c.GetProject())
c.Completion.Client = mc
c.Completion.Proj = c.GetProject()
return nil
}

Expand Down
14 changes: 8 additions & 6 deletions testing/e2e/test_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@ func NewRootCmd(t *testing.T, c *TestConfig) e2e_test.NewRootCmdFunc {
viper.Reset()

return cmd.NewRootCmd(&config.Config{
Fs: fs,
Out: &out,
In: in,
PromptOut: io.Discard,
Completion: completion.New(cl, ""),
Client: cl,
Fs: fs,
Out: &out,
In: in,
PromptOut: io.Discard,
Completion: &completion.Completion{
Client: cl,
},
Client: cl,
}), &out
}
}
Loading