provider

package
v1.3.27 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package provider provides the building blocks for creating a provider.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotSupported = customerror.New("not supported", customerror.WithStatusCode(http.StatusBadRequest))

ErrNotSupported is the error returned when a provider does not support some operation, e.g., Load (read secrets).

Functions

func ExportToEnvVar

func ExportToEnvVar(p IProvider, key string, value interface{}) (string, error)

ExportToEnvVar exports the given key and value to the environment.

NOTE: If override is `true`, it'll override existing environment variables!

Types

type IProvider

type IProvider interface {
	// ExportToStruct exports the loaded configuration to the given struct.
	ExportToStruct(v any) error

	// GetName returns the name of the provider.
	GetName() string

	// GetLogger returns the logger.
	GetLogger() *logging.Logger

	// GetOverride returns the override flag.
	GetOverride() bool

	// GetRawValue returns the raw value flag.
	GetRawValue() bool

	// Load retrieves the configuration, and exports it to the environment.
	//
	// NOTE: Not all providers allow loading secrets, for example, GitHub. They
	// are designed to be write-only stores of information. This is a security
	// measure to prevent exposure of sensitive data. If that's the case, an
	// error ErrNotSupported is returned.
	Load(ctx context.Context, opts ...option.LoadKeyFunc) (map[string]string, error)

	// Write stores a new secret in the Vault.
	Write(ctx context.Context, values map[string]interface{}, opts ...option.WriteFunc) error
}

IProvider defines what a provider does.

type Provider

type Provider struct {
	// Logger is provider's logger.
	Logger *logging.Logger `json:"-" validate:"required"`

	// Name is the name of the provider.
	Name string `json:"name" validate:"required,gte=3,lte=50"`

	// Override is the flag that indicates if the provider should override
	// existing environment variables. Default is `false`.
	Override bool `json:"override"`

	// RawValue is the flag that indicates if the provider should not parse
	// (escaping sequence, etc) values. Default is `false`.
	RawValue bool `json:"rawValue"`
}

Provider contains common settings for all providers.

func New

func New(name string, override bool, rawValue bool) (*Provider, error)

New creates a new provider.

func (*Provider) ExportToStruct added in v0.0.2

func (p *Provider) ExportToStruct(v any) error

ExportToStruct exports the loaded configuration to the given struct.

func (*Provider) GetLogger

func (p *Provider) GetLogger() *logging.Logger

GetLogger returns the logger.

func (*Provider) GetName added in v1.1.32

func (p *Provider) GetName() string

GetName returns the name of the provider.

func (*Provider) GetOverride

func (p *Provider) GetOverride() bool

GetOverride returns the override flag.

func (*Provider) GetRawValue added in v1.2.17

func (p *Provider) GetRawValue() bool

GetRawValue returns the raw value flag.

Jump to

Keyboard shortcuts

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