Skip to content
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

Add PINNIPED_SKIP_PRINT_LOGIN_URL env var to CLI #1897

Merged
merged 2 commits into from
Mar 15, 2024

Conversation

cfryanr
Copy link
Member

@cfryanr cfryanr commented Mar 14, 2024

The approach taken in #1874 to attempt to solve #1868 did not work as well as I had hoped.

This PR removes some of the code from #1874 and replaces it with a new env var used by the CLI called PINNIPED_SKIP_PRINT_LOGIN_URL, which causes the CLI to skip printing the login URL to stderr when the env car is set to true and when the browser was opened to the login URL.

For example, you could use PINNIPED_SKIP_PRINT_LOGIN_URL=true k9s --kubeconfig pinniped-browser-flow-kubeconfig.yaml to start k9s.

Release note:

The `pinniped login oidc` CLI command will skip printing the login URL to stderr if the browser has successfully opened and if the `PINNIPED_SKIP_PRINT_LOGIN_URL` env var is set to `true`. This new env var can be used to avoid having the URL output on stdout confuse console UIs like k9s.

Copy link

codecov bot commented Mar 14, 2024

Codecov Report

Attention: Patch coverage is 58.33333% with 5 lines in your changes are missing coverage. Please review.

Project coverage is 38.25%. Comparing base (15627e7) to head (92a082b).

Files Patch % Lines
pkg/oidcclient/login.go 16.66% 5 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1897   +/-   ##
=======================================
  Coverage   38.25%   38.25%           
=======================================
  Files         347      347           
  Lines       44200    44207    +7     
=======================================
+ Hits        16907    16910    +3     
- Misses      26780    26785    +5     
+ Partials      513      512    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@joshuatcasey
Copy link
Member

Could this be a pinniped CLI argument, so that it could be baked into a kubeconfig? Would we want that? I guess the same kubeconfig would be used for both kubectl and k9s, so that isn't really desirable.

debugEnvVarName = "PINNIPED_DEBUG"

// The value to use for true/false env vars to enable the behavior caused by the env var.
envVarTruthyValue = "true"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we relax this a bit to allow for True or TRUE? The following func should only return true for a very limited number of values as per https://gosamples.dev/string-to-bool/. We could still document using true but this allows for variations.

func isTruthyString(s string) bool {
	b, err := strconv.ParseBool(s)
	return err == nil && b
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do that if you'd like. I was copying the style used by the existing PINNIPED_DEBUG env var which is either true or anything else is considered not true.

@cfryanr
Copy link
Member Author

cfryanr commented Mar 15, 2024

Could this be a pinniped CLI argument, so that it could be baked into a kubeconfig? Would we want that? I guess the same kubeconfig would be used for both kubectl and k9s, so that isn't really desirable.

It could be a flag. The community member who reported this problem suggested that as a solution. However, I was thinking the same thing that you mentioned about the same kubeconfig being used for both purposes, which is why I thought maybe it should be an env var.

If a user wanted to hardcode this value into their kubeconfig, they can still do so, because you can put env var names and values into the kubeconfig (see https://kubernetes.io/docs/reference/access-authn-authz/authentication/#configuration).

@cfryanr cfryanr merged commit 6307a32 into main Mar 15, 2024
40 checks passed
@cfryanr cfryanr deleted the cli_skip_print_url_env_var branch March 15, 2024 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants