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 token entry/storage functionality to test console #7

Merged
merged 21 commits into from
Jul 16, 2024
Merged

Conversation

efixler
Copy link

@efixler efixler commented Jul 15, 2024

This PR:

  1. Adds the ability to enter a token into the scrape test console
  • The token entry widget only appears when the server is running with authentication enabled
  1. Lets the user save the token to local storage, and loads that token on page load if present. This is here to make managing the tokens and using the test console less of a hassle.
  2. Makes the page generally more responsive and with a more coherent box model, following on the updates in Refactor test console ahead of upcoming auth changes #6

NB: There are still no material changes to auth behavior in this PR. IOW, The server will still supply a short-lived token to auth the test console when auth is enabled. I'll be addressing that in the next PR, there were enough changes here that I wanted to keep that behavior separate, and focus on the frontend changes here.

Decisions and Requested Feedback

In general, I think the additions here are pretty slick ( ;) ) and I'm happy both to see a more modern HTML structure and for myself to get better versed in flexbox and such. That said, the CSS in particular seems a little more ungainly in this rev I'm happy for any suggestions on making that and the page structure generally, leaner.

Also [within the boundaries of things that are easy to accomplish] would love UX feedback.

Steps to Test

The things to test here are mainly that the form, and especially the new addition for tokens, works and seems comprehensible. (Note that you'll still get a pre-populated token in this release, which will be dropped in the next PR; so you can test the operations, but just keep in mind that in the future that will be blank)

The html for this page can be viewed and interacted with pretty well by just opening the index.html file in your browser. Form submissions obviously won't work, but testing without a running server can cover the important bases. So, if you can't run the server, you can still review the code and most of the UX without doing that.

If you're executed a full test with the server: Since the test console will only show the new token entry widget when authentication is enabled, and as authentication is enabled on startup, you'll need to start the server two different ways to get a full and comprehensive test.

Building this PR

  • Check out the branch

Without Go on your machine

  • In the branch root:
    • make docker-build

With Go 1.22.x on your machine

  • In the branch root:
    • make

Authentication Disabled

In this case, you're just verifying that the server still works and that there's no token management artifacts visible here. The only visible changes here are that the url entry field is now responsive, and there's a border around the form.

Starting the server

Docker: make docker-run
Binary: ./build/scrape-server

Testing

Enter a url in the url entry field and Hit It, etc.

Authentication Enabled

The meat of the changes in this PR are visible when Authentication is enabled.

Starting the Server

Authentication is enabled in scrape-server by providing a signing key to the server at startup. This can be done via a command line flag or an environment variable.

Here's a signing key for testing:

bCdcAT8EBvQXo7A50c4cSbkTc2gMvpVoMYrVaOpuKmM=

Is a signing key that you can use to enable authentication as shown below

Starting the server with authentication enabled:

Using Docker:

  • In your Docker Desktop find the scrape-bookworm-slim image you just built. If it's running, stop it.
  • Click the play button
  • When the modal opens, expand Optional Settings
  • For host port, enter 8080
  • Make an environment variable called SCRAPE_SIGNING_KEY
  • Set its value to the signing key above

Using a binary you built:

This is a little easier since you can just pass a command line flag containing the signing key

./build/scrape-server -signing-key bCdcAT8EBvQXo7A50c4cSbkTc2gMvpVoMYrVaOpuKmM=

Stuff to test (finally)

The Enter Token button will show and hide the token entry field, along with other buttons to save and clear the token, as noted above. Generally exercise these, feedback welcome!

var keyF = func() string { return "" }
if len(h.SigningKey) > 0 {
keyF = func() string {
var authTokenF = func() string { return "" }
Copy link
Author

Choose a reason for hiding this comment

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

Just renamed this to make it a little more descriptive.

tmpl = tmpl.Funcs(template.FuncMap{"AuthToken": keyF})
funcMap := template.FuncMap{
"AuthToken": authTokenF,
"AuthEnabled": authEnabledF,
Copy link
Author

Choose a reason for hiding this comment

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

This adds the hook so we can skip the token entry widget when auth is not enabled

font-size: 1.0rem;
font-family: Verdana, Arial, Helvetica, sans-serif;
text-decoration: none;
margin-bottom: 1px;
Copy link
Author

Choose a reason for hiding this comment

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

This margin-bottom and the line-heights here and in the next class are there because the vertical alignment of the +/- and the text following it were slightly off. There is now 1px extra space below, but the alignment looks ok.

This is annoying, but not that big of a deal -- but if there's a better way to do this, I'd like to know!

@efixler efixler marked this pull request as ready for review July 15, 2024 21:19
}
}
</script>
<div class="page-container">
Copy link
Author

@efixler efixler Jul 16, 2024

Choose a reason for hiding this comment

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

There are a bunch of changes in this block, but the reason it's showing up as a a complete block diff is because I fixed the formatting. The material changes are incremental.

@efixler efixler requested a review from ScottDowne July 16, 2024 19:18
@efixler efixler merged commit 1720426 into main Jul 16, 2024
1 check passed
efixler added a commit that referenced this pull request Jul 16, 2024
* Refactor test console ahead of upcoming auth changes (#6)
* Add token entry/storage functionality to test console (#7)
@efixler efixler deleted the token-control branch August 13, 2024 10:20
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.

2 participants