feat: use auth token with all client commands

This commit is contained in:
wpetit 2023-03-08 19:42:40 +01:00
parent 9aca9a6c58
commit a297821f3c
4 changed files with 20 additions and 4 deletions

2
go.mod
View File

@ -16,6 +16,7 @@ require (
github.com/jackc/pgx/v5 v5.3.1 github.com/jackc/pgx/v5 v5.3.1
github.com/jedib0t/go-pretty/v6 v6.4.4 github.com/jedib0t/go-pretty/v6 v6.4.4
github.com/lestrrat-go/jwx/v2 v2.0.8 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/mitchellh/mapstructure v1.5.0
github.com/pkg/errors v0.9.1 github.com/pkg/errors v0.9.1
github.com/qri-io/jsonschema v0.2.1 github.com/qri-io/jsonschema v0.2.1
@ -36,7 +37,6 @@ require (
github.com/gorilla/websocket v1.5.0 // indirect github.com/gorilla/websocket v1.5.0 // indirect
github.com/hashicorp/mdns v1.0.5 // indirect github.com/hashicorp/mdns v1.0.5 // indirect
github.com/igm/sockjs-go/v3 v3.0.2 // 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/miekg/dns v1.1.51 // indirect
github.com/oklog/ulid/v2 v2.1.0 // indirect github.com/oklog/ulid/v2 v2.1.0 // indirect
github.com/orcaman/concurrent-map v1.0.0 // indirect github.com/orcaman/concurrent-map v1.0.0 // indirect

View File

@ -18,7 +18,13 @@ func CountCommand() *cli.Command {
Flags: clientFlag.ComposeFlags(), Flags: clientFlag.ComposeFlags(),
Action: func(ctx *cli.Context) error { Action: func(ctx *cli.Context) error {
baseFlags := clientFlag.GetBaseFlags(ctx) 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) _, total, err := client.QueryAgents(ctx.Context)
if err != nil { if err != nil {

View File

@ -24,7 +24,12 @@ func GetCommand() *cli.Command {
return errors.WithStack(err) 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) specs, err := client.GetAgentSpecs(ctx.Context, agentID)
if err != nil { if err != nil {

View File

@ -61,7 +61,12 @@ func UpdateCommand() *cli.Command {
noPatch := ctx.Bool("no-patch") 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) specs, err := client.GetAgentSpecs(ctx.Context, agentID)
if err != nil { if err != nil {