Hi @DavidRepas ! There are many ways to do this, but I suppose the “best” one depends on your setup. If all you need to do is swap out the MySQL user, I’d recommend simply using an environment variable for this.
So you just use the ${MY_ENV_VAR}
placeholder in your JSON file and then you can create a .env
file locally on your machine that looks like this
MY_ENV_VAR=myLocalPassword
Ensure you have the commandbox-dotenv
module installed (comes out of the box now in CommandBox 5.8.0) and it will load up that env var as your server starts. On production, simply specify a different environment variable, which can be a “proper” server env var, or a docker secret, etc, etc. Just ensure if you use a .env
in production that your web server is blocking access to it.
You can also cheat and only specify the env var in one location and make the other the default value. So, for example, if your JSON file had this:
"password": "${DB_PASSWORD:defaultPassword}"
Then the contents of the DB_PASSWORD
env var would be used if it existed, and when it didn’t the default value would be put in.
And another option that doesn’t require you to touch your JSON file at all would simply be to provide this env var on dev
cfconfig_datasources_yourDSName_password=yourPassword
and that will automatically swap out the password for the yourDSName
datasource regardless of what was in the JSON.
And there are many more options that don’t involve env vars. You could swap out the entire CFConfig.json file for dev/prod, but that feels like overkill just to change a password.
Many options, your choice