From a297821f3c6468f79a9cbd3909e3e6bb268d60c5 Mon Sep 17 00:00:00 2001 From: William Petit Date: Wed, 8 Mar 2023 19:42:40 +0100 Subject: [PATCH] feat: use auth token with all client commands --- go.mod | 2 +- internal/command/client/agent/count.go | 8 +++++++- internal/command/client/agent/spec/get.go | 7 ++++++- internal/command/client/agent/spec/update.go | 7 ++++++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 68670d3..e4ebd4d 100644 --- a/go.mod +++ b/go.mod @@ -16,6 +16,7 @@ require ( github.com/jackc/pgx/v5 v5.3.1 github.com/jedib0t/go-pretty/v6 v6.4.4 github.com/lestrrat-go/jwx/v2 v2.0.8 + github.com/lithammer/shortuuid/v4 v4.0.0 github.com/mitchellh/mapstructure v1.5.0 github.com/pkg/errors v0.9.1 github.com/qri-io/jsonschema v0.2.1 @@ -36,7 +37,6 @@ require ( github.com/gorilla/websocket v1.5.0 // indirect github.com/hashicorp/mdns v1.0.5 // indirect github.com/igm/sockjs-go/v3 v3.0.2 // indirect - github.com/lithammer/shortuuid/v4 v4.0.0 // indirect github.com/miekg/dns v1.1.51 // indirect github.com/oklog/ulid/v2 v2.1.0 // indirect github.com/orcaman/concurrent-map v1.0.0 // indirect diff --git a/internal/command/client/agent/count.go b/internal/command/client/agent/count.go index a9723d0..b093866 100644 --- a/internal/command/client/agent/count.go +++ b/internal/command/client/agent/count.go @@ -18,7 +18,13 @@ func CountCommand() *cli.Command { Flags: clientFlag.ComposeFlags(), Action: func(ctx *cli.Context) error { baseFlags := clientFlag.GetBaseFlags(ctx) - client := client.New(baseFlags.ServerURL) + + token, err := clientFlag.GetToken(baseFlags) + if err != nil { + return errors.WithStack(apierr.Wrap(err)) + } + + client := client.New(baseFlags.ServerURL, client.WithToken(token)) _, total, err := client.QueryAgents(ctx.Context) if err != nil { diff --git a/internal/command/client/agent/spec/get.go b/internal/command/client/agent/spec/get.go index 2fae053..8275e02 100644 --- a/internal/command/client/agent/spec/get.go +++ b/internal/command/client/agent/spec/get.go @@ -24,7 +24,12 @@ func GetCommand() *cli.Command { return errors.WithStack(err) } - client := client.New(baseFlags.ServerURL) + token, err := clientFlag.GetToken(baseFlags) + if err != nil { + return errors.WithStack(apierr.Wrap(err)) + } + + client := client.New(baseFlags.ServerURL, client.WithToken(token)) specs, err := client.GetAgentSpecs(ctx.Context, agentID) if err != nil { diff --git a/internal/command/client/agent/spec/update.go b/internal/command/client/agent/spec/update.go index 312a001..6b31b3f 100644 --- a/internal/command/client/agent/spec/update.go +++ b/internal/command/client/agent/spec/update.go @@ -61,7 +61,12 @@ func UpdateCommand() *cli.Command { noPatch := ctx.Bool("no-patch") - client := client.New(baseFlags.ServerURL) + token, err := clientFlag.GetToken(baseFlags) + if err != nil { + return errors.WithStack(apierr.Wrap(err)) + } + + client := client.New(baseFlags.ServerURL, client.WithToken(token)) specs, err := client.GetAgentSpecs(ctx.Context, agentID) if err != nil {