<commit_before>#!/bin/bash
#
# creates the encrypted data bag secret
# creates a key and certificate
# adds them to a local encrypted data bag
#

if [ ! -f encrypted_data_bag_secret ]; then
  openssl rand -base64 512 | tr -d '\r\n' > encrypted_data_bag_secret
fi

if [ ! -f lj.key ] || [ ! -f lj.crt ]; then
  openssl req -x509 -newkey rsa:2048 -keyout lj.key -out lj.crt -nodes -subj /CN=logstash.getuhost.org
fi

CERT=`cat lj.crt | base64 | xargs echo | sed 's/ //g'`
KEY=`cat lj.key | base64 | xargs echo | sed 's/ //g'`

echo '{
  "id": "secrets",
  "key": "$KEY",
  "certificate": "$CERT"
}' | sed s/'$KEY'/$KEY/ | sed s/'$CERT'/$CERT/ > bag.json


knife data bag create lumberjack -z
knife data bag from file lumberjack bag.json --secret-file encrypted_data_bag_secret -z

rm bag.json
<commit_msg>Added parameter to pass in the site name<commit_after>#!/bin/bash
#
# create_crt_key.sh <logserver dns name>
#
# creates the encrypted data bag secret
# creates a key and certificate
# adds them to a local encrypted data bag
#

set -e

if [ $# -eq 0 ]; then
    echo "Usage: create_crt_key.sh <logserver dns name>"
    exit 1;
fi

name=$1

if [ ! -f encrypted_data_bag_secret ]; then
  openssl rand -base64 512 | tr -d '\r\n' > encrypted_data_bag_secret
fi

if [ ! -f lj.key ] || [ ! -f lj.crt ]; then
  openssl req -x509 -newkey rsa:2048 -keyout lj.key -out lj.crt -nodes -subj /CN=$name
fi

CERT=`cat lj.crt | base64 | xargs echo | sed 's/ //g'`
KEY=`cat lj.key | base64 | xargs echo | sed 's/ //g'`

echo '{
  "id": "secrets",
  "key": "$KEY",
  "certificate": "$CERT"
}' | sed s/'$KEY'/$KEY/ | sed s/'$CERT'/$CERT/ > bag.json


knife data bag create lumberjack -z
knife data bag from file lumberjack bag.json --secret-file encrypted_data_bag_secret -z

rm bag.json

{'fraction_non_alphanumeric': 0.15011286681715574, 'fraction_numerical': 0.019751693002257337, 'mean_word_length': 3.2214285714285715, 'pattern_counts': {'":': 6, '<': 5, '<?xml version=': 0, '>': 9, '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': '2454928', 'n_tokens_mistral': 740, 'n_tokens_neox': 687, 'n_words': 223}