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

refactor: 'create_initial_user.sh' helper script #59

Merged
merged 5 commits into from
Jan 25, 2022

Conversation

bryphe-coder
Copy link
Contributor

I've been running this curl command a bunch of times every day (whenever I restart my dev server) - so I thought it might nice to have as a utility. Let me know if you'd prefer a different place to put this, @kylecarbs !

@bryphe-coder bryphe-coder self-assigned this Jan 25, 2022
@codecov
Copy link

codecov bot commented Jan 25, 2022

Codecov Report

Merging #59 (afc64a7) into main (5d7112f) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main      #59   +/-   ##
=======================================
  Coverage   71.91%   71.91%           
=======================================
  Files          79       79           
  Lines        2902     2902           
  Branches       49       49           
=======================================
  Hits         2087     2087           
  Misses        641      641           
  Partials      174      174           
Flag Coverage Δ
unittest-go-macos-latest 67.52% <ø> (-0.09%) ⬇️
unittest-go-ubuntu-latest 70.66% <ø> (-0.09%) ⬇️
unittest-go-windows-latest 67.39% <ø> (+0.17%) ⬆️
unittest-js 73.10% <ø> (ø)
Impacted Files Coverage Δ
peer/conn.go 76.64% <0.00%> (-0.90%) ⬇️
peerbroker/listen.go 82.81% <0.00%> (+2.34%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5d7112f...afc64a7. Read the comment docs.

PASSWORD="${PASSWORD:-p@ssword1}"

curl -X POST \
-d "{\"email\": \"$EMAIL\", \"username\": \"$USERNAME\", \"organization\": \"$ORGANIZATION\", \"password\": \"$PASSWORD\"}" \
Copy link
Contributor

Choose a reason for hiding this comment

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

you can probably make this look more readable if you quote with '' on the outside, you can see coderd-setup for examples: https://github.com/coder/m/blob/b397beb481dfc03192b1b7af53f681330bccfb0f/devbin/coderd-setup#L97-L104 (this example needs to double escape due to run_trace, but you probably don't need to do that)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I actually tried this first! But when I ran lint, I got this shellcheck error:

In scripts/create_initial_user.sh line 11:
-d '{"email": "$EMAIL", "username": "$USERNAME", "organization": "$ORGANIZATION", "password": "$PASSWORD"}' \
   ^-- SC2016: Expressions don't expand in single quotes, use double quotes for that.

I'm open to ideas to make this cleaner though, the current approach is not so readable.

Copy link
Contributor

Choose a reason for hiding this comment

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

Bash will only interpolate $-variables inside ""s, but double quotes don't do what they normally do when inside a single-quoted expression. So the solution is to exit the single-quote context, add the quoted variable, and then re-enter. Something like this:

-d '{"email": "'"$EMAIL"'", "username": "'"$USERNAME"'", "organization": "'"$ORGANIZATION"'", "password": "'"$PASSWORD"'"}' \

Copy link
Member

@kylecarbs kylecarbs left a comment

Choose a reason for hiding this comment

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

Another option would be making this happen in the develop.sh script. I'd be game for that!


EMAIL="${EMAIL:-admin@coder.com}"
USERNAME="${USERNAME:-admin}"
ORGANIZATION="${ORGANIZATION:-default}"
Copy link
Member

Choose a reason for hiding this comment

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

Let's make this something like ACME-Corp instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, made the change in a5427bb

EMAIL="${EMAIL:-admin@coder.com}"
USERNAME="${USERNAME:-admin}"
ORGANIZATION="${ORGANIZATION:-default}"
PASSWORD="${PASSWORD:-p@ssword1}"
Copy link
Member

Choose a reason for hiding this comment

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

Could we use password instead? Nobody should be using this in a secure way anyhow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing 👍 Fixed in a5427bb

@bryphe-coder bryphe-coder merged commit 139828d into main Jan 25, 2022
@bryphe-coder bryphe-coder deleted the bryphe/refactor/create-user-script branch January 25, 2022 19:08
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.

None yet

3 participants