From a878d79fda7a71677fa645ff7d73742c5682ff12 Mon Sep 17 00:00:00 2001 From: Cole Eason Date: Wed, 1 Nov 2023 15:48:06 -0700 Subject: [PATCH 01/15] A working script that only supports additions --- .github/scripts/createHelpRedirects.sh | 117 +++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100755 .github/scripts/createHelpRedirects.sh diff --git a/.github/scripts/createHelpRedirects.sh b/.github/scripts/createHelpRedirects.sh new file mode 100755 index 000000000000..d2def2b72d31 --- /dev/null +++ b/.github/scripts/createHelpRedirects.sh @@ -0,0 +1,117 @@ +#!/bin/bash +# +# Adds new routes to the Cloudflare Bulk Redirects list for communityDot to helpDot +# pages. Does some basic sanity checking. +# set -x +source ../../scripts/shellUtils.sh + +info "Adding any new redirects from communityDot to helpDot" + +declare -r LIST_ID="20eb13215038446a98fd69ccf6d1026d" +declare -r ZONE_ID="$CLOUDFLARE_ACCOUNT_ID" +declare -r REDIRECTS_FILE="../../docs/redirects.csv" + +function checkCloudflareResult { + RESULTS=$1 + RESULT_MESSAGE=$(echo "$RESULTS" | jq .success) + + if ! [[ "$RESULT_MESSAGE" == "true" ]]; then + ERROR_MESSAGE=$(echo "$RESULTS" | jq .errors) + error "Error calling Cloudfalre API: $ERROR_MESSAGE" + exit 1 + fi +} + +LIST_RESULT=$(curl -s --request GET --url "https://api.cloudflare.com/client/v4/accounts/$ZONE_ID/rules/lists/$LIST_ID/items" \ + --header 'Content-Type: application/json' \ + --header "Authorization: Bearer $CLOUDFLARE_LIST_TOKEN") + +checkCloudflareResult "$LIST_RESULT" + +# Build an array of all of the current directs, each line is a csv of source,destination +read -r -a CURRENT_REDIRECTS < <(echo "$LIST_RESULT" | jq -r '.result[].redirect | "\(.source_url),\(.target_url)"' | tr '\n' ' ') +declare -a ITEMS_TO_ADD + +while read -r line; do + # Split each line of the file into a source and destination so we can sanity check + # and compare against the current list. + read -r -a LINE_PARTS < <(echo "$line" | tr ',' ' ') + SOURCE_URL=${LINE_PARTS[0]} + DEST_URL=${LINE_PARTS[1]} + FOUND=false + + # Make sure the format of the line is as execpted. + if [[ "${#LINE_PARTS[@]}" -gt 2 ]]; then + error "Found a line with more than one comma: $line" + exit 1 + fi + + # Basic sanity checking to make sure that the source and destination are in expected + # subdomains. + if ! [[ $SOURCE_URL =~ ^https://community\.expensify\.com ]]; then + error "Found source URL that is not a community URL: $SOURCE_URL" + exit 1 + fi + + if ! [[ $DEST_URL =~ ^https://help\.expensify\.com ]]; then + error "Found destination URL that is not a help URL: $DEST_URL" + exit 1 + fi + + info "Source: $SOURCE_URL and destination: $DEST_URL appear to be formatted correctly." + + # This will get slow if we get to a ton of entries but there's no better way to do this in bash v3 + # because associative arrays do not exist. + for entry in "${CURRENT_REDIRECTS[@]}"; do + read -r -a ENTRY_PARTS < <(echo "$entry" | tr ',' ' ') + CURRENT_SOURCE_URL=${ENTRY_PARTS[0]} + CURRENT_DEST_URL=${ENTRY_PARTS[1]} + + # If the current csv line matches an existing rule, skip. + if [[ "$SOURCE_URL" == "$CURRENT_SOURCE_URL" ]] && [[ "$DEST_URL" == "$CURRENT_DEST_URL" ]]; then + echo "$SOURCE_URL is already mapped to $DEST_URL, skipping." + FOUND=true + break + fi + done + + if [[ $FOUND == true ]]; then + continue + fi + + # If we've made it this far, this csv line doesn't match any existing rules + # so we need to do add it. + info "$SOURCE_URL was not found in the existing list mapped to $DEST_URL, adding it." + ITEMS_TO_ADD+=("$line") + +# This line skips the first line in the csv because the first line is a header row. +done <<< "$(tail +2 $REDIRECTS_FILE)" + +# Sanity check that we should actually be running this. +if [[ "${#ITEMS_TO_ADD[@]}" -lt 1 ]]; then + error "No items found to add, why are we running?" + exit 1 +fi + +# This block builds a single JSON object with all of our updates so we can +# reduce the number of API calls we make. You cannot add any logging or anything +# that prints to std out to this block or it will break. We capture all of the std out +# from this loop and pass it to jq to build the json object. Any non-json will break the +# jq call at the end. +POST_JSON=$(for new in "${ITEMS_TO_ADD[@]}"; do + read -r -a LINE_PARTS < <(echo "$new" | tr ',' ' ') + SOURCE_URL=${LINE_PARTS[0]} + DEST_URL=${LINE_PARTS[1]} + jq -n --arg source "$SOURCE_URL" --arg dest "$DEST_URL" '{"redirect": {source_url: $source, target_url: $dest}}' +done | jq -n '. |= [inputs]') + +info "Adding redirects for $POST_JSON" + +POST_RESULT=$(curl -s --request POST --url "https://api.cloudflare.com/client/v4/accounts/$ZONE_ID/rules/lists/$LIST_ID/items" \ + --header 'Content-Type: application/json' \ + --header "Authorization: Bearer $CLOUDFLARE_LIST_TOKEN" \ + --data "$POST_JSON") + +checkCloudflareResult "$POST_RESULT" + +success "Updated lists successfully" From 12836a4fac5c9a1df35c5a59c8425ba13bd3ecda Mon Sep 17 00:00:00 2001 From: Cole Eason Date: Wed, 1 Nov 2023 16:02:54 -0700 Subject: [PATCH 02/15] A more thorough approach that allows deletions --- .github/scripts/createHelpRedirects.sh | 78 +++++++++++++------------- 1 file changed, 40 insertions(+), 38 deletions(-) diff --git a/.github/scripts/createHelpRedirects.sh b/.github/scripts/createHelpRedirects.sh index d2def2b72d31..154ddb00ce0d 100755 --- a/.github/scripts/createHelpRedirects.sh +++ b/.github/scripts/createHelpRedirects.sh @@ -2,7 +2,7 @@ # # Adds new routes to the Cloudflare Bulk Redirects list for communityDot to helpDot # pages. Does some basic sanity checking. -# set -x + source ../../scripts/shellUtils.sh info "Adding any new redirects from communityDot to helpDot" @@ -22,14 +22,6 @@ function checkCloudflareResult { fi } -LIST_RESULT=$(curl -s --request GET --url "https://api.cloudflare.com/client/v4/accounts/$ZONE_ID/rules/lists/$LIST_ID/items" \ - --header 'Content-Type: application/json' \ - --header "Authorization: Bearer $CLOUDFLARE_LIST_TOKEN") - -checkCloudflareResult "$LIST_RESULT" - -# Build an array of all of the current directs, each line is a csv of source,destination -read -r -a CURRENT_REDIRECTS < <(echo "$LIST_RESULT" | jq -r '.result[].redirect | "\(.source_url),\(.target_url)"' | tr '\n' ' ') declare -a ITEMS_TO_ADD while read -r line; do @@ -38,7 +30,6 @@ while read -r line; do read -r -a LINE_PARTS < <(echo "$line" | tr ',' ' ') SOURCE_URL=${LINE_PARTS[0]} DEST_URL=${LINE_PARTS[1]} - FOUND=false # Make sure the format of the line is as execpted. if [[ "${#LINE_PARTS[@]}" -gt 2 ]]; then @@ -60,34 +51,13 @@ while read -r line; do info "Source: $SOURCE_URL and destination: $DEST_URL appear to be formatted correctly." - # This will get slow if we get to a ton of entries but there's no better way to do this in bash v3 - # because associative arrays do not exist. - for entry in "${CURRENT_REDIRECTS[@]}"; do - read -r -a ENTRY_PARTS < <(echo "$entry" | tr ',' ' ') - CURRENT_SOURCE_URL=${ENTRY_PARTS[0]} - CURRENT_DEST_URL=${ENTRY_PARTS[1]} - - # If the current csv line matches an existing rule, skip. - if [[ "$SOURCE_URL" == "$CURRENT_SOURCE_URL" ]] && [[ "$DEST_URL" == "$CURRENT_DEST_URL" ]]; then - echo "$SOURCE_URL is already mapped to $DEST_URL, skipping." - FOUND=true - break - fi - done - - if [[ $FOUND == true ]]; then - continue - fi - - # If we've made it this far, this csv line doesn't match any existing rules - # so we need to do add it. - info "$SOURCE_URL was not found in the existing list mapped to $DEST_URL, adding it." ITEMS_TO_ADD+=("$line") # This line skips the first line in the csv because the first line is a header row. done <<< "$(tail +2 $REDIRECTS_FILE)" -# Sanity check that we should actually be running this. +# Sanity check that we should actually be running this and we aren't about to delete +# every single redirect. if [[ "${#ITEMS_TO_ADD[@]}" -lt 1 ]]; then error "No items found to add, why are we running?" exit 1 @@ -98,20 +68,52 @@ fi # that prints to std out to this block or it will break. We capture all of the std out # from this loop and pass it to jq to build the json object. Any non-json will break the # jq call at the end. -POST_JSON=$(for new in "${ITEMS_TO_ADD[@]}"; do +PUT_JSON=$(for new in "${ITEMS_TO_ADD[@]}"; do read -r -a LINE_PARTS < <(echo "$new" | tr ',' ' ') SOURCE_URL=${LINE_PARTS[0]} DEST_URL=${LINE_PARTS[1]} jq -n --arg source "$SOURCE_URL" --arg dest "$DEST_URL" '{"redirect": {source_url: $source, target_url: $dest}}' done | jq -n '. |= [inputs]') -info "Adding redirects for $POST_JSON" +info "Adding redirects for $PUT_JSON" -POST_RESULT=$(curl -s --request POST --url "https://api.cloudflare.com/client/v4/accounts/$ZONE_ID/rules/lists/$LIST_ID/items" \ +# We use PUT here instead of POST so that we replace the entire list in place. This has many benefits: +# 1. We don't have to check if items are already in the list, allowing this script to run faster +# 2. We can support deleting redirects this way by simply removing them from the list +# 3. We can support updating redirects this way, in the case of typos or moved destinations. +# +# Additionally this API call is async, so after we finish it, we must poll to wait for it to finish to +# to know that it was actually completed. +PUT_RESULT=$(curl -s --request PUT --url "https://api.cloudflare.com/client/v4/accounts/$ZONE_ID/rules/lists/$LIST_ID/items" \ --header 'Content-Type: application/json' \ --header "Authorization: Bearer $CLOUDFLARE_LIST_TOKEN" \ - --data "$POST_JSON") + --data "$PUT_JSON") + +checkCloudflareResult "$PUT_RESULT" +OPERATION_ID=$(echo "$PUT_RESULT" | jq -r .result.operation_id) -checkCloudflareResult "$POST_RESULT" +DONE=false + +# Poll for completition +while [[ $DONE == false ]]; do + CHECK_RESULT=$(curl -s --request GET --url "https://api.cloudflare.com/client/v4/accounts/$ZONE_ID/rules/lists/bulk_operations/$OPERATION_ID" \ + --header 'Content-Type: application/json' \ + --header "Authorization: Bearer $CLOUDFLARE_LIST_TOKEN") + checkCloudflareResult "$CHECK_RESULT" + + STATUS=$(echo "$CHECK_RESULT" | jq -r .result.status) + + # Exit on completed or failed, other options are pending or running, in both cases + # we want to keep polling. + if [[ $STATUS == "completed" ]]; then + DONE=true + fi + + if [[ $STATUS == "failed" ]]; then + ERROR_MESSAGE=$(echo "$CHECK_RESULT" | jq .result.error) + error "List update failed with error: $ERROR_MESSAGE" + exit 1 + fi +done success "Updated lists successfully" From 96fc10e1245f5393aa6ba0b9d59b60c6284ef53a Mon Sep 17 00:00:00 2001 From: Cole Eason Date: Wed, 1 Nov 2023 16:08:41 -0700 Subject: [PATCH 03/15] Add worker, add redirects file, fix import line based on cwd in runner --- .github/scripts/createHelpRedirects.sh | 2 +- .github/workflows/updateHelpDotRedirects.yml | 31 ++++++++++++++++++++ docs/redirects.csv | 2 ++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/updateHelpDotRedirects.yml create mode 100644 docs/redirects.csv diff --git a/.github/scripts/createHelpRedirects.sh b/.github/scripts/createHelpRedirects.sh index 154ddb00ce0d..ac4d85bc730e 100755 --- a/.github/scripts/createHelpRedirects.sh +++ b/.github/scripts/createHelpRedirects.sh @@ -3,7 +3,7 @@ # Adds new routes to the Cloudflare Bulk Redirects list for communityDot to helpDot # pages. Does some basic sanity checking. -source ../../scripts/shellUtils.sh +source scripts/shellUtils.sh info "Adding any new redirects from communityDot to helpDot" diff --git a/.github/workflows/updateHelpDotRedirects.yml b/.github/workflows/updateHelpDotRedirects.yml new file mode 100644 index 000000000000..5a4286bf9f3d --- /dev/null +++ b/.github/workflows/updateHelpDotRedirects.yml @@ -0,0 +1,31 @@ +name: Update Redirects to ExpensifyHelp + +on: + # Run on any push to main that has changes to the docs directory + push: + branches: + - main + paths: + - 'docs/redirects.csv' + + # Run on any manual trigger + workflow_dispatch: + +# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. +# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. +concurrency: + group: "pages" + cancel-in-progress: false + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 + + - name: Create docs routes file + env: + CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + CLOUDFLARE_LIST_TOKEN: ${{ secrets.CLOUDFLARE_LIST_TOKEN }} + run: ./.github/scripts/createHelpRedirects.sh diff --git a/docs/redirects.csv b/docs/redirects.csv new file mode 100644 index 000000000000..d4fb7723bd0f --- /dev/null +++ b/docs/redirects.csv @@ -0,0 +1,2 @@ +sourceURL,targetURL +https://community.expensify.com/discussion/5634/deep-dive-how-long-will-it-take-for-me-to-receive-my-reimbursement,https://help.expensify.com/articles/expensify-classic/get-paid-back/reports/Reimbursements From 863f1c4b4a0aebf520f107ba8df3088e42f5f7ce Mon Sep 17 00:00:00 2001 From: Cole Eason Date: Wed, 1 Nov 2023 16:14:18 -0700 Subject: [PATCH 04/15] Add infra as code owner on redirects file --- .github/CODEOWNERS | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 4f78ee6b69bf..8f0c21b67132 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,2 +1,5 @@ # Every PR gets a review from an internal Expensify engineer * @Expensify/pullerbear + +# Every PR that touches redirects gets reviewed by ring0 +docs/redirects.csv @Expensify/ring0 \ No newline at end of file From 1627a696854a3619577d064d8fff8af0bdce7598 Mon Sep 17 00:00:00 2001 From: Cole Eason Date: Wed, 1 Nov 2023 16:18:48 -0700 Subject: [PATCH 05/15] Remove page that is in the wrong place and duplicated elsewhere --- ...e share for ExpensifyApproved!-partners.md | 22 ------------------- 1 file changed, 22 deletions(-) delete mode 100644 docs/Expensify-Card-revenue share for ExpensifyApproved!-partners.md diff --git a/docs/Expensify-Card-revenue share for ExpensifyApproved!-partners.md b/docs/Expensify-Card-revenue share for ExpensifyApproved!-partners.md deleted file mode 100644 index f9d18da76ef6..000000000000 --- a/docs/Expensify-Card-revenue share for ExpensifyApproved!-partners.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: Expensify Card revenue share for ExpensifyApproved! partners -description: Earn money when your clients adopt the Expensify Card ---- - - -# About -Start making more with us! We're thrilled to announce a new incentive for our US-based ExpensifyApproved! partner accountants. You can now earn additional income for your firm every time your client uses their Expensify Card. We're offering 0.5% of the total Expensify Card spend of your clients in cashback returned to your firm. The more your clients spend, the more cashback your firm receives!
-
This program is currently only available to US-based ExpensifyApproved! partner accountants. - -# How-to -To benefit from this program, complete the following steps -1. Ensure that you are listed as the Primary Contact under your client's domain in Expensify. If you're not currently the Primary Contact for your client, you or your client can follow the instructions outlined in [our help article](https://community.expensify.com/discussion/5749/how-to-add-and-remove-domain-admins#:~:text=Domain%20Admins%20have%20total%20control,a%20member%20of%20the%20domain.) to assign you this role. -2. Add a Business Bank Account to the Primary Contact account. Follow the instructions in [our help article](https://community.expensify.com/discussion/4641/how-to-add-a-deposit-only-bank-account-both-personal-and-business) to get a Business Bank Account added. - -# FAQ -- What if my firm is not permitted to accept revenue share from our clients?
-
We understand that different firms may have different policies. If your firm is unable to accept this revenue share, you can pass the revenue share back to your client to give them an additional 0.5% of cash back using your own internal payment tools.

