Skip to content

Commit

Permalink
feat: add auth print-access-token command
Browse files Browse the repository at this point in the history
This is a convenience function to print the API client access token to
stdout. Mainly useful when testing things on the API with curl and maybe
some scriping use-cases.
  • Loading branch information
ctrox committed Jun 5, 2024
1 parent 542610b commit 4c84e4b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
15 changes: 8 additions & 7 deletions auth/auth.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package auth

type Cmd struct {
Login LoginCmd `cmd:"" help:"Login to nineapis.ch."`
Logout LogoutCmd `cmd:"" help:"Logout from nineapis.ch."`
Cluster ClusterCmd `cmd:"" help:"Authenticate with Kubernetes Cluster."`
OIDC OIDCCmd `cmd:"" help:"Perform interactive OIDC login." hidden:""`
SetProject SetProjectCmd `cmd:"" help:"Set the default project to be used."`
SetOrg SetOrgCmd `cmd:"" help:"Set the organization to be used."`
Whoami WhoAmICmd `cmd:"" help:"Show who you are logged in as, your active organization and all your available organizations."`
Login LoginCmd `cmd:"" help:"Login to nineapis.ch."`
Logout LogoutCmd `cmd:"" help:"Logout from nineapis.ch."`
Cluster ClusterCmd `cmd:"" help:"Authenticate with Kubernetes Cluster."`
OIDC OIDCCmd `cmd:"" help:"Perform interactive OIDC login." hidden:""`
SetProject SetProjectCmd `cmd:"" help:"Set the default project to be used."`
SetOrg SetOrgCmd `cmd:"" help:"Set the organization to be used."`
Whoami WhoAmICmd `cmd:"" help:"Show who you are logged in as, your active organization and all your available organizations."`
PrintAccessToken PrintAccessTokenCmd `cmd:"" help:"Print short-lived access token to authenticate against the API to stdout and exit."`
}
15 changes: 15 additions & 0 deletions auth/print_access_token.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package auth

import (
"context"
"fmt"

"github.com/ninech/nctl/api"
)

type PrintAccessTokenCmd struct{}

func (o *PrintAccessTokenCmd) Run(ctx context.Context, client *api.Client) error {
fmt.Println(client.Token)
return nil
}

0 comments on commit 4c84e4b

Please sign in to comment.