From c56cb6ee96145fb53a737fe6a5ed871cd73c79fc Mon Sep 17 00:00:00 2001 From: Andrew Nester Date: Mon, 25 Mar 2024 15:35:40 +0100 Subject: [PATCH] fixes --- cmd/auth/describe.go | 23 +++++++++++++++-------- cmd/root/auth.go | 7 ++++++- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/cmd/auth/describe.go b/cmd/auth/describe.go index 442b1541d2..ceceb55c5c 100644 --- a/cmd/auth/describe.go +++ b/cmd/auth/describe.go @@ -12,24 +12,22 @@ import ( "github.com/spf13/cobra" ) -var authTemplate = fmt.Sprintf(`{{"Workspace:" | bold}} {{.Details.Host}}. +var authTemplate = `{{"Workspace:" | bold}} {{.Details.Host}}. {{if .Username }}{{"User:" | bold}} {{.Username}}.{{end}} {{"Authenticated with:" | bold}} {{.Details.AuthType}} {{if .AccountID }}{{"Account ID:" | bold}} {{.AccountID}}.{{end}} ----- -%s -`, configurationTemplate) +` + configurationTemplate -var errorTemplate = fmt.Sprintf(`Unable to authenticate: {{.Error}} +var errorTemplate = `Unable to authenticate: {{.Error}} ----- -%s -`, configurationTemplate) +` + configurationTemplate const configurationTemplate = `Configuration: {{- $details := .Details}} {{- range $k, $v := $details.Configuration }} - {{if $v.AuthTypeMismatch}}x{{else}}✓{{end}} {{$k | bold}}: {{$v.Value}} - {{- if $v.Source }} + {{if $v.AuthTypeMismatch}}~{{else}}✓{{end}} {{$k | bold}}: {{$v.Value}} + {{- if and (not (eq $v.Source.String "dynamic configuration")) $v.Source }} {{- " (from" | italic}} {{$v.Source.String | italic}} {{- if $v.AuthTypeMismatch}}, {{ "not used for auth type " | red | italic }}{{$details.AuthType | red | italic}}{{end}}) {{- end}} @@ -169,5 +167,14 @@ func getAuthDetails(cmd *cobra.Command, cfg *config.Config, showSensitive bool) } } + // If profile is not set explicitly, default to "default" + if _, ok := details.Configuration["profile"]; !ok { + profile := cfg.Profile + if profile == "" { + profile = "default" + } + details.Configuration["profile"] = &config.AttrConfig{Value: profile, Source: config.Source{Type: config.SourceDynamicConfig}} + } + return details } diff --git a/cmd/root/auth.go b/cmd/root/auth.go index 9f3d6c492f..0f07114139 100644 --- a/cmd/root/auth.go +++ b/cmd/root/auth.go @@ -78,6 +78,10 @@ func MustAccountClient(cmd *cobra.Command, args []string) error { cfg.Profile = profile } + ctx := cmd.Context() + ctx = context.WithValue(ctx, &configUsed, cfg) + cmd.SetContext(ctx) + if cfg.Profile == "" { // account-level CLI was not really done before, so here are the assumptions: // 1. only admins will have account configured @@ -100,7 +104,8 @@ func MustAccountClient(cmd *cobra.Command, args []string) error { return err } - cmd.SetContext(context.WithValue(cmd.Context(), &accountClient, a)) + ctx = context.WithValue(ctx, &accountClient, a) + cmd.SetContext(ctx) return nil }