From 6bc6b750cce355d710ee523771815059a526a9ec Mon Sep 17 00:00:00 2001 From: Stefan Majer Date: Thu, 16 Oct 2025 11:26:15 +0200 Subject: [PATCH 1/2] Migrate to simple --- cmd/root.go | 7 +++++-- go.mod | 10 +++++----- go.sum | 20 ++++++++++---------- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 5320980..9bb0ce1 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -123,12 +123,15 @@ func initConfigWithViperCtx(c *config.Config) error { } func newApiClient(apiURL, token string) (client.Client, error) { + logLevel := slog.LevelInfo + if viper.GetBool("debug") { + logLevel = slog.LevelDebug + } 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})), + Log: slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: logLevel})), } return client.New(dialConfig) diff --git a/go.mod b/go.mod index 18675b1..1b2f7a0 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( 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.22 + github.com/metal-stack/api v0.0.31 github.com/metal-stack/metal-lib v0.23.5 github.com/metal-stack/v v1.0.3 github.com/spf13/afero v1.15.0 @@ -16,7 +16,7 @@ require ( github.com/spf13/pflag v1.0.10 github.com/spf13/viper v1.21.0 github.com/stretchr/testify v1.11.1 - golang.org/x/net v0.45.0 + golang.org/x/net v0.46.0 google.golang.org/protobuf v1.36.10 sigs.k8s.io/yaml v1.6.0 ) @@ -44,7 +44,7 @@ require ( github.com/oklog/ulid v1.3.1 // indirect github.com/olekukonko/cat v0.0.0-20250911104152-50322a0618f6 // indirect github.com/olekukonko/errors v1.1.0 // indirect - github.com/olekukonko/ll v0.1.1 // indirect + github.com/olekukonko/ll v0.1.2 // indirect github.com/olekukonko/tablewriter v1.1.0 // indirect github.com/pelletier/go-toml/v2 v2.2.4 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect @@ -57,8 +57,8 @@ require ( go.mongodb.org/mongo-driver v1.17.4 // indirect go.yaml.in/yaml/v2 v2.4.3 // indirect go.yaml.in/yaml/v3 v3.0.4 // indirect - golang.org/x/sys v0.36.0 // indirect - golang.org/x/text v0.29.0 // indirect + golang.org/x/sys v0.37.0 // indirect + golang.org/x/text v0.30.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect k8s.io/apimachinery v0.34.1 // indirect diff --git a/go.sum b/go.sum index 463d801..4846edb 100644 --- a/go.sum +++ b/go.sum @@ -55,8 +55,8 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.19 h1:v++JhqYnZuu5jSKrk9RbgF5v4CGUjqRfBm05byFGLdw= github.com/mattn/go-runewidth v0.0.19/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs= -github.com/metal-stack/api v0.0.22 h1:AGslhOY29u8BEp/YOsQ7knjrGny945U2Ei9v87r6E9s= -github.com/metal-stack/api v0.0.22/go.mod h1:X9UVCG20w94kkjG94zpHEi9vEf2ueS9G5WJndnEuUP8= +github.com/metal-stack/api v0.0.31 h1:ivgaqYuWFrGO4IZS/9ViwkuV1AzytZlji6zgDnANo+s= +github.com/metal-stack/api v0.0.31/go.mod h1:LcJkrJPJRdLPFaeCiWy5tL0dJXU74kq+vFe5uc/Cm9U= github.com/metal-stack/metal-lib v0.23.5 h1:ozrkB3DNr3Cqn8nkBvmzc/KKpYqC1j1mv2OVOj8i7Ac= github.com/metal-stack/metal-lib v0.23.5/go.mod h1:7uyHIrE19dkLwCZyeh2jmd7IEq5pEpzrzUGLoMN1eqY= github.com/metal-stack/v v1.0.3 h1:Sh2oBlnxrCUD+mVpzfC8HiqL045YWkxs0gpTvkjppqs= @@ -67,8 +67,8 @@ github.com/olekukonko/cat v0.0.0-20250911104152-50322a0618f6 h1:zrbMGy9YXpIeTnGj github.com/olekukonko/cat v0.0.0-20250911104152-50322a0618f6/go.mod h1:rEKTHC9roVVicUIfZK7DYrdIoM0EOr8mK1Hj5s3JjH0= github.com/olekukonko/errors v1.1.0 h1:RNuGIh15QdDenh+hNvKrJkmxxjV4hcS50Db478Ou5sM= github.com/olekukonko/errors v1.1.0/go.mod h1:ppzxA5jBKcO1vIpCXQ9ZqgDh8iwODz6OXIGKU8r5m4Y= -github.com/olekukonko/ll v0.1.1 h1:9Dfeed5/Mgaxb9lHRAftLK9pVfYETvHn+If6lywVhJc= -github.com/olekukonko/ll v0.1.1/go.mod h1:2dJo+hYZcJMLMbKwHEWvxCUbAOLc/CXWS9noET22Mdo= +github.com/olekukonko/ll v0.1.2 h1:lkg/k/9mlsy0SxO5aC+WEpbdT5K83ddnNhAepz7TQc0= +github.com/olekukonko/ll v0.1.2/go.mod h1:b52bVQRRPObe+yyBl0TxNfhesL0nedD4Cht0/zx55Ew= github.com/olekukonko/tablewriter v1.1.0 h1:N0LHrshF4T39KvI96fn6GT8HEjXRXYNDrDjKFDB7RIY= github.com/olekukonko/tablewriter v1.1.0/go.mod h1:5c+EBPeSqvXnLLgkm9isDdzR3wjfBkHR9Nhfp3NWrzo= github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4= @@ -106,13 +106,13 @@ go.yaml.in/yaml/v2 v2.4.3 h1:6gvOSjQoTB3vt1l+CU+tSyi/HOjfOjRLJ4YwYZGwRO0= go.yaml.in/yaml/v2 v2.4.3/go.mod h1:zSxWcmIDjOzPXpjlTTbAsKokqkDNAVtZO0WOMiT90s8= go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc= go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= -golang.org/x/net v0.45.0 h1:RLBg5JKixCy82FtLJpeNlVM0nrSqpCRYzVU1n8kj0tM= -golang.org/x/net v0.45.0/go.mod h1:ECOoLqd5U3Lhyeyo/QDCEVQ4sNgYsqvCZ722XogGieY= +golang.org/x/net v0.46.0 h1:giFlY12I07fugqwPuWJi68oOnpfqFnJIJzaIIm2JVV4= +golang.org/x/net v0.46.0/go.mod h1:Q9BGdFy1y4nkUwiLvT5qtyhAnEHgnQ/zd8PfU6nc210= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k= -golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= -golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk= -golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4= +golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ= +golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= +golang.org/x/text v0.30.0 h1:yznKA/E9zq54KzlzBEAWn1NXSQ8DIp/NYMy88xJjl4k= +golang.org/x/text v0.30.0/go.mod h1:yDdHFIX9t+tORqspjENWgzaCVXgk0yYnYuSZ8UzzBVM= google.golang.org/protobuf v1.36.10 h1:AYd7cD/uASjIL6Q9LiTjz8JLcrh/88q5UObnmY3aOOE= google.golang.org/protobuf v1.36.10/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From 9dbdf8970376f12d7e2940abe90079a71e67bc5d Mon Sep 17 00:00:00 2001 From: Ilja Rotar Date: Thu, 16 Oct 2025 11:32:00 +0200 Subject: [PATCH 2/2] remove connect and .msg --- cmd/admin/v1/image.go | 17 +++++---- cmd/admin/v1/token.go | 7 ++-- cmd/api/v1/health.go | 5 ++- cmd/api/v1/image.go | 13 ++++--- cmd/api/v1/ip.go | 31 ++++++++--------- cmd/api/v1/methods.go | 9 +++-- cmd/api/v1/project.go | 73 +++++++++++++++++++-------------------- cmd/api/v1/tenant.go | 73 +++++++++++++++++++-------------------- cmd/api/v1/token.go | 21 ++++++----- cmd/api/v1/user.go | 5 ++- cmd/api/v1/version.go | 5 ++- cmd/completion/ip.go | 5 ++- cmd/completion/project.go | 17 +++++---- cmd/completion/tenant.go | 33 +++++++++--------- cmd/completion/token.go | 19 +++++----- cmd/config/config.go | 7 ++-- cmd/login.go | 13 ++++--- 17 files changed, 168 insertions(+), 185 deletions(-) diff --git a/cmd/admin/v1/image.go b/cmd/admin/v1/image.go index 25c7d9d..be9e7d0 100644 --- a/cmd/admin/v1/image.go +++ b/cmd/admin/v1/image.go @@ -5,7 +5,6 @@ import ( "strings" "time" - "connectrpc.com/connect" 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" @@ -52,12 +51,12 @@ func (c *image) Get(id string) (*apiv2.Image, error) { req := &apiv2.ImageServiceGetRequest{Id: id} - resp, err := c.c.Client.Apiv2().Image().Get(ctx, connect.NewRequest(req)) + resp, err := c.c.Client.Apiv2().Image().Get(ctx, req) if err != nil { return nil, fmt.Errorf("failed to get image: %w", err) } - return resp.Msg.Image, nil + return resp.Image, nil } func (c *image) Create(rq *adminv2.ImageServiceCreateRequest) (*apiv2.Image, error) { @@ -82,12 +81,12 @@ func (c *image) Create(rq *adminv2.ImageServiceCreateRequest) (*apiv2.Image, err }, } - resp, err := c.c.Client.Adminv2().Image().Create(ctx, connect.NewRequest(req)) + resp, err := c.c.Client.Adminv2().Image().Create(ctx, req) if err != nil { return nil, fmt.Errorf("failed to get image: %w", err) } - return resp.Msg.Image, nil + return resp.Image, nil } func (c *image) Delete(id string) (*apiv2.Image, error) { @@ -96,12 +95,12 @@ func (c *image) Delete(id string) (*apiv2.Image, error) { req := &adminv2.ImageServiceDeleteRequest{Id: id} - resp, err := c.c.Client.Adminv2().Image().Delete(ctx, connect.NewRequest(req)) + resp, err := c.c.Client.Adminv2().Image().Delete(ctx, req) if err != nil { return nil, fmt.Errorf("failed to delete image: %w", err) } - return resp.Msg.Image, nil + return resp.Image, nil } func (c *image) List() ([]*apiv2.Image, error) { panic("unimplemented") @@ -157,12 +156,12 @@ func (c *image) Update(rq *adminv2.ImageServiceUpdateRequest) (*apiv2.Image, err }, } - resp, err := c.c.Client.Adminv2().Image().Update(ctx, connect.NewRequest(req)) + resp, err := c.c.Client.Adminv2().Image().Update(ctx, req) if err != nil { return nil, fmt.Errorf("failed to get image: %w", err) } - return resp.Msg.Image, nil + return resp.Image, nil } func imageFeaturesFromString(features []string) []apiv2.ImageFeature { diff --git a/cmd/admin/v1/token.go b/cmd/admin/v1/token.go index 8464989..91f0bbd 100644 --- a/cmd/admin/v1/token.go +++ b/cmd/admin/v1/token.go @@ -3,7 +3,6 @@ package v1 import ( "fmt" - "connectrpc.com/connect" 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" @@ -61,12 +60,12 @@ func (c *token) List() ([]*apiv2.Token, error) { req.User = pointer.Pointer(viper.GetString("user")) } - resp, err := c.c.Client.Adminv2().Token().List(ctx, connect.NewRequest(req)) + resp, err := c.c.Client.Adminv2().Token().List(ctx, req) if err != nil { return nil, fmt.Errorf("failed to list tokens: %w", err) } - return resp.Msg.GetTokens(), nil + return resp.GetTokens(), nil } func (t *token) Create(rq any) (*apiv2.Token, error) { @@ -86,7 +85,7 @@ func (c *token) Delete(id string) (*apiv2.Token, error) { User: viper.GetString("user"), } - _, err := c.c.Client.Adminv2().Token().Revoke(ctx, connect.NewRequest(req)) + _, err := c.c.Client.Adminv2().Token().Revoke(ctx, req) if err != nil { return nil, fmt.Errorf("failed to revoke token: %w", err) } diff --git a/cmd/api/v1/health.go b/cmd/api/v1/health.go index 9916949..eac6678 100644 --- a/cmd/api/v1/health.go +++ b/cmd/api/v1/health.go @@ -3,7 +3,6 @@ package v1 import ( "fmt" - "connectrpc.com/connect" v1 "github.com/metal-stack/api/go/metalstack/api/v2" "github.com/metal-stack/cli/cmd/config" "github.com/spf13/cobra" @@ -18,12 +17,12 @@ func newHealthCmd(c *config.Config) *cobra.Command { ctx, cancel := c.NewRequestContext() defer cancel() - resp, err := c.Client.Apiv2().Health().Get(ctx, connect.NewRequest(&v1.HealthServiceGetRequest{})) + resp, err := c.Client.Apiv2().Health().Get(ctx, &v1.HealthServiceGetRequest{}) if err != nil { return fmt.Errorf("failed to get health: %w", err) } - return c.ListPrinter.Print(resp.Msg.Health) + return c.ListPrinter.Print(resp.Health) }, } diff --git a/cmd/api/v1/image.go b/cmd/api/v1/image.go index 438c399..14da8c9 100644 --- a/cmd/api/v1/image.go +++ b/cmd/api/v1/image.go @@ -4,7 +4,6 @@ import ( "fmt" "strings" - "connectrpc.com/connect" 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" @@ -68,12 +67,12 @@ func (c *image) Get(id string) (*apiv2.Image, error) { req := &apiv2.ImageServiceGetRequest{Id: id} - resp, err := c.c.Client.Apiv2().Image().Get(ctx, connect.NewRequest(req)) + resp, err := c.c.Client.Apiv2().Image().Get(ctx, req) if err != nil { return nil, fmt.Errorf("failed to get image: %w", err) } - return resp.Msg.Image, nil + return resp.Image, nil } func (c *image) List() ([]*apiv2.Image, error) { @@ -89,12 +88,12 @@ func (c *image) List() ([]*apiv2.Image, error) { Feature: imageFeatureFromString(viper.GetString("feature")), }} - resp, err := c.c.Client.Apiv2().Image().List(ctx, connect.NewRequest(req)) + resp, err := c.c.Client.Apiv2().Image().List(ctx, req) if err != nil { return nil, fmt.Errorf("failed to get images: %w", err) } - return resp.Msg.Images, nil + return resp.Images, nil } func (c *image) latest() error { @@ -103,12 +102,12 @@ func (c *image) latest() error { req := &apiv2.ImageServiceLatestRequest{Os: viper.GetString("os")} - resp, err := c.c.Client.Apiv2().Image().Latest(ctx, connect.NewRequest(req)) + resp, err := c.c.Client.Apiv2().Image().Latest(ctx, req) if err != nil { return fmt.Errorf("failed to get images: %w", err) } - return c.c.ListPrinter.Print(resp.Msg.Image) + return c.c.ListPrinter.Print(resp.Image) } func imageFeatureFromString(feature string) *apiv2.ImageFeature { diff --git a/cmd/api/v1/ip.go b/cmd/api/v1/ip.go index cdb6e2c..3c757fa 100644 --- a/cmd/api/v1/ip.go +++ b/cmd/api/v1/ip.go @@ -3,7 +3,6 @@ package v1 import ( "fmt" - "connectrpc.com/connect" apiv2 "github.com/metal-stack/api/go/metalstack/api/v2" "github.com/metal-stack/cli/cmd/config" "github.com/metal-stack/cli/cmd/sorters" @@ -125,12 +124,12 @@ func (c *ip) Create(rq *apiv2.IPServiceCreateRequest) (*apiv2.IP, error) { ctx, cancel := c.c.NewRequestContext() defer cancel() - resp, err := c.c.Client.Apiv2().IP().Create(ctx, connect.NewRequest(rq)) + resp, err := c.c.Client.Apiv2().IP().Create(ctx, rq) if err != nil { return nil, err } - return resp.Msg.Ip, nil + return resp.Ip, nil } func (c *ip) Delete(id string) (*apiv2.IP, error) { @@ -150,53 +149,53 @@ func (c *ip) Delete(id string) (*apiv2.IP, error) { } } - resp, err := c.c.Client.Apiv2().IP().Delete(ctx, connect.NewRequest(req)) + resp, err := c.c.Client.Apiv2().IP().Delete(ctx, req) if err != nil { return nil, err } - return resp.Msg.Ip, nil + return resp.Ip, nil } func (c *ip) Get(id string) (*apiv2.IP, error) { ctx, cancel := c.c.NewRequestContext() defer cancel() - resp, err := c.c.Client.Apiv2().IP().Get(ctx, connect.NewRequest(&apiv2.IPServiceGetRequest{ + resp, err := c.c.Client.Apiv2().IP().Get(ctx, &apiv2.IPServiceGetRequest{ Project: c.c.GetProject(), Ip: id, - })) + }) if err != nil { return nil, err } - return resp.Msg.Ip, nil + return resp.Ip, nil } func (c *ip) List() ([]*apiv2.IP, error) { ctx, cancel := c.c.NewRequestContext() defer cancel() - resp, err := c.c.Client.Apiv2().IP().List(ctx, connect.NewRequest(&apiv2.IPServiceListRequest{ + resp, err := c.c.Client.Apiv2().IP().List(ctx, &apiv2.IPServiceListRequest{ Project: c.c.GetProject(), - })) + }) if err != nil { return nil, err } - return resp.Msg.Ips, nil + return resp.Ips, nil } func (c *ip) Update(rq *apiv2.IPServiceUpdateRequest) (*apiv2.IP, error) { ctx, cancel := c.c.NewRequestContext() defer cancel() - resp, err := c.c.Client.Apiv2().IP().Update(ctx, connect.NewRequest(rq)) + resp, err := c.c.Client.Apiv2().IP().Update(ctx, rq) if err != nil { return nil, err } - return resp.Msg.Ip, nil + return resp.Ip, nil } func (c *ip) Convert(r *apiv2.IP) (string, *apiv2.IPServiceCreateRequest, *apiv2.IPServiceUpdateRequest, error) { @@ -219,10 +218,10 @@ func (c *ip) IpResponseToUpdate(desired *apiv2.IP) (*apiv2.IPServiceUpdateReques ctx, cancel := c.c.NewRequestContext() defer cancel() - current, err := c.c.Client.Apiv2().IP().Get(ctx, connect.NewRequest(&apiv2.IPServiceGetRequest{ + current, err := c.c.Client.Apiv2().IP().Get(ctx, &apiv2.IPServiceGetRequest{ Ip: desired.Ip, Project: desired.Project, - })) + }) if err != nil { return nil, err } @@ -232,7 +231,7 @@ func (c *ip) IpResponseToUpdate(desired *apiv2.IP) (*apiv2.IPServiceUpdateReques Update: &apiv2.Labels{}, } - for key, currentValue := range current.Msg.Ip.Meta.Labels.Labels { + for key, currentValue := range current.Ip.Meta.Labels.Labels { value, ok := desired.Meta.Labels.Labels[key] if !ok { diff --git a/cmd/api/v1/methods.go b/cmd/api/v1/methods.go index 5fd8f3e..ff71c49 100644 --- a/cmd/api/v1/methods.go +++ b/cmd/api/v1/methods.go @@ -4,7 +4,6 @@ import ( "fmt" "sort" - "connectrpc.com/connect" 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/printers" @@ -24,12 +23,12 @@ func newMethodsCmd(c *config.Config) *cobra.Command { req := &apiv2.MethodServiceTokenScopedListRequest{} - resp, err := c.Client.Apiv2().Method().TokenScopedList(ctx, connect.NewRequest(req)) + resp, err := c.Client.Apiv2().Method().TokenScopedList(ctx, req) if err != nil { return fmt.Errorf("failed to list methods: %w", err) } - return printers.NewProtoYAMLPrinter().WithOut(c.Out).Print(resp.Msg) + return printers.NewProtoYAMLPrinter().WithOut(c.Out).Print(resp) } var ( @@ -37,12 +36,12 @@ func newMethodsCmd(c *config.Config) *cobra.Command { req = &apiv2.MethodServiceListRequest{} ) - resp, err := c.Client.Apiv2().Method().List(ctx, connect.NewRequest(req)) + resp, err := c.Client.Apiv2().Method().List(ctx, req) if err != nil { return fmt.Errorf("failed to list methods: %w", err) } - methods = resp.Msg.GetMethods() + methods = resp.GetMethods() sort.Strings(methods) diff --git a/cmd/api/v1/project.go b/cmd/api/v1/project.go index 1087c38..023708e 100644 --- a/cmd/api/v1/project.go +++ b/cmd/api/v1/project.go @@ -3,7 +3,6 @@ package v1 import ( "fmt" - "connectrpc.com/connect" "github.com/dustin/go-humanize" "github.com/fatih/color" apiv2 "github.com/metal-stack/api/go/metalstack/api/v2" @@ -171,12 +170,12 @@ func (c *project) Get(id string) (*apiv2.Project, error) { Project: id, } - resp, err := c.c.Client.Apiv2().Project().Get(ctx, connect.NewRequest(req)) + 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.Msg.GetProject(), nil + return resp.GetProject(), nil } func (c *project) List() ([]*apiv2.Project, error) { @@ -188,38 +187,38 @@ func (c *project) List() ([]*apiv2.Project, error) { Tenant: pointer.PointerOrNil(viper.GetString("tenant")), } - resp, err := c.c.Client.Apiv2().Project().List(ctx, connect.NewRequest(req)) + resp, err := c.c.Client.Apiv2().Project().List(ctx, req) if err != nil { return nil, fmt.Errorf("failed to list projects: %w", err) } - return resp.Msg.GetProjects(), nil + return resp.GetProjects(), nil } func (c *project) Create(rq *apiv2.ProjectServiceCreateRequest) (*apiv2.Project, error) { ctx, cancel := c.c.NewRequestContext() defer cancel() - resp, err := c.c.Client.Apiv2().Project().Create(ctx, connect.NewRequest(rq)) + resp, err := c.c.Client.Apiv2().Project().Create(ctx, rq) if err != nil { return nil, fmt.Errorf("failed to create project: %w", err) } - return resp.Msg.Project, nil + return resp.Project, nil } func (c *project) Delete(id string) (*apiv2.Project, error) { ctx, cancel := c.c.NewRequestContext() defer cancel() - resp, err := c.c.Client.Apiv2().Project().Delete(ctx, connect.NewRequest(&apiv2.ProjectServiceDeleteRequest{ + 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.Msg.Project, nil + return resp.Project, nil } func (c *project) Convert(r *apiv2.Project) (string, *apiv2.ProjectServiceCreateRequest, *apiv2.ProjectServiceUpdateRequest, error) { @@ -238,12 +237,12 @@ func (c *project) Update(rq *apiv2.ProjectServiceUpdateRequest) (*apiv2.Project, ctx, cancel := c.c.NewRequestContext() defer cancel() - resp, err := c.c.Client.Apiv2().Project().Update(ctx, connect.NewRequest(rq)) + 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.Msg.Project, nil + return resp.Project, nil } func (c *project) createRequestFromCLI() (*apiv2.ProjectServiceCreateRequest, error) { @@ -294,9 +293,9 @@ func (c *project) join(args []string) error { ctx, cancel := c.c.NewRequestContext() defer cancel() - resp, err := c.c.Client.Apiv2().Project().InviteGet(ctx, connect.NewRequest(&apiv2.ProjectServiceInviteGetRequest{ + resp, err := c.c.Client.Apiv2().Project().InviteGet(ctx, &apiv2.ProjectServiceInviteGetRequest{ Secret: secret, - })) + }) if err != nil { return fmt.Errorf("failed to get project invite: %w", err) } @@ -305,8 +304,8 @@ func (c *project) join(args []string) error { ShowAnswers: true, Message: fmt.Sprintf( "Do you want to join project \"%s\" as %s?", - color.GreenString(resp.Msg.GetInvite().GetProjectName()), - resp.Msg.GetInvite().GetRole().String(), + color.GreenString(resp.GetInvite().GetProjectName()), + resp.GetInvite().GetRole().String(), ), In: c.c.In, Out: c.c.Out, @@ -318,14 +317,14 @@ func (c *project) join(args []string) error { ctx2, cancel2 := c.c.NewRequestContext() defer cancel2() - acceptResp, err := c.c.Client.Apiv2().Project().InviteAccept(ctx2, connect.NewRequest(&apiv2.ProjectServiceInviteAcceptRequest{ + acceptResp, err := c.c.Client.Apiv2().Project().InviteAccept(ctx2, &apiv2.ProjectServiceInviteAcceptRequest{ Secret: secret, - })) + }) if err != nil { return fmt.Errorf("failed to join project: %w", err) } - _, _ = fmt.Fprintf(c.c.Out, "%s successfully joined project \"%s\"\n", color.GreenString("✔"), color.GreenString(acceptResp.Msg.ProjectName)) + _, _ = fmt.Fprintf(c.c.Out, "%s successfully joined project \"%s\"\n", color.GreenString("✔"), color.GreenString(acceptResp.ProjectName)) return nil } @@ -339,16 +338,16 @@ func (c *project) generateInvite() error { return fmt.Errorf("project is required") } - resp, err := c.c.Client.Apiv2().Project().Invite(ctx, connect.NewRequest(&apiv2.ProjectServiceInviteRequest{ + resp, err := c.c.Client.Apiv2().Project().Invite(ctx, &apiv2.ProjectServiceInviteRequest{ Project: project, Role: apiv2.ProjectRole(apiv2.ProjectRole_value[viper.GetString("role")]), - })) + }) if err != nil { return fmt.Errorf("failed to generate an invite: %w", err) } - _, _ = fmt.Fprintf(c.c.Out, "You can share this secret with the member to join, it expires in %s:\n\n", humanize.Time(resp.Msg.Invite.ExpiresAt.AsTime())) - _, _ = fmt.Fprintf(c.c.Out, "%s (https://console.metal-stack.io/project-invite/%s)\n", resp.Msg.Invite.Secret, resp.Msg.Invite.Secret) + _, _ = fmt.Fprintf(c.c.Out, "You can share this secret with the member to join, it expires in %s:\n\n", humanize.Time(resp.Invite.ExpiresAt.AsTime())) + _, _ = fmt.Fprintf(c.c.Out, "%s (https://console.metal-stack.io/project-invite/%s)\n", resp.Invite.Secret, resp.Invite.Secret) return nil } @@ -357,19 +356,19 @@ func (c *project) listInvites() error { ctx, cancel := c.c.NewRequestContext() defer cancel() - resp, err := c.c.Client.Apiv2().Project().InvitesList(ctx, connect.NewRequest(&apiv2.ProjectServiceInvitesListRequest{ + resp, err := c.c.Client.Apiv2().Project().InvitesList(ctx, &apiv2.ProjectServiceInvitesListRequest{ Project: c.c.GetProject(), - })) + }) if err != nil { return fmt.Errorf("failed to list invites: %w", err) } - err = sorters.ProjectInviteSorter().SortBy(resp.Msg.Invites) + err = sorters.ProjectInviteSorter().SortBy(resp.Invites) if err != nil { return err } - return c.c.ListPrinter.Print(resp.Msg.Invites) + return c.c.ListPrinter.Print(resp.Invites) } func (c *project) deleteInvite(args []string) error { @@ -381,10 +380,10 @@ func (c *project) deleteInvite(args []string) error { ctx, cancel := c.c.NewRequestContext() defer cancel() - _, err = c.c.Client.Apiv2().Project().InviteDelete(ctx, connect.NewRequest(&apiv2.ProjectServiceInviteDeleteRequest{ + _, err = c.c.Client.Apiv2().Project().InviteDelete(ctx, &apiv2.ProjectServiceInviteDeleteRequest{ Project: c.c.GetProject(), Secret: secret, - })) + }) if err != nil { return fmt.Errorf("failed to delete invite: %w", err) } @@ -401,10 +400,10 @@ func (c *project) removeMember(args []string) error { ctx, cancel := c.c.NewRequestContext() defer cancel() - _, err = c.c.Client.Apiv2().Project().RemoveMember(ctx, connect.NewRequest(&apiv2.ProjectServiceRemoveMemberRequest{ + _, err = c.c.Client.Apiv2().Project().RemoveMember(ctx, &apiv2.ProjectServiceRemoveMemberRequest{ Project: c.c.GetProject(), Member: member, - })) + }) if err != nil { return fmt.Errorf("failed to remove member from project: %w", err) } @@ -423,30 +422,30 @@ func (c *project) updateMember(args []string) error { ctx, cancel := c.c.NewRequestContext() defer cancel() - resp, err := c.c.Client.Apiv2().Project().UpdateMember(ctx, connect.NewRequest(&apiv2.ProjectServiceUpdateMemberRequest{ + resp, err := c.c.Client.Apiv2().Project().UpdateMember(ctx, &apiv2.ProjectServiceUpdateMemberRequest{ Project: c.c.GetProject(), Member: member, Role: apiv2.ProjectRole(apiv2.ProjectRole_value[viper.GetString("role")]), - })) + }) if err != nil { return fmt.Errorf("failed to update member: %w", err) } - return c.c.DescribePrinter.Print(resp.Msg.GetProjectMember()) + return c.c.DescribePrinter.Print(resp.GetProjectMember()) } func (c *project) listMembers() error { ctx, cancel := c.c.NewRequestContext() defer cancel() - resp, err := c.c.Client.Apiv2().Project().Get(ctx, connect.NewRequest(&apiv2.ProjectServiceGetRequest{ + resp, err := c.c.Client.Apiv2().Project().Get(ctx, &apiv2.ProjectServiceGetRequest{ Project: c.c.GetProject(), - })) + }) if err != nil { return fmt.Errorf("failed to get project: %w", err) } - members := resp.Msg.GetProjectMembers() + members := resp.GetProjectMembers() if err := sorters.ProjectMemberSorter().SortBy(members); err != nil { return err diff --git a/cmd/api/v1/tenant.go b/cmd/api/v1/tenant.go index 8893597..c26fe7e 100644 --- a/cmd/api/v1/tenant.go +++ b/cmd/api/v1/tenant.go @@ -3,7 +3,6 @@ package v1 import ( "fmt" - "connectrpc.com/connect" "github.com/dustin/go-humanize" "github.com/fatih/color" apiv2 "github.com/metal-stack/api/go/metalstack/api/v2" @@ -173,12 +172,12 @@ func (c *tenant) Get(id string) (*apiv2.Tenant, error) { Login: id, } - resp, err := c.c.Client.Apiv2().Tenant().Get(ctx, connect.NewRequest(req)) + 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.Msg.GetTenant(), nil + return resp.GetTenant(), nil } func (c *tenant) List() ([]*apiv2.Tenant, error) { @@ -189,38 +188,38 @@ func (c *tenant) List() ([]*apiv2.Tenant, error) { Name: pointer.PointerOrNil(viper.GetString("name")), Id: pointer.PointerOrNil(viper.GetString("tenant")), } - resp, err := c.c.Client.Apiv2().Tenant().List(ctx, connect.NewRequest(req)) + resp, err := c.c.Client.Apiv2().Tenant().List(ctx, req) if err != nil { return nil, fmt.Errorf("failed to list tenants: %w", err) } - return resp.Msg.GetTenants(), nil + return resp.GetTenants(), nil } func (c *tenant) Create(rq *apiv2.TenantServiceCreateRequest) (*apiv2.Tenant, error) { ctx, cancel := c.c.NewRequestContext() defer cancel() - resp, err := c.c.Client.Apiv2().Tenant().Create(ctx, connect.NewRequest(rq)) + resp, err := c.c.Client.Apiv2().Tenant().Create(ctx, rq) if err != nil { return nil, fmt.Errorf("failed to create tenant: %w", err) } - return resp.Msg.Tenant, nil + return resp.Tenant, nil } func (c *tenant) Delete(id string) (*apiv2.Tenant, error) { ctx, cancel := c.c.NewRequestContext() defer cancel() - resp, err := c.c.Client.Apiv2().Tenant().Delete(ctx, connect.NewRequest(&apiv2.TenantServiceDeleteRequest{ + 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.Msg.Tenant, nil + return resp.Tenant, nil } func (c *tenant) Convert(r *apiv2.Tenant) (string, *apiv2.TenantServiceCreateRequest, *apiv2.TenantServiceUpdateRequest, error) { @@ -244,12 +243,12 @@ func (c *tenant) Update(rq *apiv2.TenantServiceUpdateRequest) (*apiv2.Tenant, er ctx, cancel := c.c.NewRequestContext() defer cancel() - resp, err := c.c.Client.Apiv2().Tenant().Update(ctx, connect.NewRequest(rq)) + 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.Msg.Tenant, nil + return resp.Tenant, nil } func (c *tenant) createRequestFromCLI() (*apiv2.TenantServiceCreateRequest, error) { @@ -274,9 +273,9 @@ func (c *tenant) join(args []string) error { ctx, cancel := c.c.NewRequestContext() defer cancel() - resp, err := c.c.Client.Apiv2().Tenant().InviteGet(ctx, connect.NewRequest(&apiv2.TenantServiceInviteGetRequest{ + resp, err := c.c.Client.Apiv2().Tenant().InviteGet(ctx, &apiv2.TenantServiceInviteGetRequest{ Secret: secret, - })) + }) if err != nil { return fmt.Errorf("failed to get tenant invite: %w", err) } @@ -285,8 +284,8 @@ func (c *tenant) join(args []string) error { ShowAnswers: true, Message: fmt.Sprintf( "Do you want to join tenant \"%s\" as %s?", - color.GreenString(resp.Msg.GetInvite().GetTargetTenantName()), - resp.Msg.GetInvite().GetRole().String(), + color.GreenString(resp.GetInvite().GetTargetTenantName()), + resp.GetInvite().GetRole().String(), ), In: c.c.In, Out: c.c.Out, @@ -298,14 +297,14 @@ func (c *tenant) join(args []string) error { ctx2, cancel2 := c.c.NewRequestContext() defer cancel2() - acceptResp, err := c.c.Client.Apiv2().Tenant().InviteAccept(ctx2, connect.NewRequest(&apiv2.TenantServiceInviteAcceptRequest{ + acceptResp, err := c.c.Client.Apiv2().Tenant().InviteAccept(ctx2, &apiv2.TenantServiceInviteAcceptRequest{ Secret: secret, - })) + }) if err != nil { return fmt.Errorf("failed to join tenant: %w", err) } - _, _ = fmt.Fprintf(c.c.Out, "%s successfully joined tenant \"%s\"\n", color.GreenString("✔"), color.GreenString(acceptResp.Msg.TenantName)) + _, _ = fmt.Fprintf(c.c.Out, "%s successfully joined tenant \"%s\"\n", color.GreenString("✔"), color.GreenString(acceptResp.TenantName)) return nil } @@ -319,16 +318,16 @@ func (c *tenant) generateInvite() error { return err } - resp, err := c.c.Client.Apiv2().Tenant().Invite(ctx, connect.NewRequest(&apiv2.TenantServiceInviteRequest{ + resp, err := c.c.Client.Apiv2().Tenant().Invite(ctx, &apiv2.TenantServiceInviteRequest{ Login: tenant, Role: apiv2.TenantRole(apiv2.TenantRole_value[viper.GetString("role")]), - })) + }) if err != nil { return fmt.Errorf("failed to generate an invite: %w", err) } - _, _ = fmt.Fprintf(c.c.Out, "You can share this secret with the member to join, it expires in %s:\n\n", humanize.Time(resp.Msg.Invite.ExpiresAt.AsTime())) - _, _ = fmt.Fprintf(c.c.Out, "%s (https://console.metal-stack.io/organization-invite/%s)\n", resp.Msg.Invite.Secret, resp.Msg.Invite.Secret) + _, _ = fmt.Fprintf(c.c.Out, "You can share this secret with the member to join, it expires in %s:\n\n", humanize.Time(resp.Invite.ExpiresAt.AsTime())) + _, _ = fmt.Fprintf(c.c.Out, "%s (https://console.metal-stack.io/organization-invite/%s)\n", resp.Invite.Secret, resp.Invite.Secret) return nil } @@ -342,19 +341,19 @@ func (c *tenant) listInvites() error { return err } - resp, err := c.c.Client.Apiv2().Tenant().InvitesList(ctx, connect.NewRequest(&apiv2.TenantServiceInvitesListRequest{ + resp, err := c.c.Client.Apiv2().Tenant().InvitesList(ctx, &apiv2.TenantServiceInvitesListRequest{ Login: tenant, - })) + }) if err != nil { return fmt.Errorf("failed to list invites: %w", err) } - err = sorters.TenantInviteSorter().SortBy(resp.Msg.Invites) + err = sorters.TenantInviteSorter().SortBy(resp.Invites) if err != nil { return err } - return c.c.ListPrinter.Print(resp.Msg.Invites) + return c.c.ListPrinter.Print(resp.Invites) } func (c *tenant) deleteInvite(args []string) error { @@ -371,10 +370,10 @@ func (c *tenant) deleteInvite(args []string) error { ctx, cancel := c.c.NewRequestContext() defer cancel() - _, err = c.c.Client.Apiv2().Tenant().InviteDelete(ctx, connect.NewRequest(&apiv2.TenantServiceInviteDeleteRequest{ + _, err = c.c.Client.Apiv2().Tenant().InviteDelete(ctx, &apiv2.TenantServiceInviteDeleteRequest{ Login: tenant, Secret: secret, - })) + }) if err != nil { return fmt.Errorf("failed to delete invite: %w", err) } @@ -396,10 +395,10 @@ func (c *tenant) removeMember(args []string) error { ctx, cancel := c.c.NewRequestContext() defer cancel() - _, err = c.c.Client.Apiv2().Tenant().RemoveMember(ctx, connect.NewRequest(&apiv2.TenantServiceRemoveMemberRequest{ + _, err = c.c.Client.Apiv2().Tenant().RemoveMember(ctx, &apiv2.TenantServiceRemoveMemberRequest{ Login: tenant, Member: member, - })) + }) if err != nil { return fmt.Errorf("failed to remove member from tenant: %w", err) } @@ -423,16 +422,16 @@ func (c *tenant) updateMember(args []string) error { ctx, cancel := c.c.NewRequestContext() defer cancel() - resp, err := c.c.Client.Apiv2().Tenant().UpdateMember(ctx, connect.NewRequest(&apiv2.TenantServiceUpdateMemberRequest{ + resp, err := c.c.Client.Apiv2().Tenant().UpdateMember(ctx, &apiv2.TenantServiceUpdateMemberRequest{ Login: tenant, Member: member, Role: apiv2.TenantRole(apiv2.TenantRole_value[viper.GetString("role")]), - })) + }) if err != nil { return fmt.Errorf("failed to update member: %w", err) } - return c.c.DescribePrinter.Print(resp.Msg.GetTenantMember()) + return c.c.DescribePrinter.Print(resp.GetTenantMember()) } func (c *tenant) listMembers() error { @@ -444,14 +443,14 @@ func (c *tenant) listMembers() error { return err } - resp, err := c.c.Client.Apiv2().Tenant().Get(ctx, connect.NewRequest(&apiv2.TenantServiceGetRequest{ + resp, err := c.c.Client.Apiv2().Tenant().Get(ctx, &apiv2.TenantServiceGetRequest{ Login: tenant, - })) + }) if err != nil { return fmt.Errorf("failed to get tenant: %w", err) } - members := resp.Msg.GetTenantMembers() + members := resp.GetTenantMembers() if err := sorters.TenantMemberSorter().SortBy(members); err != nil { return err diff --git a/cmd/api/v1/token.go b/cmd/api/v1/token.go index 3925ff5..7ca3cc7 100644 --- a/cmd/api/v1/token.go +++ b/cmd/api/v1/token.go @@ -5,7 +5,6 @@ import ( "strings" "time" - "connectrpc.com/connect" apiv2 "github.com/metal-stack/api/go/metalstack/api/v2" "github.com/metal-stack/cli/cmd/config" "github.com/metal-stack/cli/cmd/sorters" @@ -128,12 +127,12 @@ func (c *token) Get(id string) (*apiv2.Token, error) { Uuid: id, } - resp, err := c.c.Client.Apiv2().Token().Get(ctx, connect.NewRequest(req)) + resp, err := c.c.Client.Apiv2().Token().Get(ctx, req) if err != nil { return nil, fmt.Errorf("failed to get token: %w", err) } - return resp.Msg.GetToken(), nil + return resp.GetToken(), nil } func (c *token) List() ([]*apiv2.Token, error) { @@ -142,31 +141,31 @@ func (c *token) List() ([]*apiv2.Token, error) { req := &apiv2.TokenServiceListRequest{} - resp, err := c.c.Client.Apiv2().Token().List(ctx, connect.NewRequest(req)) + resp, err := c.c.Client.Apiv2().Token().List(ctx, req) if err != nil { return nil, fmt.Errorf("failed to list tokens: %w", err) } - return resp.Msg.GetTokens(), nil + return resp.GetTokens(), nil } func (c *token) Create(rq *apiv2.TokenServiceCreateRequest) (*apiv2.Token, error) { ctx, cancel := c.c.NewRequestContext() defer cancel() - resp, err := c.c.Client.Apiv2().Token().Create(ctx, connect.NewRequest(rq)) + resp, err := c.c.Client.Apiv2().Token().Create(ctx, rq) if err != nil { return nil, err } _, _ = fmt.Fprintf(c.c.Out, "Make sure to copy your personal access token now as you will not be able to see this again.\n") _, _ = fmt.Fprintln(c.c.Out) - _, _ = fmt.Fprintln(c.c.Out, resp.Msg.GetSecret()) + _, _ = fmt.Fprintln(c.c.Out, resp.GetSecret()) _, _ = fmt.Fprintln(c.c.Out) // TODO: allow printer in metal-lib to be silenced - return resp.Msg.GetToken(), nil + return resp.GetToken(), nil } func (c *token) Delete(id string) (*apiv2.Token, error) { @@ -177,7 +176,7 @@ func (c *token) Delete(id string) (*apiv2.Token, error) { Uuid: id, } - _, err := c.c.Client.Apiv2().Token().Revoke(ctx, connect.NewRequest(req)) + _, err := c.c.Client.Apiv2().Token().Revoke(ctx, req) if err != nil { return nil, fmt.Errorf("failed to revoke token: %w", err) } @@ -191,12 +190,12 @@ func (c *token) Update(rq *apiv2.TokenServiceUpdateRequest) (*apiv2.Token, error ctx, cancel := c.c.NewRequestContext() defer cancel() - resp, err := c.c.Client.Apiv2().Token().Update(ctx, connect.NewRequest(rq)) + resp, err := c.c.Client.Apiv2().Token().Update(ctx, rq) if err != nil { return nil, fmt.Errorf("failed to update token: %w", err) } - return resp.Msg.GetToken(), nil + return resp.GetToken(), nil } func (c *token) Convert(r *apiv2.Token) (string, *apiv2.TokenServiceCreateRequest, *apiv2.TokenServiceUpdateRequest, error) { diff --git a/cmd/api/v1/user.go b/cmd/api/v1/user.go index ea34877..329944e 100644 --- a/cmd/api/v1/user.go +++ b/cmd/api/v1/user.go @@ -3,7 +3,6 @@ package v1 import ( "fmt" - "connectrpc.com/connect" 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" @@ -47,12 +46,12 @@ func (c *user) Get(id string) (*apiv2.User, error) { req := &apiv2.UserServiceGetRequest{} - resp, err := c.c.Client.Apiv2().User().Get(ctx, connect.NewRequest(req)) + resp, err := c.c.Client.Apiv2().User().Get(ctx, req) if err != nil { return nil, fmt.Errorf("failed to get user: %w", err) } - return resp.Msg.GetUser(), nil + return resp.GetUser(), nil } func (c *user) List() ([]*apiv2.User, error) { diff --git a/cmd/api/v1/version.go b/cmd/api/v1/version.go index 18605ba..c62219f 100644 --- a/cmd/api/v1/version.go +++ b/cmd/api/v1/version.go @@ -3,7 +3,6 @@ package v1 import ( "fmt" - "connectrpc.com/connect" v1 "github.com/metal-stack/api/go/metalstack/api/v2" "github.com/metal-stack/cli/cmd/config" "github.com/metal-stack/v" @@ -28,9 +27,9 @@ func newVersionCmd(c *config.Config) *cobra.Command { Client: v.V.String(), } - resp, err := c.Client.Apiv2().Version().Get(ctx, connect.NewRequest(&v1.VersionServiceGetRequest{})) + resp, err := c.Client.Apiv2().Version().Get(ctx, &v1.VersionServiceGetRequest{}) if err == nil { - v.Server = resp.Msg.Version + v.Server = resp.Version } if err := c.DescribePrinter.Print(v); err != nil { diff --git a/cmd/completion/ip.go b/cmd/completion/ip.go index 06d7241..b433db5 100644 --- a/cmd/completion/ip.go +++ b/cmd/completion/ip.go @@ -1,7 +1,6 @@ package completion import ( - "connectrpc.com/connect" apiv2 "github.com/metal-stack/api/go/metalstack/api/v2" "github.com/spf13/cobra" ) @@ -10,12 +9,12 @@ func (c *Completion) IpListCompletion(cmd *cobra.Command, args []string, toCompl req := &apiv2.IPServiceListRequest{ Project: c.Project, } - resp, err := c.Client.Apiv2().IP().List(c.Ctx, connect.NewRequest(req)) + resp, err := c.Client.Apiv2().IP().List(c.Ctx, req) if err != nil { return nil, cobra.ShellCompDirectiveError } var names []string - for _, s := range resp.Msg.Ips { + for _, s := range resp.Ips { names = append(names, s.Uuid+"\t"+s.Ip+"\t"+s.Name) } return names, cobra.ShellCompDirectiveNoFileComp diff --git a/cmd/completion/project.go b/cmd/completion/project.go index 04a063c..6acb591 100644 --- a/cmd/completion/project.go +++ b/cmd/completion/project.go @@ -1,7 +1,6 @@ package completion import ( - "connectrpc.com/connect" "github.com/spf13/cobra" apiv2 "github.com/metal-stack/api/go/metalstack/api/v2" @@ -9,13 +8,13 @@ import ( func (c *Completion) ProjectListCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { req := &apiv2.ProjectServiceListRequest{} - resp, err := c.Client.Apiv2().Project().List(c.Ctx, connect.NewRequest(req)) + resp, err := c.Client.Apiv2().Project().List(c.Ctx, req) if err != nil { return nil, cobra.ShellCompDirectiveError } var names []string - for _, s := range resp.Msg.GetProjects() { + for _, s := range resp.GetProjects() { names = append(names, s.Uuid+"\t"+s.Name) } @@ -37,16 +36,16 @@ func (c *Completion) ProjectRoleCompletion(cmd *cobra.Command, args []string, to } func (c *Completion) ProjectInviteListCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - resp, err := c.Client.Apiv2().Project().InvitesList(c.Ctx, connect.NewRequest(&apiv2.ProjectServiceInvitesListRequest{ + resp, err := c.Client.Apiv2().Project().InvitesList(c.Ctx, &apiv2.ProjectServiceInvitesListRequest{ Project: c.Project, - })) + }) if err != nil { return nil, cobra.ShellCompDirectiveError } var names []string - for _, invite := range resp.Msg.Invites { + for _, invite := range resp.Invites { names = append(names, invite.Secret+"\t"+invite.Role.String()) } @@ -54,16 +53,16 @@ func (c *Completion) ProjectInviteListCompletion(cmd *cobra.Command, args []stri } func (c *Completion) ProjectMemberListCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - resp, err := c.Client.Apiv2().Project().Get(c.Ctx, connect.NewRequest(&apiv2.ProjectServiceGetRequest{ + resp, err := c.Client.Apiv2().Project().Get(c.Ctx, &apiv2.ProjectServiceGetRequest{ Project: c.Project, - })) + }) if err != nil { return nil, cobra.ShellCompDirectiveError } var names []string - for _, member := range resp.Msg.ProjectMembers { + for _, member := range resp.ProjectMembers { names = append(names, member.Id+"\t"+member.Role.String()) } diff --git a/cmd/completion/tenant.go b/cmd/completion/tenant.go index b2de0d3..fb4e9eb 100644 --- a/cmd/completion/tenant.go +++ b/cmd/completion/tenant.go @@ -1,7 +1,6 @@ package completion import ( - "connectrpc.com/connect" adminv2 "github.com/metal-stack/api/go/metalstack/admin/v2" apiv2 "github.com/metal-stack/api/go/metalstack/api/v2" "github.com/spf13/cobra" @@ -9,13 +8,13 @@ import ( func (c *Completion) TenantListCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { req := &apiv2.TenantServiceListRequest{} - resp, err := c.Client.Apiv2().Tenant().List(c.Ctx, connect.NewRequest(req)) + resp, err := c.Client.Apiv2().Tenant().List(c.Ctx, req) if err != nil { return nil, cobra.ShellCompDirectiveError } var names []string - for _, t := range resp.Msg.Tenants { + for _, t := range resp.Tenants { names = append(names, t.Login+"\t"+t.Name) } return names, cobra.ShellCompDirectiveNoFileComp @@ -36,23 +35,23 @@ func (c *Completion) TenantRoleCompletion(cmd *cobra.Command, args []string, toC } func (c *Completion) TenantInviteListCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - projectResp, err := c.Client.Apiv2().Project().Get(c.Ctx, connect.NewRequest(&apiv2.ProjectServiceGetRequest{ + projectResp, err := c.Client.Apiv2().Project().Get(c.Ctx, &apiv2.ProjectServiceGetRequest{ Project: c.Project, - })) + }) if err != nil { return nil, cobra.ShellCompDirectiveError } - resp, err := c.Client.Apiv2().Tenant().InvitesList(c.Ctx, connect.NewRequest(&apiv2.TenantServiceInvitesListRequest{ - Login: projectResp.Msg.Project.Tenant, - })) + resp, err := c.Client.Apiv2().Tenant().InvitesList(c.Ctx, &apiv2.TenantServiceInvitesListRequest{ + Login: projectResp.Project.Tenant, + }) if err != nil { return nil, cobra.ShellCompDirectiveError } var names []string - for _, invite := range resp.Msg.Invites { + for _, invite := range resp.Invites { names = append(names, invite.Secret+"\t"+invite.Role.String()) } @@ -60,23 +59,23 @@ func (c *Completion) TenantInviteListCompletion(cmd *cobra.Command, args []strin } func (c *Completion) TenantMemberListCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - projectResp, err := c.Client.Apiv2().Project().Get(c.Ctx, connect.NewRequest(&apiv2.ProjectServiceGetRequest{ + projectResp, err := c.Client.Apiv2().Project().Get(c.Ctx, &apiv2.ProjectServiceGetRequest{ Project: c.Project, - })) + }) if err != nil { return nil, cobra.ShellCompDirectiveError } - resp, err := c.Client.Apiv2().Tenant().Get(c.Ctx, connect.NewRequest(&apiv2.TenantServiceGetRequest{ - Login: projectResp.Msg.Project.Tenant, - })) + resp, err := c.Client.Apiv2().Tenant().Get(c.Ctx, &apiv2.TenantServiceGetRequest{ + Login: projectResp.Project.Tenant, + }) if err != nil { return nil, cobra.ShellCompDirectiveError } var names []string - for _, member := range resp.Msg.TenantMembers { + for _, member := range resp.TenantMembers { names = append(names, member.Id+"\t"+member.Role.String()) } @@ -85,12 +84,12 @@ func (c *Completion) TenantMemberListCompletion(cmd *cobra.Command, args []strin func (c *Completion) AdminTenantListCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { req := &adminv2.TenantServiceListRequest{} - resp, err := c.Client.Adminv2().Tenant().List(c.Ctx, connect.NewRequest(req)) + resp, err := c.Client.Adminv2().Tenant().List(c.Ctx, req) if err != nil { return nil, cobra.ShellCompDirectiveError } var names []string - for _, s := range resp.Msg.Tenants { + for _, s := range resp.Tenants { names = append(names, s.Login+"\t"+s.Name) } return names, cobra.ShellCompDirectiveNoFileComp diff --git a/cmd/completion/token.go b/cmd/completion/token.go index 3571a32..b7498f5 100644 --- a/cmd/completion/token.go +++ b/cmd/completion/token.go @@ -4,7 +4,6 @@ import ( "fmt" "strings" - "connectrpc.com/connect" "github.com/spf13/cobra" apiv2 "github.com/metal-stack/api/go/metalstack/api/v2" @@ -12,13 +11,13 @@ import ( func (c *Completion) TokenListCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { req := &apiv2.TokenServiceListRequest{} - resp, err := c.Client.Apiv2().Token().List(c.Ctx, connect.NewRequest(req)) + resp, err := c.Client.Apiv2().Token().List(c.Ctx, req) if err != nil { return nil, cobra.ShellCompDirectiveError } var names []string - for _, s := range resp.Msg.Tokens { + for _, s := range resp.Tokens { fmt.Println(s.Uuid) names = append(names, s.Uuid+"\t"+s.Description) } @@ -27,14 +26,14 @@ func (c *Completion) TokenListCompletion(cmd *cobra.Command, args []string, toCo } func (c *Completion) TokenProjectRolesCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - methods, err := c.Client.Apiv2().Method().TokenScopedList(c.Ctx, connect.NewRequest(&apiv2.MethodServiceTokenScopedListRequest{})) + methods, err := c.Client.Apiv2().Method().TokenScopedList(c.Ctx, &apiv2.MethodServiceTokenScopedListRequest{}) if err != nil { return nil, cobra.ShellCompDirectiveError } var roles []string - for project, role := range methods.Msg.ProjectRoles { + for project, role := range methods.ProjectRoles { roles = append(roles, project+"="+role.String()) } @@ -42,14 +41,14 @@ func (c *Completion) TokenProjectRolesCompletion(cmd *cobra.Command, args []stri } func (c *Completion) TokenTenantRolesCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - methods, err := c.Client.Apiv2().Method().TokenScopedList(c.Ctx, connect.NewRequest(&apiv2.MethodServiceTokenScopedListRequest{})) + methods, err := c.Client.Apiv2().Method().TokenScopedList(c.Ctx, &apiv2.MethodServiceTokenScopedListRequest{}) if err != nil { return nil, cobra.ShellCompDirectiveError } var roles []string - for tenant, role := range methods.Msg.TenantRoles { + for tenant, role := range methods.TenantRoles { roles = append(roles, tenant+"="+role.String()) } @@ -67,7 +66,7 @@ func (c *Completion) TokenAdminRoleCompletion(cmd *cobra.Command, args []string, } func (c *Completion) TokenPermissionsCompletionfunc(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - methods, err := c.Client.Apiv2().Method().TokenScopedList(c.Ctx, connect.NewRequest(&apiv2.MethodServiceTokenScopedListRequest{})) + methods, err := c.Client.Apiv2().Method().TokenScopedList(c.Ctx, &apiv2.MethodServiceTokenScopedListRequest{}) if err != nil { return nil, cobra.ShellCompDirectiveError } @@ -80,7 +79,7 @@ func (c *Completion) TokenPermissionsCompletionfunc(cmd *cobra.Command, args []s if subject == "" { var perms []string - for _, p := range methods.Msg.Permissions { + for _, p := range methods.Permissions { perms = append(perms, p.Subject) } @@ -91,7 +90,7 @@ func (c *Completion) TokenPermissionsCompletionfunc(cmd *cobra.Command, args []s var perms []string - for _, p := range methods.Msg.Permissions { + for _, p := range methods.Permissions { perms = append(perms, p.Methods...) } diff --git a/cmd/config/config.go b/cmd/config/config.go index 965542b..67006b9 100644 --- a/cmd/config/config.go +++ b/cmd/config/config.go @@ -8,7 +8,6 @@ import ( "path" "time" - "connectrpc.com/connect" "github.com/metal-stack/api/go/client" "github.com/metal-stack/cli/cmd/completion" "github.com/metal-stack/metal-lib/pkg/genericcli/printers" @@ -92,14 +91,14 @@ func (c *Config) GetTenant() (string, error) { ctx, cancel := c.NewRequestContext() defer cancel() - projectResp, err := c.Client.Apiv2().Project().Get(ctx, connect.NewRequest(&apiv2.ProjectServiceGetRequest{ + projectResp, err := c.Client.Apiv2().Project().Get(ctx, &apiv2.ProjectServiceGetRequest{ Project: c.GetProject(), - })) + }) if err != nil { return "", fmt.Errorf("unable to derive tenant from project: %w", err) } - return projectResp.Msg.Project.Tenant, nil + return projectResp.Project.Tenant, nil } func (c *Config) GetToken() string { diff --git a/cmd/login.go b/cmd/login.go index 1a44670..739d77d 100644 --- a/cmd/login.go +++ b/cmd/login.go @@ -9,7 +9,6 @@ import ( "os/exec" "time" - "connectrpc.com/connect" "github.com/fatih/color" apiv2 "github.com/metal-stack/api/go/metalstack/api/v2" "github.com/metal-stack/cli/cmd/config" @@ -129,16 +128,16 @@ func (l *login) login() error { return err } - tokenResp, err := mc.Apiv2().Token().Create(context.Background(), connect.NewRequest(&apiv2.TokenServiceCreateRequest{ + tokenResp, err := mc.Apiv2().Token().Create(context.Background(), &apiv2.TokenServiceCreateRequest{ Description: "admin access issues by metal cli", Expires: durationpb.New(3 * time.Hour), AdminRole: pointer.Pointer(apiv2.AdminRole((apiv2.AdminRole_value[viper.GetString("admin-role")]))), - })) + }) if err != nil { return fmt.Errorf("unable to issue admin token: %w", err) } - token = tokenResp.Msg.Secret + token = tokenResp.Secret } ctx.Token = token @@ -149,13 +148,13 @@ func (l *login) login() error { return err } - projects, err := mc.Apiv2().Project().List(context.Background(), connect.NewRequest(&apiv2.ProjectServiceListRequest{})) + projects, err := mc.Apiv2().Project().List(context.Background(), &apiv2.ProjectServiceListRequest{}) if err != nil { return fmt.Errorf("unable to retrieve project list: %w", err) } - if len(projects.Msg.Projects) > 0 { - ctx.DefaultProject = projects.Msg.Projects[0].Uuid + if len(projects.Projects) > 0 { + ctx.DefaultProject = projects.Projects[0].Uuid } }