Repository navigation
feat: support environment name abbreviations for --env flag #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,7 +55,7 @@ var CredentialStoreFlags = []cli.Flag{ | |
| }, | ||
| &cli.StringFlag{ | ||
| Name: backendFlagName, | ||
| Usage: "Pin credential storage to a specific system backend (see `lfx auth backends`); mutually exclusive with --insecure-storage", | ||
| Usage: "Pin credential storage to a specific system backend (see 'lfx auth backends'); mutually exclusive with --insecure-storage", | ||
| }, | ||
| } | ||
|
|
||
|
|
@@ -84,6 +84,7 @@ func NewAuthCommand() *cli.Command { | |
| newAuthStatusCommand(), | ||
| newAuthLogoutCommand(), | ||
| newAuthBackendsCommand(), | ||
| newAuthEnvironmentsCommand(), | ||
| }, | ||
| } | ||
| } | ||
|
|
@@ -116,12 +117,12 @@ func newAuthLoginCommand() *cli.Command { | |
| }, | ||
| &cli.StringFlag{ | ||
| Name: envFlagName, | ||
| Usage: "Target environment: prod, staging, or development", | ||
| Value: string(envProd), | ||
| Usage: "Target environment; see 'lfx auth environments' for accepted values", | ||
| Value: string(envProduction), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [question] New logins persist "production", which released v1.0.x binaries reject Issue: The renamed constant is also the value saved to Proof: Why it matters: Downgrading, or running a v1.0.x binary alongside this build against the same state dir, breaks Fix: If downgrade compatibility matters, keep writing the legacy production value ( |
||
| }, | ||
| &cli.StringFlag{ | ||
| Name: audienceFlagName, | ||
| Usage: "Auth0 API audience to request tokens for (defaults to the selected environment's LFX API audience)", | ||
| Usage: "Auth0 API audience to request tokens for; defaults to --env's audience (see 'lfx auth environments')", | ||
| }, | ||
| }, | ||
| Action: runAuthLogin, | ||
|
|
@@ -134,7 +135,7 @@ func runAuthLogin(ctx context.Context, cmd *cli.Command) error { | |
| return err | ||
| } | ||
|
|
||
| env := authEnvironment(cmd.String(envFlagName)) | ||
| env := normalizeEnvironment(cmd.String(envFlagName)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [minor] No test exercises alias handling through Issue: This is the only place aliases are applied to user input. The new tests cover Proof: No Why it matters: Accepting aliases in Fix: Table-test a root command ( |
||
| domain, clientID, err := resolveEnvironment(env) | ||
| if err != nil { | ||
| return err | ||
|
|
@@ -336,7 +337,7 @@ func loadDeviceStateForBackend(store credstore.Store, cmd *cli.Command) (state c | |
| ) | ||
| } | ||
|
|
||
| domain, clientID, err = resolveEnvironment(authEnvironment(state.Environment)) | ||
| domain, clientID, err = resolveEnvironment(normalizeEnvironment(state.Environment)) | ||
| if err != nil { | ||
| return credstore.DeviceState{}, "", "", err | ||
| } | ||
|
|
@@ -488,7 +489,7 @@ func resolveAccessToken(ctx context.Context, cmd *cli.Command) (token, audience | |
| } | ||
|
|
||
| if creds.ValidAccessToken() { | ||
| return creds.AccessToken, state.Audience, authEnvironment(state.Environment), nil | ||
| return creds.AccessToken, state.Audience, normalizeEnvironment(state.Environment), nil | ||
| } | ||
|
|
||
| if creds.RefreshToken == "" { | ||
|
|
@@ -527,7 +528,7 @@ func resolveAccessToken(ctx context.Context, cmd *cli.Command) (token, audience | |
| return "", "", "", fmt.Errorf("save refreshed credentials: %w", err) | ||
| } | ||
|
|
||
| return refreshed.AccessToken, state.Audience, authEnvironment(state.Environment), nil | ||
| return refreshed.AccessToken, state.Audience, normalizeEnvironment(state.Environment), nil | ||
| } | ||
|
|
||
| func newAuthStatusCommand() *cli.Command { | ||
|
|
@@ -563,7 +564,7 @@ func newAuthStatusCommand() *cli.Command { | |
| ) | ||
| } | ||
| if state.Environment != "" { | ||
| fmt.Printf(" %-22s %s\n", "Environment:", state.Environment) | ||
| fmt.Printf(" %-22s %s\n", "Environment:", normalizeEnvironment(state.Environment)) | ||
| } | ||
| if state.IDPDomain != "" { | ||
| fmt.Printf(" %-22s %s\n", "IdP domain:", state.IDPDomain) | ||
|
|
@@ -680,6 +681,31 @@ func newAuthBackendsCommand() *cli.Command { | |
| } | ||
| } | ||
|
|
||
| // newAuthEnvironmentsCommand builds `lfx auth environments`, which lists | ||
| // every canonical --env value accepted by `lfx auth login`, along with | ||
| // its aliases and default API audience. Kept out of --env's own usage | ||
| // text (and out of the main help listing, aside from the command itself) | ||
| // to keep that terser; full detail lives here for anyone who needs to | ||
| // look it up. | ||
| func newAuthEnvironmentsCommand() *cli.Command { | ||
| return &cli.Command{ | ||
| Name: "environments", | ||
| Usage: "List --env values accepted by `lfx auth login`, including aliases and default audiences", | ||
|
emsearcy marked this conversation as resolved.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nit] Use single quotes in the environments command Usage, like the rest of the help text Issue: This PR switched flag Usage that names a command to single quotes ( Proof: Flag Usage runs through urfave/cli's Why it matters: Help output mixes quoting styles for the same kind of command reference. No behavioral break; consistency only. Fix: |
||
| Action: func(_ context.Context, _ *cli.Command) error { | ||
| fmt.Println("Accepted --env values:") | ||
| for _, env := range []authEnvironment{envProduction, envStaging, envDevelopment} { | ||
| line := " " + string(env) | ||
| if aliases := environmentAliases(env); len(aliases) > 0 { | ||
| line += fmt.Sprintf(" (aliases: %s)", strings.Join(aliases, ", ")) | ||
| } | ||
| fmt.Println(line) | ||
| fmt.Printf(" default audience: %s\n", defaultAudiences[env]) | ||
| } | ||
| return nil | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| // lfidClaimsNamespace prefixes the custom LFID claims Auth0 adds to the ID | ||
| // token, namely username. Distinct from the shorter "http://lfx.dev/claims" | ||
| // LFX claims namespace used elsewhere. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] Show canonical --env names in the README and point to
lfx auth environmentsIssue: The staging example leads with the canonical name; the development example leads with the alias
devand listsdevelopmentunder "also". The README also never mentions the newlfx auth environmentscommand, even though--backendalready points atlfx auth backends.Proof: Canonical names are
production/staging/development(environment.go:21-25). Afterlfx auth login --env dev,auth statusprintsEnvironment: developmentbecause login persists the normalized value. AGENTS.md asks to update the README for user-facing changes.Why it matters: The README teaches an alias as the primary spelling, which fights this PR's move to full-word canonical names and what
auth status/auth environmentsprint.Fix: Lead with the canonical names and point at the new command, e.g.