<commit_before>#!/bin/bash
# DO NOT EDIT - This file is being maintained by Chef
set -e

NUM_TOKENS=4 # current + 4
VALID_TOKEN=<PASSWORD> # in seconds

SECONDS_AGO=$((${NUM_TOKENS} * ${VALID_TOKEN}))
OLD_TIME=$(/bin/date -u "+%Y-%m-%dT %H:%M:%S %z" -d "${SECONDS_AGO} seconds ago")
QOS_TOKENS=($(/usr/bin/oathtool --totp --now="${OLD_TIME}" --window=${NUM_TOKENS} --time-step-size=${VALID_TOKEN}s -b "<%= @totp_key %>"))

# ${qos_tokens[4]/[-1] } = OSM.org exclusive / current
# ${qos_tokens[3]/[-2] } = OSM.org exclusive / stale
# ${qos_tokens[2]/[-3] } = tile.openstreetmap.org default
# ${qos_tokens[1]/[-4] } = stale ~ 1 hour
# ${qos_tokens[0]} = expired

# Test if number of tokens returned by oathtool is expected number
if [ "${#QOS_TOKENS[@]}" -ne "$((${NUM_TOKENS}+1))" ]; then
  >&2 echo "ERROR: Unexpected number of tokens"
  exit 1
fi

QOS_TOKEN_OSM=${QOS_TOKENS[-1]} # Cookie set by openstreetmap.org
QOS_TOKEN_OSM_STALE=${QOS_TOKENS[-2]} # Cookie set by openstreetmap.org stale
QOS_TOKEN_DEFAULT=${QOS_TOKENS[-3]} # Cookie presented by tile.openstreetmap.org to browsers
QOS_TOKEN_STALE=${QOS_TOKENS[-4]} # Cookie which has become stale and will be replaced

if [ -z "$QOS_TOKEN_OSM" -o -z "$QOS_TOKEN_DEFAULT" -o -z "$QOS_TOKEN_STALE" ]; then
  >&2 echo "ERROR: Unexpected blank token"
  exit 2
fi

cat <<EOF >/etc/nginx/conf.d/tile_qos_rates.map
default 24576; # Default Rate (No QoS cookie)
"${QOS_TOKEN_STALE}" 24576; # Stale
"${QOS_TOKEN_DEFAULT}" 24576; # Default
"${QOS_TOKEN_OSM_STALE}" 32768; # Exclusive Stale
"${QOS_TOKEN_OSM}" 32768; # Exclusive
EOF

cat <<EOF >/etc/nginx/conf.d/tile_qos_cookies.map
default 'qos_token=${QOS_TOKEN_DEFAULT}; Max-Age=${VALID_TOKEN}; Domain=openstreetmap.org; Path=/'; # Cookie Domain per RFC6265
"${QOS_TOKEN_DEFAULT}" ''; # Do not Set-Cookie. # Default
"${QOS_TOKEN_OSM}" ''; # Do not Set-Cookie. # Exclusive
EOF

# Check config, reload config and fail safe
/etc/init.d/nginx configtest && /bin/systemctl try-reload-or-restart nginx<commit_msg>tilecache: make config test quiet<commit_after>#!/bin/bash
# DO NOT EDIT - This file is being maintained by Chef
set -e

NUM_TOKENS=4 # current + 4
VALID_TOKEN=<PASSWORD> # in seconds

SECONDS_AGO=$((${NUM_TOKENS} * ${VALID_TOKEN}))
OLD_TIME=$(/bin/date -u "+%Y-%m-%dT %H:%M:%S %z" -d "${SECONDS_AGO} seconds ago")
QOS_TOKENS=($(/usr/bin/oathtool --totp --now="${OLD_TIME}" --window=${NUM_TOKENS} --time-step-size=${VALID_TOKEN}s -b "<%= @totp_key %>"))

# ${qos_tokens[4]/[-1] } = OSM.org exclusive / current
# ${qos_tokens[3]/[-2] } = OSM.org exclusive / stale
# ${qos_tokens[2]/[-3] } = tile.openstreetmap.org default
# ${qos_tokens[1]/[-4] } = stale ~ 1 hour
# ${qos_tokens[0]} = expired

# Test if number of tokens returned by oathtool is expected number
if [ "${#QOS_TOKENS[@]}" -ne "$((${NUM_TOKENS}+1))" ]; then
  >&2 echo "ERROR: Unexpected number of tokens"
  exit 1
fi

QOS_TOKEN_OSM=${QOS_TOKENS[-1]} # Cookie set by openstreetmap.org
QOS_TOKEN_OSM_STALE=${QOS_TOKENS[-2]} # Cookie set by openstreetmap.org stale
QOS_TOKEN_DEFAULT=${QOS_TOKENS[-3]} # Cookie presented by tile.openstreetmap.org to browsers
QOS_TOKEN_STALE=${QOS_TOKENS[-4]} # Cookie which has become stale and will be replaced

if [ -z "$QOS_TOKEN_OSM" -o -z "$QOS_TOKEN_DEFAULT" -o -z "$QOS_TOKEN_STALE" ]; then
  >&2 echo "ERROR: Unexpected blank token"
  exit 2
fi

cat <<EOF >/etc/nginx/conf.d/tile_qos_rates.map
default 24576; # Default Rate (No QoS cookie)
"${QOS_TOKEN_STALE}" 24576; # Stale
"${QOS_TOKEN_DEFAULT}" 24576; # Default
"${QOS_TOKEN_OSM_STALE}" 32768; # Exclusive Stale
"${QOS_TOKEN_OSM}" 32768; # Exclusive
EOF

cat <<EOF >/etc/nginx/conf.d/tile_qos_cookies.map
default 'qos_token=${QOS_TOKEN_DEFAULT}; Max-Age=${VALID_TOKEN}; Domain=openstreetmap.org; Path=/'; # Cookie Domain per RFC6265
"${QOS_TOKEN_DEFAULT}" ''; # Do not Set-Cookie. # Default
"${QOS_TOKEN_OSM}" ''; # Do not Set-Cookie. # Exclusive
EOF

# Check config, reload config and fail safe
/etc/init.d/nginx configtest 2>/dev/null && /bin/systemctl try-reload-or-restart nginx
{'fraction_non_alphanumeric': 0.1751608114794656, 'fraction_numerical': 0.02498762988619495, 'mean_word_length': 5.052395209580839, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3635558', 'n_tokens_mistral': 1697, 'n_tokens_neox': 1611, 'n_words': 376}