This is a Node.js package that replaces secrets in configuration files. It works by fetching variables from a remote server, merging them with any additional variables provided, and then replacing placeholders in configuration files with the merged variables. The resulting files are then saved to a specified output directory.
To install this package, run the following command:
npm install @jumpgroup/secret-fetcher
To use this package you can import the:
- 'replaceSecrets',
- 'replaceFiles'
- 'addUpdateSecret'
functions from the package and call it with the necessary parameters or you can use this functions like a command.
If you want to use this like a functions has the following signature:
replaceSecrets(groupKey, groupSecret, input, output, addVariables = {})
Here is an explanation of the parameters:
groupKey
: The key of the group of variables to fetch from the remote server.groupSecret
: The secret key of the group of variables to fetch from the remote server.input
: The input file or directory where the configuration files to replace secrets are located.output
: The output directory where the resulting files will be saved.addVariables
: (Optional) Additional variables to merge with the fetched variables. This parameter should be an object containing the additional variables. If the additional variables are provided as a string, they will be parsed as JSON.
replaceFiles(input, output, addVariables = {})
Here is an explanation of the parameters:
input
: The input file or directory where the configuration files to replace secrets are located.output
: The output directory where the resulting files will be saved.addVariables
: (Optional) Additional variables to merge with the fetched variables. This parameter should be an object containing the additional variables. If the additional variables are provided as a string, they will be parsed as JSON.
addUpdateSecret(groupKey, groupSecret, note, env)
Here is an explanation of the parameters:
groupKey
: The key of the group of variables to fetch from the remote server.groupSecret
: The secret key of the group of variables to fetch from the remote server.note
: The note of the secret to add or update.env
: The environment of the secret to add or update. It can be "staging" or "production" or "site".
If you want to use this like a command you can use the following commands:
To replace secrets in configuration files, use the following command:
secret-fetcher replace-secrets --groupKey myGroup --groupSecret mySecret --input config/**/* --output .config --addVariables '{"myVariable": "myValue"}'
The following options are available:
--groupKey
: The key of the group of variables to fetch from the remote server.--groupSecret
: The secret key of the group of variables to fetch from the remote server.--input
: The input file or directory where the configuration files to replace secrets are located.--output
: The output directory where the resulting files will be saved.--addVariables
: (Optional) Additional variables to merge with the fetched variables. This parameter should be an object containing the additional variables. If the additional variables are provided as a string, they will be parsed as JSON.
To replace secrets in configuration files, use the following command:
secret-fetcher replace-files --input config/**/* --output .config --variables '{"myVariable": "myValue"}'
The following options are available:
--input
: The input file or directory where the configuration files to replace secrets are located.--output
: The output directory where the resulting files will be saved.--variables
: (Optional) Additional variables to merge with the fetched variables. This parameter should be an object containing the additional variables. If the additional variables are provided as a string, they will be parsed as JSON.
To add or update a secret, use the following command:
secret-fetcher add-update-secret --groupKey myGroup --groupSecret mySecret --note myNote --env site
The following options are available:
--groupKey
: The key of the group of variables to fetch from the remote server.--groupSecret
: The secret key of the group of variables to fetch from the remote server.--note
: The note of the secret to add or update.--env
: The environment of the secret to add or update. It can be "staging" or "production" or "site".
import { replaceSecrets } from '@jumpgroup/secret-fetcher';
replaceSecrets('myGroup', 'mySecret', 'config/**/*', '.config');
This will replace secrets in all files in the config directory and its subdirectories and save the resulting files in a directory called ".config".
import { replaceFiles } from '@jumpgroup/secret-fetcher';
replaceFiles('config/**/*', '.config');
This will replace secrets in all files in the config directory and its subdirectories and save the resulting files in a directory called ".config".
import { addUpdateSecret } from '@jumpgroup/secret-fetcher';
addUpdateSecret('myGroup', 'mySecret', 'myNote', 'site');
This will create or update a secret with the note "myNote" using tag and name like "myGroup-site".
secret-fetcher replace-secrets --groupKey myGroup --groupSecret mySecret --input config/**/* --output .config --addVariables '{"myVariable": "myValue"}'
This will replace secrets in all files in the config directory and its subdirectories and save the resulting files in a directory called ".config".
secret-fetcher replace-files --input config/**/* --output .config --variables '{"myVariable": "myValue"}'
This will replace secrets in all files in the config directory and its subdirectories and save the resulting files in a directory called ".config".
secret-fetcher add-update-secret --groupKey myGroup --groupSecret mySecret --note myNote --env site
This will create or update a secret with the note "myNote" using tag and name like "myGroup-site".
This package is licensed under the MIT License.