<commit_before>#!/bin/bash

set -eou pipefail

source utils.sh

# The Vagrantfiles in this repo set their VMs' hostnames to the directory
# in which they appear. Conveniently, this is the directory to which the
# VAGRANT_CWD environment variable points.
hostname="$VAGRANT_CWD"

echo "Adding Conjur connection info to Windows registry"
vagrant powershell -e -c "/vagrant/add_conjur_registry.ps1 $(conjur_host_port)"

echo "Rotating Conjur API key for host 'node01'"
conjur_ctl_container=$(docker ps | awk '/cyberark\/conjur-cli/{print $1}')
node_api_key="$(docker exec $conjur_ctl_container conjur host rotate_api_key -h node01)"

echo "Adding rotated Conjur API key to Windows Credentials Manager"
vagrant powershell -e -c "/vagrant/add_conjur_creds.ps1 $node_api_key $(conjur_host_port)"


echo "Clearing any previous certs generated for \"$hostname\" from Puppet server..."
puppet_master_container=$(docker ps | awk '/puppet\/puppetserver/{print $1}')
# Ignore errors since there might not be any certificates to clear

# We try first with Puppet v5 CLI (`puppet cert`)
docker exec "$puppet_master_container" \
  puppet cert clean "$hostname.cyber-ark.com" &>/dev/null || true

# Then we try the Puppet v6 CLI (`puppetserver ca`). Clean is not very predictable so
# we also do a revoke before it.
docker exec "$puppet_master_container" \
  puppetserver ca revoke --certname "$hostname.cyber-ark.com" 2>/dev/null || true
docker exec "$puppet_master_container" \
  puppetserver ca clean --certname "$hostname.cyber-ark.com" 2>/dev/null || true

# When the Puppet server tries to retrieve the API token for host 'node01'
# from Conjur, it will use the Conjur URL provided by the Puppet agent,
# which will be of the form 'https://conjur:<random-host-port>'. This random<commit_msg>Make Vagrant E2E tests use a snapshot restore before running Puppet agent<commit_after>#!/bin/bash

set -eou pipefail

source utils.sh

# The Vagrantfiles in this repo set their VMs' hostnames to the directory
# in which they appear. Conveniently, this is the directory to which the
# VAGRANT_CWD environment variable points.
hostname="$VAGRANT_CWD"

snapshot_name="$(agent_snapshot_name $PUPPET_AGENT_VERSION)"

echo "Restoring snapshot to '$snapshot_name'..."
vagrant snapshot restore "$snapshot_name"

echo "Adding Conjur connection info to Windows registry"
vagrant powershell -e -c "/vagrant/add_conjur_registry.ps1 $(conjur_host_port)"

echo "Rotating Conjur API key for host 'node01'"
conjur_ctl_container=$(docker ps | awk '/cyberark\/conjur-cli/{print $1}')
node_api_key="$(docker exec $conjur_ctl_container conjur host rotate_api_key -h node01)"

echo "Adding rotated Conjur API key to Windows Credentials Manager"
vagrant powershell -e -c "/vagrant/add_conjur_creds.ps1 $node_api_key $(conjur_host_port)"


echo "Clearing any previous certs generated for \"$hostname\" from Puppet server..."
puppet_master_container=$(docker ps | awk '/puppet\/puppetserver/{print $1}')
# Ignore errors since there might not be any certificates to clear

# We try first with Puppet v5 CLI (`puppet cert`)
docker exec "$puppet_master_container" \
  puppet cert clean "$hostname.cyber-ark.com" &>/dev/null || true

# Then we try the Puppet v6 CLI (`puppetserver ca`). Clean is not very predictable so
# we also do a revoke before it.
docker exec "$puppet_master_container" \
  puppetserver ca revoke --certname "$hostname.cyber-ark.com" 2>/dev/null || true
docker exec "$puppet_master_container" \
  puppetserver ca clean --certname "$hostname.cyber-<EMAIL>" 2>/dev/null || true

# When the Puppet server tries to retrieve the API token for host 'node01'
# from Conjur, it will use the Conjur URL provided by the Puppet agent,
# which will be of the form 'https://conjur:<random-host-port>'. This random
{'fraction_non_alphanumeric': 0.0993114406779661, 'fraction_numerical': 0.007680084745762712, 'mean_word_length': 4.966824644549763, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 12, 'https://': 2, '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': '6434048', 'n_tokens_mistral': 1280, 'n_tokens_neox': 1219, 'n_words': 439}