vaulter

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2023 License: MIT Imports: 7 Imported by: 0

README

vaulter

Simple HashiCorp vault client wrapper for configs that is compatible with gitlab.com/distributed_lab/kit/kv package

Usage example

package example

import (
	"github.com/zspkg/vaulter"
	"gitlab.com/distributed_lab/figure"
	"gitlab.com/distributed_lab/kit/kv"
)

const fooVaultSecretKey = "key"

type FooConfig struct {
	Foo string `fig:"foo_key,required"`
	Bar int    `fig:"bar_secret,required"`
}

func GetFooConfig() (FooConfig, error) {
	var (
		cfg         FooConfig
		vaultGetter = vaulter.MustFromEnv(vaulter.AuthTypeToken)
	)

	fooMap := kv.MustGetStringMap(vaultGetter, fooVaultSecretKey)

	// TODO: figure out config from fooMap with your favorite config library
	if err := figure.Out(&cfg).From(fooMap).Please(); err != nil {
		return cfg, err
	}

	return cfg, nil
}

Documentation

Index

Constants

View Source
const (

	// AuthTypeToken is used for vault client configuration via VAULT_TOKEN environment variable
	AuthTypeToken AuthType = iota
	// AuthTypeCertificate is for another type of vault client configuration (in development)
	AuthTypeCertificate

	EnvVaultPath        = "VAULT_PATH"
	EnvVaultToken       = vault.EnvVaultToken
	EnvVaultKVMountPath = "VAULT_KV_MOUNT_PATH"
)

Variables

View Source
var ErrInvalidEnvs = errors.New("environment variables are not configured properly")

Functions

This section is empty.

Types

type AuthType added in v1.0.1

type AuthType int

type Vaulter

type Vaulter interface{ kv.Getter }

func MustFromEnv

func MustFromEnv(authType AuthType) Vaulter

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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