Skip to content

Instantly share code, notes, and snippets.

@pepicrft
Last active April 9, 2025 15:55
Show Gist options
  • Save pepicrft/a692d44abf72df96c7bcd12c1e7bbc75 to your computer and use it in GitHub Desktop.
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_`
#!/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