formatter

package
v0.0.0-...-bed3165 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2021 License: MIT Imports: 8 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bash

func Bash(w io.Writer, creds <-chan Item) error

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

func BashIfEmpty(w io.Writer, creds <-chan Item) error

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

func BashIfNotSet(w io.Writer, creds <-chan Item) error

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

func Dotenv(w io.Writer, creds <-chan Item) error

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.

func JSON

func JSON(w io.Writer, creds <-chan Item) error

JSON implements the Formatter interface.

It outputs the decrypted secrets as JSON:

{
  "my_secret": "my value",
  "another_one": "string with \"quotes\""
}

func YAML

func YAML(w io.Writer, creds <-chan Item) error

YAML implements the Formatter interface.

It outputs the decrypted secrets as YAML:

my_secret: my value
another_one: string with "quotes"

Types

type Formatter

type Formatter func(w io.Writer, creds <-chan Item) error

Formatter is the interface implemented by formatters.

It takes any Writer and a channel of Items (to ease parallelization of KMS calls)

type Item

type Item struct {
	Name      string
	Plaintext string
}

Item is a parameter given to formatters, with the secret name and the associated plaintext

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL