Documentation ¶
Overview ¶
Package formatter is a collection of functions used to format secrets for output. Currently formatters for Bash, JSON and Dotenv are implemented.
Example ¶
Here is how to use the formatters:
items := make(chan formatter.Items, 1) items <- formatter.Item{Name: "secret", Plaintext: "password"} switch format { case "bash": // SECRET='password' formatter.Bash(os.Stdout, items) case "dotenv": // SECRET="password" formatter.Dotenv(os.Stdout, items) case "json": // { "secret": "password" } formatter.JSON(os.Stdout, items) }
Index ¶
- func Bash(w io.Writer, creds <-chan Item) error
- func BashIfEmpty(w io.Writer, creds <-chan Item) error
- func BashIfNotSet(w io.Writer, creds <-chan Item) error
- func Dotenv(w io.Writer, creds <-chan Item) error
- func JSON(w io.Writer, creds <-chan Item) error
- func YAML(w io.Writer, creds <-chan Item) error
- type Formatter
- type Item
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bash ¶
Bash implements the Formatter interface.
It outputs the decrypted secrets in the form:
MY_SECRET='my value' ANOTHER_ONE='string with ''quotes'''
The secret names are capitalized and the no processing is done to the string except replacing all `'` with `”`.
func BashIfEmpty ¶
BashIfEmpty implements the Formatter interface.
It outputs the decrypted secrets in the form:
: ${MY_SECRET:='my value'} : ${ANOTHER_ONE:='string with ''quotes'''}
The secret names are capitalized and the no processing is done to the string except replacing all `'` with `”`.
This will set the environment variable only if it has not been previously set or if it is an empty string.
func BashIfNotSet ¶
BashIfNotSet implements the Formatter interface.
It outputs the decrypted secrets in the form:
: ${MY_SECRET='my value'} : ${ANOTHER_ONE='string with ''quotes'''}
The secret names are capitalized and the no processing is done to the string except replacing all `'` with `”`.
This will set the environment variable only if it has not been previously set.
func Dotenv ¶
Dotenv implements the Formatter interface.
It outputs the decrypted secrets in the form:
MY_SECRET="my value" ANOTHER_ONE="string with \"quotes\""
The secret names are capitalized and the values are quoted as Go strings. Specifically, it uses escape sequences (\t, \n, \xFF, \u0100) for non-ASCII characters and non-printable characters
TODO: Ensure the go syntax for strings is compatible with Dotenv, as it seems to be the case from quick testing.