Skip to content
Draft
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ In addition to the standard API services, there are also admin services that req

You can access help for every service and command by using `--help` or `-h`. If you encounter any issues not covered in the help prompt, or if you have suggestions for improvement, please feel free to [contact us](mailto:support@metal-stack.io) or open an issue in this repository. Your feedback is greatly appreciated!

A list of all available services (excluding admin topics). For their associated commands, arguments and flags visit the correct [documentation](./docs/metal.md).
A list of all available services (excluding admin topics). For their associated commands, arguments and flags visit the [metalctlv2 documentation](./docs/metalctlv2.md).

| Entity | Description | Documentation |
|---------------|------------------------------------------------------------|-------------------------------------------------------|
Expand Down
4 changes: 4 additions & 0 deletions cmd/admin/v1/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ func AddCmds(cmd *cobra.Command, c *config.Config) {
adminCmd.AddCommand(newImageCmd(c))
adminCmd.AddCommand(newIPCmd(c))
adminCmd.AddCommand(newNetworkCmd(c))
adminCmd.AddCommand(newSizeCmd(c))
adminCmd.AddCommand(newTenantCmd(c))
adminCmd.AddCommand(newTokenCmd(c))
adminCmd.AddCommand(newProjectCmd(c))
adminCmd.AddCommand(newVPNCmd(c))

cmd.AddCommand(adminCmd)
}
77 changes: 77 additions & 0 deletions cmd/admin/v1/project.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
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 project struct {
c *config.Config
}

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

cmdsConfig := &genericcli.CmdsConfig[*apiv2.ProjectServiceCreateRequest, *apiv2.ProjectServiceUpdateRequest, *apiv2.Project]{
BinaryName: config.BinaryName,
GenericCLI: genericcli.NewGenericCLI(w).WithFS(c.Fs),
Singular: "project",
Plural: "projects",
Description: "manage api projects",
Sorter: sorters.ProjectSorter(),
DescribePrinter: func() printers.Printer { return c.DescribePrinter },
ListPrinter: func() printers.Printer { return c.ListPrinter },
ListCmdMutateFn: func(cmd *cobra.Command) {
cmd.Flags().String("tenant", "", "lists only projects with the given tenant")
},
}

return genericcli.NewCmds(cmdsConfig)
}

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

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

req := &adminv2.ProjectServiceListRequest{
Tenant: pointer.PointerOrNil(viper.GetString("tenant")),
}

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

return resp.GetProjects(), nil
}

func (c *project) Create(rq *apiv2.ProjectServiceCreateRequest) (*apiv2.Project, error) {
panic("unimplemented")
}

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

func (c *project) Convert(r *apiv2.Project) (string, *apiv2.ProjectServiceCreateRequest, *apiv2.ProjectServiceUpdateRequest, error) {
panic("unimplemented")
}

func (c *project) Update(rq *apiv2.ProjectServiceUpdateRequest) (*apiv2.Project, error) {
panic("unimplemented")
}
123 changes: 123 additions & 0 deletions cmd/admin/v1/size.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
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/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 size struct {
c *config.Config
}

func newSizeCmd(c *config.Config) *cobra.Command {
w := &size{
c: c,
}
gcli := genericcli.NewGenericCLI(w).WithFS(c.Fs)

cmdsConfig := &genericcli.CmdsConfig[*adminv2.SizeServiceCreateRequest, *adminv2.SizeServiceUpdateRequest, *apiv2.Size]{
BinaryName: config.BinaryName,
GenericCLI: gcli,
Singular: "size",
Plural: "sizes",
Description: "manage sizes which defines the cpu, gpu, memory and storage properties of machines",
DescribePrinter: func() printers.Printer { return c.DescribePrinter },
ListPrinter: func() printers.Printer { return c.ListPrinter },
ValidArgsFn: c.Completion.SizeListCompletion,
OnlyCmds: genericcli.OnlyCmds(genericcli.CreateCmd, genericcli.UpdateCmd, genericcli.DeleteCmd, genericcli.EditCmd),
}

return genericcli.NewCmds(cmdsConfig)
}

func (c *size) Get(id string) (*apiv2.Size, error) {
ctx, cancel := c.c.NewRequestContext()
defer cancel()

req := &apiv2.SizeServiceGetRequest{Id: id}

resp, err := c.c.Client.Apiv2().Size().Get(ctx, req)
if err != nil {
return nil, fmt.Errorf("failed to get size: %w", err)
}

return resp.Size, nil
}

func (c *size) Create(rq *adminv2.SizeServiceCreateRequest) (*apiv2.Size, error) {
ctx, cancel := c.c.NewRequestContext()
defer cancel()

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

return resp.Size, nil
}

func (c *size) Delete(id string) (*apiv2.Size, error) {
ctx, cancel := c.c.NewRequestContext()
defer cancel()

req := &adminv2.SizeServiceDeleteRequest{Id: id}

resp, err := c.c.Client.Adminv2().Size().Delete(ctx, req)
if err != nil {
return nil, fmt.Errorf("failed to delete size: %w", err)
}

return resp.Size, nil
}
func (c *size) List() ([]*apiv2.Size, error) {
panic("unimplemented")

}
func (c *size) Convert(r *apiv2.Size) (string, *adminv2.SizeServiceCreateRequest, *adminv2.SizeServiceUpdateRequest, error) {

return r.Id, &adminv2.SizeServiceCreateRequest{
Size: &apiv2.Size{
Id: r.Id,
Name: r.Name,
Description: r.Description,
Meta: r.Meta,
Constraints: r.Constraints,
},
}, &adminv2.SizeServiceUpdateRequest{
Id: r.Id,
Name: r.Name,
Description: r.Description,
Constraints: r.Constraints,
// FIXME
Labels: &apiv2.UpdateLabels{},
}, nil

}

func (c *size) Update(rq *adminv2.SizeServiceUpdateRequest) (*apiv2.Size, error) {
ctx, cancel := c.c.NewRequestContext()
defer cancel()

req := &adminv2.SizeServiceUpdateRequest{
Id: viper.GetString("id"),
Name: pointer.PointerOrNil(viper.GetString("name")),
Description: pointer.PointerOrNil(viper.GetString("description")),
Constraints: rq.Constraints,
Labels: &apiv2.UpdateLabels{}, // FIXME
}

resp, err := c.c.Client.Adminv2().Size().Update(ctx, req)
if err != nil {
return nil, fmt.Errorf("failed to get size: %w", err)
}

return resp.Size, nil
}
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")
}
Loading