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
1 change: 1 addition & 0 deletions cmd/admin/v2/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ func (c *networkCmd) Create(rq *adminv2.NetworkServiceCreateRequest) (*apiv2.Net
if errorutil.IsConflict(err) {
return nil, genericcli.AlreadyExistsError()
}

return nil, err
}

Expand Down
15 changes: 6 additions & 9 deletions cmd/admin/v2/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"sort"
"strings"

"github.com/metal-stack/api/go/errorutil"
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"
Expand Down Expand Up @@ -48,14 +49,6 @@ func newPartitionCmd(c *config.Config) *cobra.Command {
ListPrinter: func() printers.Printer { return c.ListPrinter },
ValidArgsFn: c.Completion.Partition,
Sorter: sorters.PartitionSorter(),
OnlyCmds: genericcli.OnlyCmds(
genericcli.DescribeCmd,
genericcli.ListCmd,
genericcli.CreateCmd,
genericcli.UpdateCmd,
genericcli.DeleteCmd,
genericcli.EditCmd,
),
CreateCmdMutateFn: func(cmd *cobra.Command) {
cmd.Flags().String("id", "", "the id of the partition to create")
addMutableFlags(cmd)
Expand Down Expand Up @@ -173,7 +166,11 @@ func (c *partition) Create(rq *adminv2.PartitionServiceCreateRequest) (*apiv2.Pa

resp, err := c.c.Client.Adminv2().Partition().Create(ctx, rq)
if err != nil {
return nil, fmt.Errorf("failed to create partition: %w", err)
if errorutil.IsConflict(err) {
return nil, genericcli.AlreadyExistsError()
}

return nil, err
}

return resp.Partition, nil
Expand Down
75 changes: 67 additions & 8 deletions cmd/admin/v2/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package v2
import (
"fmt"

"github.com/metal-stack/api/go/errorutil"
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"
Expand All @@ -24,7 +25,7 @@ func newProjectCmd(c *config.Config) *cobra.Command {
c: c,
}

cmdsConfig := &genericcli.CmdsConfig[*apiv2.ProjectServiceCreateRequest, *apiv2.ProjectServiceUpdateRequest, *apiv2.Project]{
cmdsConfig := &genericcli.CmdsConfig[*adminv2.ProjectServiceCreateRequest, *apiv2.ProjectServiceUpdateRequest, *apiv2.Project]{
BinaryName: config.BinaryName,
GenericCLI: genericcli.NewGenericCLI(w).WithFS(c.Fs),
Singular: "project",
Expand All @@ -43,7 +44,19 @@ func newProjectCmd(c *config.Config) *cobra.Command {
}

func (c *project) Get(id string) (*apiv2.Project, error) {
panic("unimplemented")
ctx, cancel := c.c.NewRequestContext()
defer cancel()

req := &apiv2.ProjectServiceGetRequest{
Project: id,
}

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

return resp.GetProject(), nil
}

func (c *project) List() ([]*apiv2.Project, error) {
Expand Down Expand Up @@ -73,18 +86,64 @@ func (c *project) List() ([]*apiv2.Project, error) {
return resp.GetProjects(), nil
}

func (c *project) Create(rq *apiv2.ProjectServiceCreateRequest) (*apiv2.Project, error) {
panic("unimplemented")
func (c *project) Create(rq *adminv2.ProjectServiceCreateRequest) (*apiv2.Project, error) {
ctx, cancel := c.c.NewRequestContext()
defer cancel()

resp, err := c.c.Client.Adminv2().Project().Create(ctx, rq)
if err != nil {
if errorutil.IsConflict(err) {
return nil, genericcli.AlreadyExistsError()
}

return nil, err
}

return resp.Project, nil
}

func (c *project) Delete(id string) (*apiv2.Project, error) {
panic("unimplemented")
ctx, cancel := c.c.NewRequestContext()
defer cancel()

resp, err := c.c.Client.Apiv2().Project().Delete(ctx, &apiv2.ProjectServiceDeleteRequest{
Project: id,
})
if err != nil {
return nil, fmt.Errorf("failed to delete project: %w", err)
}

return resp.Project, nil
}

func (c *project) Convert(r *apiv2.Project) (string, *apiv2.ProjectServiceCreateRequest, *apiv2.ProjectServiceUpdateRequest, error) {
panic("unimplemented")
func (c *project) Convert(r *apiv2.Project) (string, *adminv2.ProjectServiceCreateRequest, *apiv2.ProjectServiceUpdateRequest, error) {
return r.Uuid, &adminv2.ProjectServiceCreateRequest{
Id: pointer.PointerOrNil(r.Uuid),
Project: &apiv2.ProjectServiceCreateRequest{
Login: r.Tenant,
Name: r.Name,
Description: r.Description,
AvatarUrl: r.AvatarUrl,
Labels: pointer.SafeDeref(r.Meta).Labels,
},
}, &apiv2.ProjectServiceUpdateRequest{
Project: r.Uuid,
Name: pointer.PointerOrNil(r.Name),
Description: pointer.PointerOrNil(r.Description),
AvatarUrl: r.AvatarUrl,
UpdateMeta: helpers.UpdateMetaFromMeta(r.Meta),
Labels: helpers.UpdateLabelsFromMeta(r.Meta),
}, nil
}

func (c *project) Update(rq *apiv2.ProjectServiceUpdateRequest) (*apiv2.Project, error) {
panic("unimplemented")
ctx, cancel := c.c.NewRequestContext()
defer cancel()

resp, err := c.c.Client.Apiv2().Project().Update(ctx, rq)
if err != nil {
return nil, fmt.Errorf("failed to update project: %w", err)
}

return resp.Project, nil
}
76 changes: 64 additions & 12 deletions cmd/admin/v2/tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func newTenantCmd(c *config.Config) *cobra.Command {
c: c,
}

cmdsConfig := &genericcli.CmdsConfig[*adminv2.TenantServiceCreateRequest, any, *apiv2.Tenant]{
cmdsConfig := &genericcli.CmdsConfig[*adminv2.TenantServiceCreateRequest, *apiv2.TenantServiceUpdateRequest, *apiv2.Tenant]{
BinaryName: config.BinaryName,
GenericCLI: genericcli.NewGenericCLI(w).WithFS(c.Fs),
Singular: "tenant",
Expand All @@ -41,28 +41,43 @@ func newTenantCmd(c *config.Config) *cobra.Command {
cmd.Flags().StringSlice("labels", nil, "lists only tenant with the given labels")
},
CreateCmdMutateFn: func(cmd *cobra.Command) {
cmd.Flags().String("login", "", "the login id of the tenant to create")
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")),
Login: pointer.PointerOrNil(viper.GetString("login")),
Tenant: &apiv2.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.AdminTenant,
}

return genericcli.NewCmds(cmdsConfig, newAddMemberCmd(c))
}

func (c *tenant) Get(id string) (*apiv2.Tenant, error) {
panic("unimplemented")
ctx, cancel := c.c.NewRequestContext()
defer cancel()

req := &apiv2.TenantServiceGetRequest{
Login: id,
}

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

return resp.GetTenant(), nil
}

func (c *tenant) List() ([]*apiv2.Tenant, error) {
Expand Down Expand Up @@ -110,15 +125,52 @@ func (c *tenant) Create(rq *adminv2.TenantServiceCreateRequest) (*apiv2.Tenant,
}

func (c *tenant) Delete(id string) (*apiv2.Tenant, error) {
panic("unimplemented")
ctx, cancel := c.c.NewRequestContext()
defer cancel()

resp, err := c.c.Client.Apiv2().Tenant().Delete(ctx, &apiv2.TenantServiceDeleteRequest{
Login: id,
})
if err != nil {
return nil, fmt.Errorf("failed to delete tenant: %w", err)
}

return resp.Tenant, nil
}

func (c *tenant) Convert(r *apiv2.Tenant) (string, *adminv2.TenantServiceCreateRequest, any, error) {
panic("unimplemented")
func (c *tenant) Convert(r *apiv2.Tenant) (string, *adminv2.TenantServiceCreateRequest, *apiv2.TenantServiceUpdateRequest, error) {
return r.Login, &adminv2.TenantServiceCreateRequest{
Login: pointer.PointerOrNil(r.Login),
Tenant: &apiv2.TenantServiceCreateRequest{
Name: r.Name,
Description: pointer.PointerOrNil(r.Description),
Email: pointer.PointerOrNil(r.Email),
AvatarUrl: pointer.PointerOrNil(r.AvatarUrl),
Labels: pointer.SafeDeref(r.Meta).Labels,
},
},
&apiv2.TenantServiceUpdateRequest{
Login: r.Login,
Name: pointer.PointerOrNil(r.Name),
Email: pointer.PointerOrNil(r.Email),
Description: pointer.PointerOrNil(r.Description),
AvatarUrl: pointer.PointerOrNil(r.AvatarUrl),
UpdateMeta: helpers.UpdateMetaFromMeta(r.Meta),
Labels: helpers.UpdateLabelsFromMeta(r.Meta),
},
nil
}

func (c *tenant) Update(rq any) (*apiv2.Tenant, error) {
panic("unimplemented")
func (c *tenant) Update(rq *apiv2.TenantServiceUpdateRequest) (*apiv2.Tenant, error) {
ctx, cancel := c.c.NewRequestContext()
defer cancel()

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

return resp.Tenant, nil
}

func newAddMemberCmd(c *config.Config) *cobra.Command {
Expand Down
Loading
Loading