-How will I know which clients to pay back?
-
Every month you will receive an automated message via new.expensify.com and email providing a breakdown of revenue shared generated per client.

-- What if my firm does not wish to participate in the program?
-
Please reach out to your assigned partner manager at new.expensify.com to inform them you would not like to accept the revenue share nor do you want to pass the revenue share to your clients. From 57de166d8ed0cd2072c7635f8e381eebecda45b3 Mon Sep 17 00:00:00 2001 From: Cole Eason Date: Wed, 1 Nov 2023 16:53:21 -0700 Subject: [PATCH 06/15] use infra not ring0 --- .github/CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 8f0c21b67132..c106a25c8ab1 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -2,4 +2,4 @@ * @Expensify/pullerbear # Every PR that touches redirects gets reviewed by ring0 -docs/redirects.csv @Expensify/ring0 \ No newline at end of file +docs/redirects.csv @Expensify/infra \ No newline at end of file From da796e004505186f86e15157f7a91f4295e243eb Mon Sep 17 00:00:00 2001 From: Cole Eason Date: Wed, 1 Nov 2023 16:55:41 -0700 Subject: [PATCH 07/15] Update concurrency group to be unique to this worker --- .github/workflows/updateHelpDotRedirects.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/updateHelpDotRedirects.yml b/.github/workflows/updateHelpDotRedirects.yml index 5a4286bf9f3d..491882b08d91 100644 --- a/.github/workflows/updateHelpDotRedirects.yml +++ b/.github/workflows/updateHelpDotRedirects.yml @@ -14,7 +14,7 @@ on: # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. concurrency: - group: "pages" + group: "redirects" cancel-in-progress: false jobs: From 3a902acace1b2b7afb19f370fac23d79d0ec7d07 Mon Sep 17 00:00:00 2001 From: Cole Eason Date: Wed, 1 Nov 2023 16:56:00 -0700 Subject: [PATCH 08/15] Update worker name --- .github/workflows/updateHelpDotRedirects.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/updateHelpDotRedirects.yml b/.github/workflows/updateHelpDotRedirects.yml index 491882b08d91..6c69aadee593 100644 --- a/.github/workflows/updateHelpDotRedirects.yml +++ b/.github/workflows/updateHelpDotRedirects.yml @@ -24,7 +24,7 @@ jobs: - name: Checkout uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 - - name: Create docs routes file + - name: Create help dot redirect env: CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} CLOUDFLARE_LIST_TOKEN: ${{ secrets.CLOUDFLARE_LIST_TOKEN }} From e0e85ed341ec6dd2d58243cc75405358e5df6ab8 Mon Sep 17 00:00:00 2001 From: Cole Eason Date: Wed, 1 Nov 2023 16:56:42 -0700 Subject: [PATCH 09/15] Update docs path based on cwd --- .github/scripts/createHelpRedirects.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/createHelpRedirects.sh b/.github/scripts/createHelpRedirects.sh index ac4d85bc730e..d36b7014510e 100755 --- a/.github/scripts/createHelpRedirects.sh +++ b/.github/scripts/createHelpRedirects.sh @@ -9,7 +9,7 @@ info "Adding any new redirects from communityDot to helpDot" declare -r LIST_ID="20eb13215038446a98fd69ccf6d1026d" declare -r ZONE_ID="$CLOUDFLARE_ACCOUNT_ID" -declare -r REDIRECTS_FILE="../../docs/redirects.csv" +declare -r REDIRECTS_FILE="docs/redirects.csv" function checkCloudflareResult { RESULTS=$1 From 855695895e11a8e6e5db6d4daee5bc420cdb78cf Mon Sep 17 00:00:00 2001 From: Cole Date: Mon, 6 Nov 2023 14:01:42 -0800 Subject: [PATCH 10/15] Update .github/workflows/updateHelpDotRedirects.yml Co-authored-by: Andrew Gable --- .github/workflows/updateHelpDotRedirects.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/updateHelpDotRedirects.yml b/.github/workflows/updateHelpDotRedirects.yml index 6c69aadee593..531b8a3812fd 100644 --- a/.github/workflows/updateHelpDotRedirects.yml +++ b/.github/workflows/updateHelpDotRedirects.yml @@ -1,7 +1,7 @@ name: Update Redirects to ExpensifyHelp on: - # Run on any push to main that has changes to the docs directory + # Run on any push to main that has changes to the redirects file push: branches: - main From bb81e9c7dbd41e532fb2a864f6fcfe2d5d7a8969 Mon Sep 17 00:00:00 2001 From: Cole Eason Date: Mon, 6 Nov 2023 14:05:01 -0800 Subject: [PATCH 11/15] Add -e --- .github/scripts/createHelpRedirects.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/scripts/createHelpRedirects.sh b/.github/scripts/createHelpRedirects.sh index d36b7014510e..c1c3082eb5ca 100755 --- a/.github/scripts/createHelpRedirects.sh +++ b/.github/scripts/createHelpRedirects.sh @@ -3,6 +3,8 @@ # Adds new routes to the Cloudflare Bulk Redirects list for communityDot to helpDot # pages. Does some basic sanity checking. +set -e + source scripts/shellUtils.sh info "Adding any new redirects from communityDot to helpDot" From fffdf95d15ca7abbb45cd37f70db7d74ea473bd7 Mon Sep 17 00:00:00 2001 From: Cole Date: Mon, 6 Nov 2023 14:52:56 -0800 Subject: [PATCH 12/15] Update .github/scripts/createHelpRedirects.sh Co-authored-by: John Lee --- .github/scripts/createHelpRedirects.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/createHelpRedirects.sh b/.github/scripts/createHelpRedirects.sh index c1c3082eb5ca..e0414b871977 100755 --- a/.github/scripts/createHelpRedirects.sh +++ b/.github/scripts/createHelpRedirects.sh @@ -96,7 +96,7 @@ OPERATION_ID=$(echo "$PUT_RESULT" | jq -r .result.operation_id) DONE=false -# Poll for completition +# Poll for completion while [[ $DONE == false ]]; do CHECK_RESULT=$(curl -s --request GET --url "https://api.cloudflare.com/client/v4/accounts/$ZONE_ID/rules/lists/bulk_operations/$OPERATION_ID" \ --header 'Content-Type: application/json' \ From c793f1511d006ca44b4c88166497e99793bc9770 Mon Sep 17 00:00:00 2001 From: Cole Date: Mon, 6 Nov 2023 14:53:02 -0800 Subject: [PATCH 13/15] Update .github/scripts/createHelpRedirects.sh Co-authored-by: John Lee --- .github/scripts/createHelpRedirects.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/createHelpRedirects.sh b/.github/scripts/createHelpRedirects.sh index e0414b871977..0a26ade7c6e3 100755 --- a/.github/scripts/createHelpRedirects.sh +++ b/.github/scripts/createHelpRedirects.sh @@ -19,7 +19,7 @@ function checkCloudflareResult { if ! [[ "$RESULT_MESSAGE" == "true" ]]; then ERROR_MESSAGE=$(echo "$RESULTS" | jq .errors) - error "Error calling Cloudfalre API: $ERROR_MESSAGE" + error "Error calling Cloudflare API: $ERROR_MESSAGE" exit 1 fi } From eeb937db556e814990ed3b2046f9b863d48a8da1 Mon Sep 17 00:00:00 2001 From: Cole Eason Date: Tue, 7 Nov 2023 09:26:21 -0800 Subject: [PATCH 14/15] Strip https from source url so we match both schemes --- .github/scripts/createHelpRedirects.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/scripts/createHelpRedirects.sh b/.github/scripts/createHelpRedirects.sh index c1c3082eb5ca..198935162e0f 100755 --- a/.github/scripts/createHelpRedirects.sh +++ b/.github/scripts/createHelpRedirects.sh @@ -74,7 +74,8 @@ PUT_JSON=$(for new in "${ITEMS_TO_ADD[@]}"; do read -r -a LINE_PARTS < <(echo "$new" | tr ',' ' ') SOURCE_URL=${LINE_PARTS[0]} DEST_URL=${LINE_PARTS[1]} - jq -n --arg source "$SOURCE_URL" --arg dest "$DEST_URL" '{"redirect": {source_url: $source, target_url: $dest}}' + NO_PREFIX_SOURCE_URL=${SOURCE_URL/https:\/\//} + jq -n --arg source "$NO_PREFIX_SOURCE_URL" --arg dest "$DEST_URL" '{"redirect": {source_url: $source, target_url: $dest}}' done | jq -n '. |= [inputs]') info "Adding redirects for $PUT_JSON" From bd7ea22ac649bd785de52e9a3d30f24ad82f74f4 Mon Sep 17 00:00:00 2001 From: Cole Eason Date: Tue, 7 Nov 2023 09:28:43 -0800 Subject: [PATCH 15/15] Add a comment about the stripping of prefix --- .github/scripts/createHelpRedirects.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/scripts/createHelpRedirects.sh b/.github/scripts/createHelpRedirects.sh index a7e60b344f57..04f55e19b4fb 100755 --- a/.github/scripts/createHelpRedirects.sh +++ b/.github/scripts/createHelpRedirects.sh @@ -19,7 +19,7 @@ function checkCloudflareResult { if ! [[ "$RESULT_MESSAGE" == "true" ]]; then ERROR_MESSAGE=$(echo "$RESULTS" | jq .errors) - error "Error calling Cloudflare API: $ERROR_MESSAGE" + error "Error calling Cloudfalre API: $ERROR_MESSAGE" exit 1 fi } @@ -74,6 +74,9 @@ PUT_JSON=$(for new in "${ITEMS_TO_ADD[@]}"; do read -r -a LINE_PARTS < <(echo "$new" | tr ',' ' ') SOURCE_URL=${LINE_PARTS[0]} DEST_URL=${LINE_PARTS[1]} + + # We strip the prefix here so that the rule will match both http and https. Since vanilla will eventially be removed, + # we need to catch both because we will not have the http > https redirect done by vanilla anymore. NO_PREFIX_SOURCE_URL=${SOURCE_URL/https:\/\//} jq -n --arg source "$NO_PREFIX_SOURCE_URL" --arg dest "$DEST_URL" '{"redirect": {source_url: $source, target_url: $dest}}' done | jq -n '. |= [inputs]') @@ -97,7 +100,7 @@ OPERATION_ID=$(echo "$PUT_RESULT" | jq -r .result.operation_id) DONE=false -# Poll for completion +# Poll for completition while [[ $DONE == false ]]; do CHECK_RESULT=$(curl -s --request GET --url "https://api.cloudflare.com/client/v4/accounts/$ZONE_ID/rules/lists/bulk_operations/$OPERATION_ID" \ --header 'Content-Type: application/json' \