@jumpgroup/secret-fetcher

1.6.4 • Public • Published

Secrets Fetcher

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.

Installation

To install this package, run the following command:

npm install @jumpgroup/secret-fetcher

Usage

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.

Include as a functions

If you want to use this like a functions has the following signature:

replaceSecrets

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

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

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".

Include as a command

If you want to use this like a command you can use the following commands:

replaceSecrets

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.

replaceFiles

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.

addUpdateSecret

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".

Example Usage

Include as a functions

replaceSecrets

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".

replaceFiles

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".

addUpdateSecret

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".

Include as a command

replaceSecrets

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".

replaceFiles

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".

addUpdateSecret

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".

License

This package is licensed under the MIT License.

Readme

Keywords

none

Package Sidebar

Install

npm i @jumpgroup/secret-fetcher

Weekly Downloads

23

Version

1.6.4

License

MIT

Unpacked Size

23.8 kB

Total Files

5

Last publish

Collaborators

  • lovejade
  • cristiano-f
  • sinsimon19
  • mellinmeg
  • jericam
  • sinsimon
  • fabio.p