diff --git a/website/redirects.txt b/website/redirects.txt new file mode 100644 index 000000000..35b706213 --- /dev/null +++ b/website/redirects.txt @@ -0,0 +1,64 @@ +# +# REDIRECTS FILE +# +# This is a sample redirect file. Redirects allow individual projects to add +# their own redirect rules in a declarative manner using Fastly edge +# dictionaries. +# +# FORMAT +# +# Redirects are in the format. There must be at least one space between the +# original path and the new path, and there must be exactly two entries per +# line. +# +# /original-path /new-path +# +# GLOB MATCHING +# +# Because of the way lookup tables work, there is no support for glob matching. +# Fastly does not provide a way to iterate through the lookup table, so it is +# not possible to run through the table and find anything that matches. As such +# URLs must match directly. +# +# More complex redirects are possible, but must be added directly to the +# configuration. Please contact the release engineering team for assistance. +# +# DELETING +# +# Deleting items is not supported at this time. To delete an item, contact the +# release engineering team and they will delete the dictionary item. +# +# MISC +# +# - Blank lines are ignored +# - Comments are hash-style +# - URLs are limited to 256 characters +# - Items are case-sensitive (please use all lowercase) +# + +/docs/config/index.html /docs/configuration/index.html +/docs/install/install.html /docs/install/index.html +/docs/install/upgrade.html /docs/guides/upgrading/index.html +/docs/install/upgrade-to-0.5.html /docs/guides/upgrading/upgrade-to-0.5.0.html +/docs/install/upgrade-to-0.5.1.html /docs/guides/upgrading/upgrade-to-0.5.1.html +/docs/install/upgrade-to-0.6.html /docs/guides/upgrading/upgrade-to-0.6.0.html +/docs/install/upgrade-to-0.6.1.html /docs/guides/upgrading/upgrade-to-0.6.1.html +/docs/install/upgrade-to-0.6.2.html /docs/guides/upgrading/upgrade-to-0.6.2.html +/docs/http/sys-init.html /api/system/init.html +/docs/http/sys-seal-status.html /api/system/seal-status.html +/docs/http/sys-seal.html /api/system/seal.html +/docs/http/sys-unseal.html /api/system/unseal.html +/docs/http/sys-mounts.html /api/system/mounts.html +/docs/http/sys-remount.html /api/system/remount.html +/docs/http/sys-auth.html /api/system/auth.html +/docs/http/sys-policy.html /api/system/policy.html +/docs/http/sys-audit.html /api/system/audit.html +/docs/http/sys-renew.html /api/system/renew.html +/docs/http/sys-revoke.html /api/system/revoke.html +/docs/http/sys-revoke-prefix.html /api/system/revoke-prefix.html +/docs/http/sys-leader.html /api/system/leader.html +/docs/http/sys-key-status.html /api/system/key-status.html +/docs/http/sys-rekey.html /api/system/rekey.html +/docs/http/sys-rotate.html /api/system/rotate.html +/docs/http/sys-raw.html /api/system/raw.html +/docs/http/sys-health.html /api/system/health.html diff --git a/website/scripts/deploy.sh b/website/scripts/deploy.sh index 383ad8a30..bd9ec6e90 100755 --- a/website/scripts/deploy.sh +++ b/website/scripts/deploy.sh @@ -1,9 +1,10 @@ -#!/bin/bash +#!/usr/bin/env sh set -e PROJECT="vault" PROJECT_URL="www.vaultproject.io" FASTLY_SERVICE_ID="7GrxRJP3PVBuqQbyxYQ0MV" +FASTLY_DICTIONARY_ID="4uTFhCUtoa1cV9DuXeC1Fo" # Ensure the proper AWS environment variables are set if [ -z "$AWS_ACCESS_KEY_ID" ]; then @@ -93,6 +94,71 @@ if [ -z "$NO_UPLOAD" ]; then modify "s3://hc-sites/$PROJECT/latest/" fi +# Add redirects if they exist +if [ -f "./redirects.txt" ]; then + echo "Adding redirects..." + fields=() + while read -r line; do + [[ "$line" =~ ^#.* ]] && continue + [[ -z "$line" ]] && continue + + # Read fields + IFS=" " read -ra parts <<<"$line" + fields+=("${parts[@]}") + done < "./redirects.txt" + + # Check we have pairs + if [ $((${#fields[@]} % 2)) -ne 0 ]; then + echo "Bad redirects (not an even number)!" + exit 1 + fi + + # Check we don't have more than 1000 entries (yes, it says 2000 below, but that + # is because we've split into multiple lines). + if [ "${#fields}" -gt 2000 ]; then + echo "More than 1000 entries!" + exit 1 + fi + + # Validations + for field in "${fields[@]}"; do + if [ "${#field}" -gt 256 ]; then + echo "'$field' is > 256 characters!" + exit 1 + fi + + if [ "${field:0:1}" != "/" ]; then + echo "'$field' does not start with /!" + exit 1 + fi + done + + # Build the payload for single-request updates. + jq_args=() + jq_query="." + for (( i=0; i<${#fields[@]}; i+=2 )); do + original="${fields[i]}" + redirect="${fields[i+1]}" + echo "Redirecting ${original} -> ${redirect}" + jq_args+=(--arg "key$((i/2))" "${original}") + jq_args+=(--arg "value$((i/2))" "${redirect}") + jq_query+="| .items |= (. + [{op: \"upsert\", item_key: \$key$((i/2)), item_value: \$value$((i/2))}])" + done + json="$(jq "${jq_args[@]}" "${jq_query}" <<<'{"items": []}')" + + # Post the JSON body + curl \ + --fail \ + --silent \ + --output /dev/null \ + --request "PATCH" \ + --header "Fastly-Key: $FASTLY_API_KEY" \ + --header "Content-type: application/json" \ + --header "Accept: application/json" \ + --data "$json"\ + "https://api.fastly.com/service/$FASTLY_SERVICE_ID/dictionary/$FASTLY_DICTIONARY_ID/items" +fi + # Perform a purge of the surrogate key. if [ -z "$NO_PURGE" ]; then echo "Purging Fastly cache..."