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
3 changes: 2 additions & 1 deletion cmd/admin/v1/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ func AddCmds(cmd *cobra.Command, c *config.Config) {
Hidden: true,
}

adminCmd.AddCommand(newTokenCmd(c))
adminCmd.AddCommand(newImageCmd(c))
adminCmd.AddCommand(newTenantCmd(c))
adminCmd.AddCommand(newTokenCmd(c))

cmd.AddCommand(adminCmd)
}
105 changes: 105 additions & 0 deletions cmd/admin/v1/tenant.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package v1

import (
"fmt"

adminv2 "github.com/metal-stack/api/go/metalstack/admin/v2"
apiv2 "github.com/metal-stack/api/go/metalstack/api/v2"
"github.com/metal-stack/cli/cmd/config"
"github.com/metal-stack/cli/cmd/sorters"
"github.com/metal-stack/metal-lib/pkg/genericcli"
"github.com/metal-stack/metal-lib/pkg/genericcli/printers"
"github.com/metal-stack/metal-lib/pkg/pointer"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

type tenant struct {
c *config.Config
}

func newTenantCmd(c *config.Config) *cobra.Command {
w := &tenant{
c: c,
}

cmdsConfig := &genericcli.CmdsConfig[*adminv2.TenantServiceCreateRequest, any, *apiv2.Tenant]{
BinaryName: config.BinaryName,
GenericCLI: genericcli.NewGenericCLI(w).WithFS(c.Fs),
Singular: "tenant",
Plural: "tenants",
Description: "manage api tenants",
Sorter: sorters.TenantSorter(),
DescribePrinter: func() printers.Printer { return c.DescribePrinter },
ListPrinter: func() printers.Printer { return c.ListPrinter },
ListCmdMutateFn: func(cmd *cobra.Command) {
cmd.Flags().String("name", "", "lists only tenants with the given name")
cmd.Flags().String("id", "", "lists only tenant with the given tenant id")
cmd.Flags().String("email", "", "lists only tenant with the given email address")
},
CreateCmdMutateFn: func(cmd *cobra.Command) {
cmd.Flags().String("name", "", "the name of the tenant to create")
cmd.Flags().String("description", "", "the description of the tenant to create")
cmd.Flags().String("email", "", "the email of the tenant to create")
cmd.Flags().String("avatar-url", "", "the avatar url of the tenant to create")
},
CreateRequestFromCLI: func() (*adminv2.TenantServiceCreateRequest, error) {
return &adminv2.TenantServiceCreateRequest{
Name: viper.GetString("name"),
Description: pointer.PointerOrNil(viper.GetString("description")),
Email: pointer.PointerOrNil(viper.GetString("email")),
AvatarUrl: pointer.PointerOrNil(viper.GetString("avatar-url")),
}, nil
},
OnlyCmds: genericcli.OnlyCmds(genericcli.ListCmd, genericcli.CreateCmd),
ValidArgsFn: w.c.Completion.AdminTenantListCompletion,
}

return genericcli.NewCmds(cmdsConfig)
}

func (c *tenant) Get(id string) (*apiv2.Tenant, error) {
panic("unimplemented")
}

func (c *tenant) List() ([]*apiv2.Tenant, error) {
ctx, cancel := c.c.NewRequestContext()
defer cancel()

req := &adminv2.TenantServiceListRequest{
Name: pointer.PointerOrNil(viper.GetString("name")),
Login: pointer.PointerOrNil(viper.GetString("id")),
Email: pointer.PointerOrNil(viper.GetString("email")),
}

resp, err := c.c.Client.Adminv2().Tenant().List(ctx, req)
if err != nil {
return nil, fmt.Errorf("failed to list tenants: %w", err)
}

return resp.GetTenants(), nil
}

func (c *tenant) Create(rq *adminv2.TenantServiceCreateRequest) (*apiv2.Tenant, error) {
ctx, cancel := c.c.NewRequestContext()
defer cancel()

resp, err := c.c.Client.Adminv2().Tenant().Create(ctx, rq)
if err != nil {
return nil, fmt.Errorf("failed to create tenant: %w", err)
}

return resp.Tenant, nil
}

func (c *tenant) Delete(id string) (*apiv2.Tenant, error) {
panic("unimplemented")
}

func (c *tenant) Convert(r *apiv2.Tenant) (string, *adminv2.TenantServiceCreateRequest, any, error) {
panic("unimplemented")
}

func (c *tenant) Update(rq any) (*apiv2.Tenant, error) {
panic("unimplemented")
}
1 change: 0 additions & 1 deletion cmd/api/v1/tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func newTenantCmd(c *config.Config) *cobra.Command {
cmd.Flags().String("name", "", "the name of the tenant to create")
cmd.Flags().String("description", "", "the description of the tenant to create")
cmd.Flags().String("email", "", "the email of the tenant to create")
cmd.Flags().String("phone", "", "the phone number of the tenant to create")
cmd.Flags().String("avatar-url", "", "the avatar url of the tenant to create")
},
CreateRequestFromCLI: w.createRequestFromCLI,
Expand Down
8 changes: 0 additions & 8 deletions cmd/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ import (
"os"
"strings"
"testing"
"time"

"slices"

"bou.ke/monkey"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
apitests "github.com/metal-stack/api/go/tests"
Expand All @@ -28,12 +26,6 @@ import (
"sigs.k8s.io/yaml"
)

var testTime = time.Date(2022, time.May, 19, 1, 2, 3, 4, time.UTC)

func init() {
_ = monkey.Patch(time.Now, func() time.Time { return testTime })
}

type Test[R any] struct {
Name string
Cmd func(want R) []string
Expand Down
1 change: 0 additions & 1 deletion docs/metalctlv2_tenant_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ metalctlv2 tenant create [flags]

-h, --help help for create
--name string the name of the tenant to create
--phone string the phone number of the tenant to create
--skip-security-prompts skips security prompt for bulk operations
--timestamps when used with --file (bulk operation): prints timestamps in-between the operations
```
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ module github.com/metal-stack/cli
go 1.25

require (
bou.ke/monkey v1.0.2
connectrpc.com/connect v1.19.1
github.com/dustin/go-humanize v1.0.1
github.com/fatih/color v1.18.0
github.com/google/go-cmp v0.7.0
Expand All @@ -23,6 +21,7 @@ require (

require (
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.10-20250912141014-52f32327d4b0.1 // indirect
connectrpc.com/connect v1.19.1 // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/clipperhouse/uax29/v2 v2.2.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
bou.ke/monkey v1.0.2 h1:kWcnsrCNUatbxncxR/ThdYqbytgOIArtYWqcQLQzKLI=
bou.ke/monkey v1.0.2/go.mod h1:OqickVX3tNx6t33n1xvtTtu85YN5s6cKwVug+oHMaIA=
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.10-20250912141014-52f32327d4b0.1 h1:31on4W/yPcV4nZHL4+UCiCvLPsMqe/vJcNg8Rci0scc=
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.10-20250912141014-52f32327d4b0.1/go.mod h1:fUl8CEN/6ZAMk6bP8ahBJPUJw7rbp+j4x+wCcYi2IG4=
connectrpc.com/connect v1.19.1 h1:R5M57z05+90EfEvCY1b7hBxDVOUl45PrtXtAV2fOC14=
Expand Down