<commit_before>#!/bin/bash
: "${secret_method:?}"
: "${taito_setv:?}"

set -e

secret_value=""
secret_value2=""

case "${secret_method}" in
  manual)
    while [[ ${#secret_value} -lt 8 ]] || [[ "${secret_value}" != "${secret_value2}" ]]; do
      echo "New secret for ${secret_name} (min 8 characters):"
      read -r -s secret_value
      echo "New secret for ${secret_name} again:"
      read -r -s secret_value2
    done
    ;;
  file)
    if [[ "${taito_provider:-}" == "gcloud" ]] && \
       [[ "${secret_name}" == *"serviceaccount"* ]]; then
      opts=""
      if [[ ${google_authuser:-} ]]; then
        opts="authuser=${google_authuser}&"
      fi
      echo ------------------------------------------------------------------------------
      echo "You most likely can download the service account key as json file from"
      echo "the following web page by pressing the 'create credentials' button."
      echo
      echo "https://console.cloud.google.com/apis/credentials?${opts}project=${taito_resource_namespace_id:-}"
      echo ------------------------------------------------------------------------------
      echo
    fi
    while [[ ! -f ${secret_value} ]]; do
      echo "File path relative to project root folder (for example './secret.json'):"
      read -r secret_value
    done
    ;;
  csrkey)
    while [[ ! "${domain}" ]]; do
      echo "Enter domain name (e.g. 'app.mydomain.com'):"
      read -r domain
    done
    echo "Next you'll have to enter details of the organization that owns the"
    echo "domain. You can usually leave the email and all the 'extra attributes'"
    echo "empty. Enter the domain name again when you are asked for a 'common name'."
    echo
    echo "If you are not sure of the details, try to find an existing website of the"
    echo "organization and use its certificate details as an example."
    echo
    echo "Press enter to continue"
    echo read -r
    mkdir -p ./tmp
    key_file="./tmp/${domain}.key"
    csr_file="./tmp/${domain}.csr"
    rm -f "${key_file}"
    rm -f "${csr_file}"
    (
      ${taito_setv}
      openssl req -new -newkey rsa:2048 -nodes \
        -keyout "${key_file}" -out "${csr_file}"
    )
    secret_value="${key_file}"
    echo
    echo "The generated secret key will be saved to Kubernetes and deleted from"
    echo "local disk during this command execution."
    echo
    echo "After this command has been executed successfully, you should send the"
    echo "generated '${csr_file}' file to the Certificate Authority. If someone"
    echo "else does that instead, it is ok to send the csr file to him by email."
    echo
    echo "Press enter to continue"
    echo read -r
    ;;
  htpasswd|htpasswd-plain)
    mkdir -p ./tmp
    secret_value="./tmp/${secret_name}"
    rm -f "${secret_value}"
    touch "${secret_value}"
    echo "Enter all usernames and passwords for the htpasswd file."
    echo "Enter empty username when you are done."
    echo
    if [[ "${secret_method}" == "htpasswd-plain" ]]; then
      htpasswd_options="-p"
      echo "NOTE: All passwords will be stored in plain text. You should not use"
      echo "them for anything important. Use method 'htpasswd' instead if you"
      echo "want to encrypt all passwords"
    else
      htpasswd_options=""
      echo "NOTE: All passwords will be encrypted. Thus, you should store all credentials"
      echo "to a safe location so that you can remember them later. Use a password manager"
      echo "for example."
    fi
    while echo && echo "username: " && read -r username && [[ ${username} ]]
    do
      until htpasswd ${htpasswd_options} "${secret_value}" "${username}"; do :; done<commit_msg>docs: improve basic auth instructions<commit_after>#!/bin/bash
: "${secret_method:?}"
: "${taito_setv:?}"

set -e

secret_value=""
secret_value2=""

case "${secret_method}" in
  manual)
    while [[ ${#secret_value} -lt 8 ]] || [[ "${secret_value}" != "${secret_value2}" ]]; do
      echo "New secret for ${secret_name} (min 8 characters):"
      read -r -s secret_value
      echo "New secret for ${secret_name} again:"
      read -r -s secret_value2
    done
    ;;
  file)
    if [[ "${taito_provider:-}" == "gcloud" ]] && \
       [[ "${secret_name}" == *"serviceaccount"* ]]; then
      opts=""
      if [[ ${google_authuser:-} ]]; then
        opts="authuser=${google_authuser}&"
      fi
      echo ------------------------------------------------------------------------------
      echo "You most likely can download the service account key as json file from"
      echo "the following web page by pressing the 'create credentials' button."
      echo
      echo "https://console.cloud.google.com/apis/credentials?${opts}project=${taito_resource_namespace_id:-}"
      echo ------------------------------------------------------------------------------
      echo
    fi
    while [[ ! -f ${secret_value} ]]; do
      echo "File path relative to project root folder (for example './secret.json'):"
      read -r secret_value
    done
    ;;
  csrkey)
    while [[ ! "${domain}" ]]; do
      echo "Enter domain name (e.g. 'app.mydomain.com'):"
      read -r domain
    done
    echo "Next you'll have to enter details of the organization that owns the"
    echo "domain. You can usually leave the email and all the 'extra attributes'"
    echo "empty. Enter the domain name again when you are asked for a 'common name'."
    echo
    echo "If you are not sure of the details, try to find an existing website of the"
    echo "organization and use its certificate details as an example."
    echo
    echo "Press enter to continue"
    echo read -r
    mkdir -p ./tmp
    key_file="./tmp/${domain}.key"
    csr_file="./tmp/${domain}.csr"
    rm -f "${key_file}"
    rm -f "${csr_file}"
    (
      ${taito_setv}
      openssl req -new -newkey rsa:2048 -nodes \
        -keyout "${key_file}" -out "${csr_file}"
    )
    secret_value="${key_file}"
    echo
    echo "The generated secret key will be saved to Kubernetes and deleted from"
    echo "local disk during this command execution."
    echo
    echo "After this command has been executed successfully, you should send the"
    echo "generated '${csr_file}' file to the Certificate Authority. If someone"
    echo "else does that instead, it is ok to send the csr file to him by email."
    echo
    echo "Press enter to continue"
    echo read -r
    ;;
  htpasswd|htpasswd-plain)
    mkdir -p ./tmp
    secret_value="./tmp/${secret_name}"
    rm -f "${secret_value}"
    touch "${secret_value}"
    echo
    echo "BASIC AUTH CREDENTIALS"
    echo
    echo "Basic autentication is typically used for hiding non-production"
    echo "environments from the public. Enter usernames and passwords below."
    echo "Enter an empty username when you are done."
    echo
    if [[ "${secret_method}" == "htpasswd-plain" ]]; then
      htpasswd_options="-p"
      echo "NOTE: All passwords will be stored in plain text. You should not use"
      echo "them for anything important."
    else
      htpasswd_options=""
      echo "NOTE: All passwords will be encrypted. Thus, you should store all credentials"
      echo "to a safe location so that you can remember them later. Use a password manager"
      echo "for example."
    fi
    while echo && echo "username: " && read -r username && [[ ${username} ]]
    do
      until htpasswd ${htpasswd_options} "${secret_value}" "${username}"; do :; done
{'fraction_non_alphanumeric': 0.15917653390742734, 'fraction_numerical': 0.0024219590958019376, 'mean_word_length': 2.386332574031891, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4931706', 'n_tokens_mistral': 2155, 'n_tokens_neox': 2097, 'n_words': 819}