-
Notifications
You must be signed in to change notification settings - Fork 9
Improve utility scripts #169
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ab23b7e
Make the create log script edit the wrangler.jsonc
mendess e34d2c5
Add script to create the ccadb_roots kv namespace
mendess d2d97c4
Make location optional
mendess 425a2f7
Improve script correctness
mendess a51f3c4
Update ct_worker/readme to mention scripts
mendess 2211e7e
Run shellcheck
mendess File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,49 +1,74 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -e -o pipefail | ||
| cd "$(dirname "$0")/.." || exit # this script assumes it's runnnig inside the ct_worker dir | ||
|
|
||
| # Helper script to create resources for a log shard. | ||
|
|
||
| if [ -z $ENV ] || [ -z $LOG_NAME ] || [ -z $LOCATION ] || [ -z $CLOUDFLARE_ACCOUNT_ID ]; then | ||
| echo "ENV, LOG_NAME, LOCATION, and CLOUDFLARE_ACCOUNT_ID must all be set" | ||
| if [ -z "${ENV}" ] || [ -z "${LOG_NAME}" ] || [ -z "${CLOUDFLARE_ACCOUNT_ID}" ]; then | ||
| echo "ENV, LOG_NAME, and CLOUDFLARE_ACCOUNT_ID must all be set" | ||
| exit 1 | ||
| fi | ||
|
|
||
| WRANGLER_CONF=${WRANGLER_CONF:-wrangler.jsonc} | ||
|
|
||
| while true; do | ||
| read -p "Do you want to proceed with ENV=${ENV}, LOG_NAME=${LOG_NAME}, LOCATION=${LOCATION}, CLOUDFLARE_ACCOUNT_ID=${CLOUDFLARE_ACCOUNT_ID}? (y/N) " yn | ||
| if [ "${LOCATION}" ]; then | ||
| L=", LOCATION=${LOCATION}" | ||
| fi | ||
| read -rp "Do you want to proceed with ENV=${ENV}, LOG_NAME=${LOG_NAME}${L}, CLOUDFLARE_ACCOUNT_ID=${CLOUDFLARE_ACCOUNT_ID}? (y/N) " yn | ||
| case $yn in | ||
| [yY] ) echo "Proceeding..."; break;; | ||
| [nN] ) echo "Exiting..."; exit;; | ||
| * ) echo "Invalid input. Please enter 'y' or 'N'.";; | ||
| esac | ||
| done | ||
|
|
||
|
|
||
| # https://github.com/cloudflare/azul/pull/169#discussion_r2582145507 | ||
| location=() | ||
| if [ "${LOCATION}" ]; then | ||
| location=(--location "${LOCATION}") | ||
| fi | ||
|
|
||
| # Create R2 bucket if it does not already exist | ||
| npx wrangler -e="${ENV}" -c "${WRANGLER_CONF}" r2 bucket create static-ct-public-${LOG_NAME} --location ${LOCATION} | ||
| npx wrangler \ | ||
| -e="${ENV}" \ | ||
| -c "${WRANGLER_CONF}" \ | ||
| r2 bucket create \ | ||
| "static-ct-public-${LOG_NAME}" \ | ||
| --update-config \ | ||
rozbb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| --binding "public_${LOG_NAME}" "${location[@]}" | ||
|
|
||
| # Create KV namespace if it does not already exist | ||
| npx wrangler -e="${ENV}" -c "${WRANGLER_CONF}" kv namespace create static-ct-cache-${LOG_NAME} | ||
| npx wrangler \ | ||
| -e="${ENV}" \ | ||
| -c "${WRANGLER_CONF}" \ | ||
| kv namespace create \ | ||
| "static-ct-cache-${LOG_NAME}" \ | ||
| --update-config \ | ||
| --binding "cache_${LOG_NAME}" | ||
|
|
||
| # Create witness and log signing keys if they do not already exist | ||
| if npx wrangler -e=${ENV} secret list | grep -q WITNESS_KEY_${LOG_NAME}; then | ||
| if npx wrangler -e="${ENV}" -c "${WRANGLER_CONF}" secret list | grep -q "WITNESS_KEY_${LOG_NAME}"; then | ||
| echo "WITNESS_KEY_${LOG_NAME} already exists" | ||
| else | ||
| openssl genpkey -algorithm ed25519 | npx wrangler -c "$WRANGLER_CONF" -e=${ENV} secret put WITNESS_KEY_${LOG_NAME} | ||
| openssl genpkey -algorithm ed25519 | | ||
| npx wrangler -e="${ENV}" -c "${WRANGLER_CONF}" secret put "WITNESS_KEY_${LOG_NAME}" | ||
| fi | ||
| if npx wrangler -e=${ENV} secret list | grep -q SIGNING_KEY_${LOG_NAME}; then | ||
| if npx wrangler -e="${ENV}" -c "${WRANGLER_CONF}" secret list | grep -q "SIGNING_KEY_${LOG_NAME}"; then | ||
| echo "SIGNING_KEY_${LOG_NAME} already exists" | ||
| else | ||
| openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256 | npx wrangler -c "$WRANGLER_CONF" -e=${ENV} secret put SIGNING_KEY_${LOG_NAME} | ||
| openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256 | | ||
| npx wrangler -e="${ENV}" -c "${WRANGLER_CONF}" secret put "SIGNING_KEY_${LOG_NAME}" | ||
| fi | ||
|
|
||
| echo "DONE" | ||
| echo "NOTE: If you intend to run wrangler dev with this log, you must add the appropriate signing keys to .dev.vars" | ||
| echo "~~~~~~" | ||
| echo "echo -n \"SIGNING_KEY_${LOG_NAME}=\\\\\"\" >> .dev.vars" | ||
| echo "openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256 | sed 's/$/\\\\\\\\\\\\\\\\n/g' | tr -d \\\\n >> .dev.vars" | ||
| echo "echo '\"' >> .dev.vars" | ||
| echo "echo -n \"WITNESS_KEY_${LOG_NAME}=\\\\\"\" >> .dev.vars" | ||
| echo "openssl genpkey -algorithm ed25519 | sed 's/$/\\\\\\\\\\\\\\\\n/g' | tr -d \\\\n >> .dev.vars" | ||
| echo "echo '\"' >> .dev.vars" | ||
| printf 'echo -n "SIGNING_KEY_%s=\\"" >> .dev.vars\n' "${LOG_NAME}" | ||
| printf 'openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256 | sed '\''s/$/\\\\n/g'\'' | tr -d '\''\\n'\'' >> .dev.vars\n' | ||
| printf 'echo \\" >> .dev.vars\n' | ||
| printf 'echo -n "WITNESS_KEY_%s=\\"" >> .dev.vars\n' "${LOG_NAME}" | ||
| printf 'openssl genpkey -algorithm ed25519 | sed '\''s/$/\\\\n/g'\'' | tr -d '\''\\n'\'' >> .dev.vars\n' | ||
| printf 'echo \\" >> .dev.vars\n' | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -e -o pipefail | ||
| cd "$(dirname "$0")/.." || exit # this script assumes it's runnnig inside the ct_worker dir | ||
|
|
||
| # Helper script to create resources for a log shard. | ||
|
|
||
| if [ -z "${ENV}" ] || [ -z "${CLOUDFLARE_ACCOUNT_ID}" ]; then | ||
| echo "ENV and CLOUDFLARE_ACCOUNT_ID must all be set" | ||
| exit 1 | ||
| fi | ||
|
|
||
| WRANGLER_CONF=${WRANGLER_CONF:-wrangler.jsonc} | ||
|
|
||
| while true; do | ||
| read -rp "Do you want to proceed with ENV=${ENV}, CLOUDFLARE_ACCOUNT_ID=${CLOUDFLARE_ACCOUNT_ID}? (y/N) " yn | ||
| case $yn in | ||
| [yY] ) echo "Proceeding..."; break;; | ||
| [nN] ) echo "Exiting..."; exit;; | ||
| * ) echo "Invalid input. Please enter 'y' or 'N'.";; | ||
| esac | ||
| done | ||
|
|
||
| # Create KV namespace if it does not already exist | ||
rozbb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| npx wrangler \ | ||
| -e="${ENV}" \ | ||
| -c "${WRANGLER_CONF}" \ | ||
| kv namespace create \ | ||
| static-ct-ccadb-roots \ | ||
| --update-config \ | ||
| --binding ccadb_roots | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.