Last active
April 9, 2025 15:55
-
-
Save pepicrft/a692d44abf72df96c7bcd12c1e7bbc75 to your computer and use it in GitHub Desktop.
It creates a Swift file with the obfuscated values of the env. variables prefixed with `SECRET_`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -eo pipefail | |
# Check if output file argument is provided | |
if [ -z "$1" ]; then | |
echo "Usage: $0 <output_file_path>" | |
exit 1 | |
fi | |
OUTPUT_FILE="$1" | |
mkdir -p "$(dirname "$OUTPUT_FILE")" | |
{ | |
echo 'import Foundation' | |
echo 'import ObfuscateMacro' | |
echo '' | |
echo 'struct Secrets {' | |
} > "$OUTPUT_FILE" | |
env | while IFS='=' read -r key value; do | |
if [[ "$key" == SECRET_* ]]; then | |
base_key="${key#SECRET_}" | |
camel_case_key="$(echo "$base_key" | awk '{ | |
split(tolower($0), parts, "_"); | |
result = parts[1]; | |
for (i = 2; i <= length(parts); i++) { | |
result = result toupper(substr(parts[i],1,1)) substr(parts[i],2); | |
} | |
print result; | |
}')" | |
echo " static let $camel_case_key = #ObfuscatedString(\"$value\")" >> "$OUTPUT_FILE" | |
fi | |
done | |
echo '}' >> "$OUTPUT_FILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment