keys

package
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2022 License: LGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeText Type = "text"
	TypeEnv       = "env"
	TypeFile      = "file"
)

Variables

This section is empty.

Functions

func RandomCreateFile added in v1.2.2

func RandomCreateFile(data []byte) (string, error)

func RemoveFile added in v1.2.2

func RemoveFile(name string) error

Types

type Key

type Key struct {
	Key     string
	Value   string
	Hyphens int
	Secrets []*Secret
}

Key is one of parsed input

type Keys

type Keys interface {

	// Import parses the input into keys, the secrets of keys are parsed by secretTag.
	// The regexp pattern of secrets is `<%s>(.*?)</%s>|<%s>(.*?)</%s>`. Only one group might be captured.
	// If no secretTag is captured, the entire value of the key will be regarded as a plaintext secret. (i.e. Secret{Text:"Value of the Key", IsEncrypted: false})
	//
	// Example for secretTag:
	//   If secretTag is `kms`, the regexp pattern will be <kms>(.*?)</kms>|<KMS>(.*?)</KMS>.
	//   The first group is lower case of the secret_tag which means plaintext of the secret(i.e. all characters between `<kms>` and `</kms>`). If it is not empty string, `secret.IsEncrypted` will be set to false.
	//   The second group is upper case of the secret_tag which means ciphertext of the secret(i.e. all characters between `<KMS>` and `</KMS>`). If it is not empty string, `secret.IsEncrypted` will be set to true.
	Import(input []string, secretTag string) []Key

	// Export outputs the `keys` to a string formated by the `Keys Type` and writes the string to the `writeCloser`
	// The secrets in the `Key.Value` will be replaced by the current `Key.Secrets`.
	// If `secret.IsEncrypted` is false, the secret will be the `secret.Text` only.
	// If `secret.IsEncrypted` is true, the secret will be the <secretTag>secret.Text</secretTag>.
	Export(keys []Key, secretTag string, writeCloser io.WriteCloser) error

	// Encrypt Decrypt and ReplaceOrignalFile are for file type key
	// Encrypt and Decrypt parses the target file into map struct and decrypt/encrypt directly
	// Because there will be nested data in file type while we use JSON/YAML, it's wasteful to use original way (Import to []Key then decrypt/encrypt) to encrypt/decrypt.
	// It will use DFS to find out string to do the target function, so we prevent it to run it twice.
	// inputs:
	//     input: filePath
	//     secretTag: secretTag
	//     cp: crypto Provider instance
	// outputs:
	//     file data in map struct after encrypt/decrypt
	Encrypt(input string, secretTag string, cp crypto.Crypto) map[string]interface{}
	Decrypt(input string, secretTag string, cp crypto.Crypto) map[string]interface{}

	ReplaceOriginFile(input string, values map[string]interface{}) error
}

Keys defines keys operations

func Get

func Get(t Type) (Keys, error)

Get returns the Keys of a Type is exists

type Secret added in v1.1.0

type Secret struct {
	Text        string
	IsEncrypted bool
}

Secret is one of the secrets of a key

type Type

type Type string

Type of the Keys implemented Keys

Jump to

Keyboard shortcuts

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