Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnester committed Mar 25, 2024
1 parent d560094 commit c56cb6e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
23 changes: 15 additions & 8 deletions cmd/auth/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down Expand Up @@ -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
}
7 changes: 6 additions & 1 deletion cmd/root/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand Down

0 comments on commit c56cb6e

Please sign in to comment.