Skip to content

Commit

Permalink
BDOG-3001 testing out decoding files
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanrowe committed Mar 27, 2024
1 parent c4792fd commit 7bc51ae
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
16 changes: 15 additions & 1 deletion app/uk/gov/hmrc/platformstatusfrontend/config/AppConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@

package uk.gov.hmrc.platformstatusfrontend.config

import play.api.Configuration
import play.api.{Configuration, Logger}

import java.io.File
import javax.inject.{Inject, Singleton}
import scala.concurrent.duration.{Duration, FiniteDuration}
import scala.io.Source
import scala.util.Using

@Singleton
class AppConfig @Inject()(config: Configuration) {
Expand Down Expand Up @@ -47,4 +50,15 @@ class AppConfig @Inject()(config: Configuration) {
lazy val iteration3Enabled: Boolean = config.get[Boolean]("checks.iteration3.enabled")
lazy val iteration4Enabled: Boolean = config.get[Boolean]("checks.iteration4.enabled")
lazy val iteration5Enabled: Boolean = config.get[Boolean]("checks.iteration5.enabled")

val logger = Logger(getClass)
lazy val filePath = config.getOptional[String]("test.file.path")
filePath.map { path =>
val file = new File(path)
Using(Source.fromFile(file)) { source =>
val lines = source.getLines().mkString

logger.info(s"Successfully loaded file from $filePath - content: $lines")
}
}
}
27 changes: 27 additions & 0 deletions decode_and_store_files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

log_error_and_exit() {
echo "$1" >&2
exit 1
}

PREFIX="BASE64FILES_"

for var in $(compgen -e | grep "^$PREFIX"); do
IFS='_' read -r _ index type <<< "$var"

if [[ "$type" == "LOCATION" ]]; then
location[$index]=${!var}
elif [[ "$type" == "CONTENT" ]]; then
content[$index]=${!var}
fi
done

for index in "${!location[@]}"; do
if [[ -n "${content[$index]}" && -n "${location[$index]}" ]]; then
echo "${content[$index]}" | base64 --decode > "${location[$index]}" 2>/dev/null || \
log_error_and_exit "Error processing ${location[$index]}: Invalid base64 or insufficient permissions."
else
log_error_and_exit "Error: Matching location or content missing for index $index."
fi
done
6 changes: 6 additions & 0 deletions start-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env sh

bash decode_and_store_files.sh

SCRIPT=$(find . -type f -name platform-status-frontend)
exec $SCRIPT $HMRC_CONFIG -Dconfig.file=conf/platform-status-frontend.conf

0 comments on commit 7bc51ae

Please sign in to comment.