From da16ab44f7e5317d179dc5c6ed77475ccc50cc50 Mon Sep 17 00:00:00 2001 From: cbaxley Date: Wed, 17 Apr 2024 03:54:39 -0400 Subject: [PATCH 1/6] Append the flags to the end of the password file --- testing/InstallTestbed.ps1 | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/testing/InstallTestbed.ps1 b/testing/InstallTestbed.ps1 index 9ccdb6cf..14077921 100644 --- a/testing/InstallTestbed.ps1 +++ b/testing/InstallTestbed.ps1 @@ -383,4 +383,18 @@ $EsPasswords # Write the passwords to a file $PasswordPath = "..\..\${ResourceGroup}.password.txt" -$EsPasswords | Out-File -Append -FilePath $PasswordPath \ No newline at end of file +$EsPasswords | Out-File -Append -FilePath $PasswordPath + +# Constructing a string that will hold all the command-line parameters to be written to the file +$paramsToWrite = @" +ResourceGroup: $ResourceGroup +DomainController: $DomainController +LinuxVM: $LinuxVM +NumClients: $NumClients +LinuxOnly: $($LinuxOnly.IsPresent) +Version: $Version +Branch: $Branch +"@ + +# Output the parameters to the end of the password file +$paramsToWrite | Out-File -Append -FilePath $PasswordPath \ No newline at end of file From 2824f6df3d46f8ec17ea0282246dedb6add97e96 Mon Sep 17 00:00:00 2001 From: cbaxley Date: Wed, 17 Apr 2024 04:40:08 -0400 Subject: [PATCH 2/6] Prints the contents of password.txt to the console --- testing/InstallTestbed.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/testing/InstallTestbed.ps1 b/testing/InstallTestbed.ps1 index 14077921..6e7b8be0 100644 --- a/testing/InstallTestbed.ps1 +++ b/testing/InstallTestbed.ps1 @@ -397,4 +397,6 @@ Branch: $Branch "@ # Output the parameters to the end of the password file -$paramsToWrite | Out-File -Append -FilePath $PasswordPath \ No newline at end of file +$paramsToWrite | Out-File -Append -FilePath $PasswordPath + +Get-Content -Path $PasswordPath \ No newline at end of file From 8d0b91a7caf9c2bf6cb488647677e12dd5c009cb Mon Sep 17 00:00:00 2001 From: cbaxley Date: Wed, 17 Apr 2024 07:23:52 -0400 Subject: [PATCH 3/6] Extract the credentials in a new way to compensate for the flags being in the file --- testing/configure/lib/functions.sh | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/testing/configure/lib/functions.sh b/testing/configure/lib/functions.sh index 95c28e1d..10fd8610 100644 --- a/testing/configure/lib/functions.sh +++ b/testing/configure/lib/functions.sh @@ -1,33 +1,25 @@ extract_credentials() { - # Set default file path if not provided local file_path=${1:-'/opt/lme/Chapter 3 Files/output.log'} - - # Check if the file exists if [ ! -f "$file_path" ]; then echo "File not found: $file_path" return 1 fi - # Read and extract credentials from the last 18 lines - while IFS= read -r line; do - # Remove leading '## ' and trim whitespaces from the line + # Use a while loop directly reading from a process substitution + while IFS=: read -r line rest; do line=$(echo "$line" | sed 's/^## //g' | xargs) + rest=$(echo "$rest" | xargs) - # Split the line into key and value - key=$(echo "$line" | awk -F ':' '{print $1}') - value=$(echo "$line" | awk -F ':' '{print $2}' | xargs) # xargs to trim whitespaces from value - - # Remove non-word characters (keep only word characters) - value=$(echo "$value" | sed 's/[^[:alnum:]_]//g') + key=$(echo "$line" | awk '{print $1}') + value=$rest case $key in - "elastic") export elastic=$value ;; - "kibana") export kibana=$value ;; - "logstash_system") export logstash_system=$value ;; - "logstash_writer") export logstash_writer=$value ;; - "dashboard_update") export dashboard_update=$value ;; + "elastic" | "kibana" | "logstash_system" | "logstash_writer" | "dashboard_update") + export "$key"="$value" + ;; esac - done < <(tail -n 18 "$file_path" | grep -E "(elastic|kibana|logstash_system|logstash_writer|dashboard_update):") + done < <(awk '/^## \w+:/{print $0}' "$file_path") + export ELASTIC_PASSWORD=$elastic } From 95befbc53485494f4e8f4f55e072120e4b011e3b Mon Sep 17 00:00:00 2001 From: cbaxley Date: Thu, 18 Apr 2024 06:29:38 -0400 Subject: [PATCH 4/6] Tests a build that runs locally on github --- .github/workflows/linux_only.yml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/linux_only.yml b/.github/workflows/linux_only.yml index eb821bc1..26e0128f 100644 --- a/.github/workflows/linux_only.yml +++ b/.github/workflows/linux_only.yml @@ -62,16 +62,17 @@ jobs: run: docker compose -p ${{ env.UNIQUE_ID }} -f testing/development/docker-compose.yml build lme --no-cache - name: Run Docker Compose - run: docker compose -p ${{ env.UNIQUE_ID }} -f testing/development/docker-compose.yml up -d + run: docker compose -p ${{ env.UNIQUE_ID }} -f testing/development/docker-compose.yml up lme -d - name: List docker containers to wait for them to start run: | docker ps - - - name: Execute commands inside ubuntu container - run: | - cd testing/development - docker compose -p ${{ env.UNIQUE_ID }} exec -T ubuntu bash -c "echo 'Ubuntu container built'" + + # We are not using the ubuntu container so no use waiting for it to start + # - name: Execute commands inside ubuntu container + # run: | + # cd testing/development + # docker compose -p ${{ env.UNIQUE_ID }} exec -T ubuntu bash -c "echo 'Ubuntu container built'" - name: Install LME in container run: | From d2fe08b5c3e4a59a7c97415d3e7206f69b5e806c Mon Sep 17 00:00:00 2001 From: cbaxley Date: Thu, 18 Apr 2024 07:30:19 -0400 Subject: [PATCH 5/6] Keep container running for debugging purposes --- .github/workflows/linux_only.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/linux_only.yml b/.github/workflows/linux_only.yml index 26e0128f..ce7db024 100644 --- a/.github/workflows/linux_only.yml +++ b/.github/workflows/linux_only.yml @@ -98,5 +98,5 @@ jobs: run: | cd testing/development docker compose -p ${{ env.UNIQUE_ID }} exec -T -u root lme bash -c "rm -rf /home/admin.ackbar/LME/.pytest_cache" - docker compose -p ${{ env.UNIQUE_ID }} down - docker system prune --force \ No newline at end of file + # docker compose -p ${{ env.UNIQUE_ID }} down + # docker system prune -a --force \ No newline at end of file From a8ecd56b97e0f6b56cb530490b77bd6187ab5d7e Mon Sep 17 00:00:00 2001 From: cbaxley Date: Thu, 18 Apr 2024 09:11:36 -0400 Subject: [PATCH 6/6] Fix the credentials parsing function --- .github/workflows/linux_only.yml | 4 ++-- testing/configure/lib/functions.sh | 32 +++++++++++++----------------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/.github/workflows/linux_only.yml b/.github/workflows/linux_only.yml index ce7db024..b921b8a1 100644 --- a/.github/workflows/linux_only.yml +++ b/.github/workflows/linux_only.yml @@ -98,5 +98,5 @@ jobs: run: | cd testing/development docker compose -p ${{ env.UNIQUE_ID }} exec -T -u root lme bash -c "rm -rf /home/admin.ackbar/LME/.pytest_cache" - # docker compose -p ${{ env.UNIQUE_ID }} down - # docker system prune -a --force \ No newline at end of file + docker compose -p ${{ env.UNIQUE_ID }} down + docker system prune -a --force \ No newline at end of file diff --git a/testing/configure/lib/functions.sh b/testing/configure/lib/functions.sh index 10fd8610..11d1e6b5 100644 --- a/testing/configure/lib/functions.sh +++ b/testing/configure/lib/functions.sh @@ -1,26 +1,22 @@ extract_credentials() { - local file_path=${1:-'/opt/lme/Chapter 3 Files/output.log'} - if [ ! -f "$file_path" ]; then - echo "File not found: $file_path" - return 1 - fi + local file_path=${1:-'/opt/lme/Chapter 3 Files/output.log'} - # Use a while loop directly reading from a process substitution - while IFS=: read -r line rest; do - line=$(echo "$line" | sed 's/^## //g' | xargs) - rest=$(echo "$rest" | xargs) + if [ ! -f "$file_path" ]; then + echo "File not found: $file_path" + return 1 + fi - key=$(echo "$line" | awk '{print $1}') - value=$rest + # Use sed to extract the lines containing the credentials + credentials=$(sed -n '/^## [a-zA-Z_]*:/p' "$file_path") - case $key in - "elastic" | "kibana" | "logstash_system" | "logstash_writer" | "dashboard_update") - export "$key"="$value" - ;; - esac - done < <(awk '/^## \w+:/{print $0}' "$file_path") + # Loop through the extracted lines and assign the values to variables + while IFS=: read -r key value; do + key=$(echo "$key" | sed 's/^## //g' | tr -d '[:space:]') + value=$(echo "$value" | tr -d '\r\n') + export "$key"="$value" + done <<< "$credentials" - export ELASTIC_PASSWORD=$elastic + export ELASTIC_PASSWORD=$elastic } write_credentials_to_file() {