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
56 changes: 45 additions & 11 deletions cmd/api/v1/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (c *ip) updateFromCLI(args []string) (*apiv2.IPServiceUpdateRequest, error)
// FIXME implement
// }

return IpResponseToUpdate(ipToUpdate), nil
return c.IpResponseToUpdate(ipToUpdate)
}

func (c *ip) Create(rq *apiv2.IPServiceCreateRequest) (*apiv2.IP, error) {
Expand Down Expand Up @@ -199,8 +199,9 @@ func (c *ip) Update(rq *apiv2.IPServiceUpdateRequest) (*apiv2.IP, error) {
return resp.Msg.Ip, nil
}

func (*ip) Convert(r *apiv2.IP) (string, *apiv2.IPServiceCreateRequest, *apiv2.IPServiceUpdateRequest, error) {
return helpers.EncodeProject(r.Uuid, r.Project), IpResponseToCreate(r), IpResponseToUpdate(r), nil
func (c *ip) Convert(r *apiv2.IP) (string, *apiv2.IPServiceCreateRequest, *apiv2.IPServiceUpdateRequest, error) {
responseToUpdate, err := c.IpResponseToUpdate(r)
return helpers.EncodeProject(r.Uuid, r.Project), IpResponseToCreate(r), responseToUpdate, err
}

func IpResponseToCreate(r *apiv2.IP) *apiv2.IPServiceCreateRequest {
Expand All @@ -213,15 +214,48 @@ func IpResponseToCreate(r *apiv2.IP) *apiv2.IPServiceCreateRequest {
}
}

func IpResponseToUpdate(r *apiv2.IP) *apiv2.IPServiceUpdateRequest {
return &apiv2.IPServiceUpdateRequest{
Project: r.Project,
Ip: r.Ip,
Name: &r.Name,
Description: &r.Description,
Type: &r.Type,
Labels: r.Meta.Labels,
func (c *ip) IpResponseToUpdate(desired *apiv2.IP) (*apiv2.IPServiceUpdateRequest, error) {

ctx, cancel := c.c.NewRequestContext()
defer cancel()

current, err := c.c.Client.Apiv2().IP().Get(ctx, connect.NewRequest(&apiv2.IPServiceGetRequest{
Ip: desired.Ip,
Project: desired.Project,
}))
if err != nil {
return nil, err
}

updateLabels := &apiv2.UpdateLabels{
Remove: []string{},
Update: &apiv2.Labels{},
}

for key, currentValue := range current.Msg.Ip.Meta.Labels.Labels {
value, ok := desired.Meta.Labels.Labels[key]

if !ok {
updateLabels.Remove = append(updateLabels.Remove, key)
continue
}

if currentValue != value {
if updateLabels.Update.Labels == nil {
updateLabels.Update.Labels = map[string]string{}
}
updateLabels.Update.Labels[key] = value
}
}

return &apiv2.IPServiceUpdateRequest{
Project: desired.Project,
Ip: desired.Ip,
Name: &desired.Name,
Description: &desired.Description,
Type: &desired.Type,
Labels: updateLabels,
}, nil
}

func ipStaticToType(b bool) apiv2.IPType {
Expand Down
5 changes: 4 additions & 1 deletion cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ func (l *login) login() error {
ctx.Token = token

if ctx.DefaultProject == "" {
mc := newApiClient(l.c.GetApiURL(), token)
mc, err := newApiClient(l.c.GetApiURL(), token)
if err != nil {
return err
}

projects, err := mc.Apiv2().Project().List(context.Background(), connect.NewRequest(&apiv2.ProjectServiceListRequest{}))
if err != nil {
Expand Down
11 changes: 8 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"log/slog"
"os"

client "github.com/metal-stack/api/go/client"
Expand Down Expand Up @@ -108,7 +109,10 @@ func initConfigWithViperCtx(c *config.Config) error {
return nil
}

mc := newApiClient(c.GetApiURL(), c.GetToken())
mc, err := newApiClient(c.GetApiURL(), c.GetToken())
if err != nil {
return err
}

c.Client = mc
c.Completion.Client = mc
Expand All @@ -118,12 +122,13 @@ func initConfigWithViperCtx(c *config.Config) error {
return nil
}

func newApiClient(apiURL, token string) client.Client {
dialConfig := client.DialConfig{
func newApiClient(apiURL, token string) (client.Client, error) {
dialConfig := &client.DialConfig{
BaseURL: apiURL,
Token: token,
UserAgent: "metal-stack-cli",
Debug: viper.GetBool("debug"),
Log: slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelInfo})),
}

return client.New(dialConfig)
Expand Down
5 changes: 1 addition & 4 deletions cmd/tableprinters/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/metal-stack/api/go/enum"
apiv2 "github.com/metal-stack/api/go/metalstack/api/v2"
"github.com/metal-stack/metal-lib/pkg/pointer"
"github.com/olekukonko/tablewriter"
)

func (t *TablePrinter) ImageTable(data []*apiv2.Image, wide bool) ([]string, [][]string, error) {
Expand Down Expand Up @@ -42,9 +41,7 @@ func (t *TablePrinter) ImageTable(data []*apiv2.Image, wide bool) ([]string, [][
rows = append(rows, []string{image.Id, pointer.SafeDeref(image.Name), pointer.SafeDeref(image.Description), strings.Join(features, ","), expiresIn, *classification})
}

t.t.MutateTable(func(table *tablewriter.Table) {
table.SetAutoWrapText(false)
})
t.t.DisableAutoWrap(false)

return header, rows, nil
}
5 changes: 1 addition & 4 deletions cmd/tableprinters/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"strings"

apiv2 "github.com/metal-stack/api/go/metalstack/api/v2"
"github.com/olekukonko/tablewriter"
)

func (t *TablePrinter) IPTable(data []*apiv2.IP, wide bool) ([]string, [][]string, error) {
Expand Down Expand Up @@ -50,9 +49,7 @@ func (t *TablePrinter) IPTable(data []*apiv2.IP, wide bool) ([]string, [][]strin
}
}

t.t.MutateTable(func(table *tablewriter.Table) {
table.SetAutoWrapText(false)
})
t.t.DisableAutoWrap(false)

return header, rows, nil
}
9 changes: 2 additions & 7 deletions cmd/tableprinters/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/dustin/go-humanize"
apiv2 "github.com/metal-stack/api/go/metalstack/api/v2"
"github.com/metal-stack/metal-lib/pkg/genericcli"
"github.com/olekukonko/tablewriter"
)

func (t *TablePrinter) ProjectTable(data []*apiv2.Project, _ bool) ([]string, [][]string, error) {
Expand All @@ -28,9 +27,7 @@ func (t *TablePrinter) ProjectTable(data []*apiv2.Project, _ bool) ([]string, []
rows = append(rows, row)
}

t.t.MutateTable(func(table *tablewriter.Table) {
table.SetAutoWrapText(false)
})
t.t.DisableAutoWrap(false)

return header, rows, nil
}
Expand All @@ -52,9 +49,7 @@ func (t *TablePrinter) ProjectInviteTable(data []*apiv2.ProjectInvite, _ bool) (
rows = append(rows, row)
}

t.t.MutateTable(func(table *tablewriter.Table) {
table.SetAutoWrapText(false)
})
t.t.DisableAutoWrap(false)

return header, rows, nil
}
Expand Down
5 changes: 1 addition & 4 deletions cmd/tableprinters/tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package tableprinters

import (
"github.com/dustin/go-humanize"
"github.com/olekukonko/tablewriter"

apiv2 "github.com/metal-stack/api/go/metalstack/api/v2"
)
Expand Down Expand Up @@ -73,9 +72,7 @@ func (t *TablePrinter) TenantInviteTable(data []*apiv2.TenantInvite, _ bool) ([]
rows = append(rows, row)
}

t.t.MutateTable(func(table *tablewriter.Table) {
table.SetAutoWrapText(false)
})
t.t.DisableAutoWrap(false)

return header, rows, nil
}
5 changes: 1 addition & 4 deletions cmd/tableprinters/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

apiv2 "github.com/metal-stack/api/go/metalstack/api/v2"
"github.com/metal-stack/cli/pkg/helpers"
"github.com/olekukonko/tablewriter"
)

func (t *TablePrinter) TokenTable(data []*apiv2.Token, _ bool) ([]string, [][]string, error) {
Expand Down Expand Up @@ -38,9 +37,7 @@ func (t *TablePrinter) TokenTable(data []*apiv2.Token, _ bool) ([]string, [][]st
rows = append(rows, row)
}

t.t.MutateTable(func(table *tablewriter.Table) {
table.SetAutoWrapText(false)
})
t.t.DisableAutoWrap(false)

return header, rows, nil
}
45 changes: 23 additions & 22 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,38 @@ module github.com/metal-stack/cli

go 1.24.0

toolchain go1.24.2

require (
bou.ke/monkey v1.0.2
connectrpc.com/connect v1.18.1
github.com/dustin/go-humanize v1.0.1
github.com/fatih/color v1.18.0
github.com/google/go-cmp v0.7.0
github.com/metal-stack/api v0.0.0-20250507054936-d3d9fbfb4653
github.com/metal-stack/metal-lib v0.22.1
github.com/metal-stack/api v0.0.11
github.com/metal-stack/metal-lib v0.23.3
github.com/metal-stack/v v1.0.3
github.com/olekukonko/tablewriter v0.0.5
github.com/olekukonko/tablewriter v1.0.9
github.com/spf13/afero v1.14.0
github.com/spf13/cobra v1.9.1
github.com/spf13/pflag v1.0.6
github.com/spf13/pflag v1.0.7
github.com/spf13/viper v1.20.1
github.com/stretchr/testify v1.10.0
golang.org/x/net v0.40.0
google.golang.org/protobuf v1.36.6
sigs.k8s.io/yaml v1.4.0
golang.org/x/net v0.43.0
google.golang.org/protobuf v1.36.7
sigs.k8s.io/yaml v1.6.0
)

require (
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.6-20250425153114-8976f5be98c1.1 // indirect
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.7-20250717185734-6c6e0d3c608e.1 // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/fsnotify/fsnotify v1.9.0 // indirect
github.com/go-openapi/errors v0.22.1 // indirect
github.com/go-openapi/errors v0.22.2 // indirect
github.com/go-openapi/strfmt v0.23.0 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
github.com/goccy/go-yaml v1.17.1 // indirect
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
github.com/goccy/go-yaml v1.18.0 // indirect
github.com/golang-jwt/jwt/v5 v5.3.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/klauspost/compress v1.18.0 // indirect
Expand All @@ -44,21 +43,23 @@ require (
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/olekukonko/errors v1.1.0 // indirect
github.com/olekukonko/ll v0.0.9 // indirect
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sagikazarmark/locafero v0.9.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/cast v1.8.0 // indirect
github.com/sagikazarmark/locafero v0.10.0 // indirect
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 // indirect
github.com/spf13/cast v1.9.2 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.mongodb.org/mongo-driver v1.17.3 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/sys v0.33.0 // indirect
golang.org/x/text v0.25.0 // indirect
go.mongodb.org/mongo-driver v1.17.4 // indirect
go.yaml.in/yaml/v2 v2.4.2 // indirect
golang.org/x/sys v0.35.0 // indirect
golang.org/x/text v0.28.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apimachinery v0.33.0 // indirect
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect
k8s.io/apimachinery v0.33.3 // indirect
sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 // indirect
)
Loading