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

Support exploring non-default KV stores #27

Merged
merged 1 commit into from
Jan 22, 2024

Conversation

kate-goldenring
Copy link
Contributor

@kate-goldenring kate-goldenring commented Dec 29, 2023

Supports exploring non-default KV stores by adding a top level field to specify the label of which store to explore
Stores the user/pass credentials in the app config store instead of in the "default" KV store

image

Draft as there is currently an issue getting the template to work with variables << Thanks @itowlson!

Thank you @karthik2804 for help with the UI!!

To test it, follow updated README instructions

Associated template updates: #28

@kate-goldenring kate-goldenring marked this pull request as ready for review January 3, 2024 02:46
@kate-goldenring
Copy link
Contributor Author

@karthik2804 @radu-matei @calebschoepp, I do not have the permissions in this repo to add reviewers, but your reviews would be helpful given your previous work in the repo.

@karthik2804 and i discussed how in the future we may want one "explorer" for all resources (KV and SQL). For now, this gets KV to links parity

explorer/main.go Outdated
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprintf(w, "KV explorer credentials not configured.\n")
// Log more informative error in cloud logs
fmt.Printf("Error getting KV explorer credentials from config store: %v\n", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this line will be printed twice. Once within the GetCredentials function and the bubbled-up error handling here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't sure about this one. I see the second line as a log, but logging doesn't work right now for Go, so instead i used a print. The first i see as additional context to the error. If we just do one, I'd prefer the second, since sometime the error is captured by the front end and never displayed in cloud logs.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was trying to point at line 76 and then line 239. I also just noticed that the error message would be of the form:

Error getting KV explorer credentials from config store: cannot get credentials pair from config store: {some_err}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! Removed the line to avoid the error duplication

explorer/main.go Outdated
if err != nil {
return "", "", fmt.Errorf("cannot get credentials pair from store: %v", err)
fmt.Printf("ERROR: cannot get credentials pair from config store: %v\n", err)
fmt.Printf("Set the 'kv_explorer_user' and 'kv_explorer_password' variables using 'spin cloud variables set'.\n")
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: could this potentially be confusing to local spin users?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are logs. They are displayed in the cloud logs not in the UI. The error is caught in the front end and the associated message is here: https://github.com/kate-goldenring/spin-kv-explorer/blob/d8b666365e72552dc3734f3f5bba48f6461810a4/explorer/index.html#L314-L315:

alert(`Access denied to store with label "${storeLabel}." Ensure the app is linked to the store with this label and that the label has been specified in the Spin manifest (spin.toml).`);

Copy link

Choose a reason for hiding this comment

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

They'll be printed to the local console under spin up though won't they?

Copy link
Contributor

Choose a reason for hiding this comment

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

As @itowlson points out, that is part of the local spin I was trying to point at.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see -- that's a great point. I was hyper focused on the Cloud scenario. Are you suggesting we remove this line? :

fmt.Printf("Set the 'kv_explorer_user' and 'kv_explorer_password' variables using 'spin cloud variables set'.\n")

Copy link
Member

@radu-matei radu-matei Jan 5, 2024

Choose a reason for hiding this comment

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

Suggestion:

"The [correct variables] for the application are not set. For local testing, you can disable authentication using the [skip auth variable], or set them in you application using [link to setting app variables for all scenarios running Spin]"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the log to give directions for both local and deployed apps:

The 'kv_explorer_user' and 'kv_explorer_password' variables for the application are not set. For deployed applications, set the variables using 'spin cloud variables set'. For local development, you can disable authentication using '--env SPIN_APP_KV_SKIP_AUTH=1' or set them in the application using runtime configuration (https://developer.fermyon.com/spin/v2/dynamic-configuration#application-variables-runtime-configuration)

@radu-matei
Copy link
Member

radu-matei commented Jan 4, 2024

@kate-goldenring the engineering team on GH should now have write access to the repo (that was an oversight when we moved the repo recently), so you should be able to add reviewers.

readme.md Show resolved Hide resolved
@radu-matei
Copy link
Member

radu-matei commented Jan 10, 2024

Not sure it's caused by this PR, but I'm noticing it's not impossible to skip checking the auth when running locally — so we either want to remove it (and update the docs), or decide if it's still valuable?

Signed-off-by: Kate Goldenring <kate.goldenring@fermyon.com>
@kate-goldenring
Copy link
Contributor Author

Not sure it's caused by this PR, but I'm noticing it's not impossible to skip checking the auth when running locally — so we either want to remove it (and update the docs), or decide if it's still valuable?

@radu, it was caused by this PR. Thanks for catching that. Just pushed a fix

@radu-matei radu-matei merged commit 578f014 into fermyon:main Jan 22, 2024
1 check passed
@kate-goldenring kate-goldenring deleted the explore-store-by-label branch January 22, 2024 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants