Add wild-config-set and wild-secret-set scripts for YAML configuration management

This commit is contained in:
2025-06-25 12:09:42 -07:00
parent 07072d1c72
commit d5d4562e2f
2 changed files with 155 additions and 0 deletions

77
bin/wild-config-set Executable file
View File

@@ -0,0 +1,77 @@
#!/bin/bash
set -e
set -o pipefail
# Usage function
usage() {
echo "Usage: wild-config-set <yaml_key_path> <value>"
echo ""
echo "Set a value in \$WC_HOME/config.yaml using a YAML key path."
echo ""
echo "Examples:"
echo " wild-config-set 'cluster.name' 'my-cluster' # Set cluster name"
echo " wild-config-set 'cloud.domain' 'example.com' # Set domain"
echo " wild-config-set 'cloud.dns.ip' '192.168.1.10' # Set DNS IP"
echo ""
echo "Options:"
echo " -h, --help Show this help message"
}
# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
usage
exit 0
;;
-*)
echo "Unknown option $1"
usage
exit 1
;;
*)
if [ -z "${KEY_PATH}" ]; then
KEY_PATH="$1"
elif [ -z "${VALUE}" ]; then
VALUE="$1"
else
echo "Too many arguments"
usage
exit 1
fi
shift
;;
esac
done
if [ -z "${KEY_PATH}" ]; then
echo "Error: YAML key path is required"
usage
exit 1
fi
if [ -z "${VALUE}" ]; then
echo "Error: Value is required"
usage
exit 1
fi
# Check if WC_HOME is set
if [ -z "${WC_HOME:-}" ]; then
echo "Error: WC_HOME environment variable not set" >&2
exit 1
fi
CONFIG_FILE="${WC_HOME}/config.yaml"
# Create config file if it doesn't exist
if [ ! -f "${CONFIG_FILE}" ]; then
echo "Creating new config file at ${CONFIG_FILE}"
echo "{}" > "${CONFIG_FILE}"
fi
# Use yq to set the value in the YAML file
yq eval ".${KEY_PATH} = \"${VALUE}\"" -i "${CONFIG_FILE}"
echo "Set ${KEY_PATH} = ${VALUE}"

78
bin/wild-secret-set Executable file
View File

@@ -0,0 +1,78 @@
#!/bin/bash
set -e
set -o pipefail
# Usage function
usage() {
echo "Usage: wild-secret-set <yaml_key_path> <value>"
echo ""
echo "Set a value in \$WC_HOME/secrets.yaml using a YAML key path."
echo ""
echo "Examples:"
echo " wild-secret-set 'database.password' 'secret123' # Set database password"
echo " wild-secret-set 'api.keys.github' 'ghp_token123' # Set GitHub API key"
echo " wild-secret-set 'cloudflare.token' 'cf_token456' # Set Cloudflare token"
echo ""
echo "Options:"
echo " -h, --help Show this help message"
}
# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
usage
exit 0
;;
-*)
echo "Unknown option $1"
usage
exit 1
;;
*)
if [ -z "${KEY_PATH}" ]; then
KEY_PATH="$1"
elif [ -z "${VALUE}" ]; then
VALUE="$1"
else
echo "Too many arguments"
usage
exit 1
fi
shift
;;
esac
done
if [ -z "${KEY_PATH}" ]; then
echo "Error: YAML key path is required"
usage
exit 1
fi
if [ -z "${VALUE}" ]; then
echo "Error: Value is required"
usage
exit 1
fi
# Check if WC_HOME is set
if [ -z "${WC_HOME:-}" ]; then
echo "Error: WC_HOME environment variable not set" >&2
exit 1
fi
SECRETS_FILE="${WC_HOME}/secrets.yaml"
# Create secrets file if it doesn't exist
if [ ! -f "${SECRETS_FILE}" ]; then
echo "Creating new secrets file at ${SECRETS_FILE}"
echo "{}" > "${SECRETS_FILE}"
chmod 600 "${SECRETS_FILE}" # Make secrets file readable only by owner
fi
# Use yq to set the value in the YAML file
yq eval ".${KEY_PATH} = \"${VALUE}\"" -i "${SECRETS_FILE}"
echo "Set ${KEY_PATH} = [REDACTED]"