From 4c84e4bce7f0466c6db57ff3a48754e3fba862d6 Mon Sep 17 00:00:00 2001 From: Cyrill Troxler Date: Wed, 5 Jun 2024 13:08:14 +0200 Subject: [PATCH] feat: add auth print-access-token command 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. --- auth/auth.go | 15 ++++++++------- auth/print_access_token.go | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 auth/print_access_token.go diff --git a/auth/auth.go b/auth/auth.go index a1603bd..9e0dd26 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -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."` } diff --git a/auth/print_access_token.go b/auth/print_access_token.go new file mode 100644 index 0000000..7cc6c16 --- /dev/null +++ b/auth/print_access_token.go @@ -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 +}