Skip to content

Commit

Permalink
remove not needed global (#18)
Browse files Browse the repository at this point in the history
* remove not needed global

* fix test

* remove not needed version from docker compose

* improve tests

* improve tests

* improve tests

* add todos
  • Loading branch information
dorsradek authored Aug 19, 2024
1 parent 1e1c76a commit 228d671
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 35 deletions.
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3.8'

services:
env-loader:
build:
Expand Down
53 changes: 21 additions & 32 deletions parse-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,49 +29,38 @@ load_dir() {

# $3, is the numbers of characters to strip in front of the key
KEY="${KEY:$3}"

# Removes the application.$application_name prefix if it exists
if [[ "$KEY" == "application.$APPLICATION_NAME."* ]]; then
KEY=${KEY#"application.$APPLICATION_NAME."}
fi

# TODO: remove when not needed - we use tag source instead
# Removes the .terraform suffix if it exists
if [[ "$KEY" == *".terraform" ]]; then
KEY=${KEY%".terraform"}
fi

# Removes the infrastructure.global prefix if it exists
# TODO: remove when not needed - we use tag visibility instead
# Removes the infrastructure.global. prefix if it exists
if [[ "$KEY" == "infrastructure.global."* ]]; then
KEY=${KEY#"infrastructure.global."}
fi

if [[ "$KEY" =~ infrastructure\.[^.]+\.global\..+ ]]; then
# Remove 'infrastructure.' prefix
TEMP=${KEY#infrastructure.}

# Split off the part after 'global.'
PART_BEFORE_GLOBAL=${TEMP%%.global.*}
PART_AFTER_GLOBAL=${TEMP#*.global.}

# Combine the parts
KEY="${PART_BEFORE_GLOBAL}.${PART_AFTER_GLOBAL}"
# Removes the infrastructure. prefix if it exists
if [[ "$KEY" == "infrastructure."* ]]; then
KEY=${KEY#"infrastructure."}
fi

# Removes the application.global prefix if it exists
# TODO: remove when not needed - we use tag visibility instead
# Removes the application.global. prefix if it exists
if [[ "$KEY" == "application.global."* ]]; then
KEY=${KEY#"application.global."}
fi

if [[ "$KEY" =~ application\.[^.]+\.global\..+ ]]; then
# Remove 'application.' prefix
TEMP=${KEY#application.}

# Split off the part after 'global.'
PART_BEFORE_GLOBAL=${TEMP%%.global.*}
PART_AFTER_GLOBAL=${TEMP#*.global.}

# Combine the parts
KEY="${PART_BEFORE_GLOBAL}.${PART_AFTER_GLOBAL}"
fi

# Removes the application.$application_name prefix if it exists
if [[ "$KEY" == "application.$APPLICATION_NAME."* ]]; then
KEY=${KEY#"application.$APPLICATION_NAME."}
fi

# Removes the .terraform suffix if it exists
if [[ "$KEY" == *".terraform" ]]; then
KEY=${KEY%".terraform"}
# Removes the application. prefix if it exists
if [[ "$KEY" == "application."* ]]; then
KEY=${KEY#"application."}
fi

log "source=$FILENAME destination=$KEY"
Expand Down
8 changes: 7 additions & 1 deletion test/validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ else
printf 'The file "%s" is different from "%s"\n' "$result" "$expected"
printf '\n'
echo $(diff $result $expected)

printf '\n\n'
printf 'Expected:\n'
cat "$expected"
printf '\n\n'
printf 'Result:\n'
cat "$result"

exit 1
fi

0 comments on commit 228d671

Please sign in to comment.