secrets API

secrets

package

API reference for the secrets package.

I
interface

Store

Store is the shared contract for secret backends.

pkg/secrets/secrets.go:19-23
type Store interface

Methods

Set
Method

Parameters

key string
value []byte

Returns

error
func Set(...)
Get
Method

Parameters

key string

Returns

[]byte
error
func Get(...)
Delete
Method

Parameters

key string

Returns

error
func Delete(...)
S
struct
Implements: Store

MemoryStore

MemoryStore is a thread-safe in-memory store intended for tests and ephemeral use.

pkg/secrets/secrets.go:26-29
type MemoryStore struct

Methods

Set
Method

Set stores a copy of the provided secret value.

Parameters

key string
value []byte

Returns

error
func (*MemoryStore) Set(key string, value []byte) error
{
	s.mu.Lock()
	defer s.mu.Unlock()
	s.m[key] = append([]byte(nil), value...)
	return nil
}
Get
Method

Get returns a copy of the stored secret value.

Parameters

key string

Returns

[]byte
error
func (*MemoryStore) Get(key string) ([]byte, error)
{
	s.mu.RLock()
	defer s.mu.RUnlock()

	v, ok := s.m[key]
	if !ok {
		return nil, ErrNotFound
	}

	return append([]byte(nil), v...), nil
}
Delete
Method

Delete removes a secret from the in-memory store.

Parameters

key string

Returns

error
func (*MemoryStore) Delete(key string) error
{
	s.mu.Lock()
	defer s.mu.Unlock()
	delete(s.m, key)
	return nil
}

Fields

Name Type Description
mu sync.RWMutex
m map[string][]byte
F
function

NewMemoryStore

NewMemoryStore creates a new in-memory store.

Returns

pkg/secrets/secrets.go:32-34
func NewMemoryStore() *MemoryStore

{
	return &MemoryStore{m: make(map[string][]byte)}
}
S
struct
Implements: Store

EnvStore

EnvStore provides read-only access to environment variables.

pkg/secrets/secrets.go:66-66
type EnvStore struct

Methods

Set
Method

Set reports that environment-backed stores are read-only.

Parameters

key string
value []byte

Returns

error
func (*EnvStore) Set(key string, value []byte) error
{
	return ErrReadOnly
}
Get
Method

Get returns the environment variable value for the provided key.

Parameters

key string

Returns

[]byte
error
func (*EnvStore) Get(key string) ([]byte, error)
{
	v, ok := os.LookupEnv(key)
	if !ok {
		return nil, ErrNotFound
	}
	return []byte(v), nil
}
Delete
Method

Delete reports that environment-backed stores are read-only.

Parameters

key string

Returns

error
func (*EnvStore) Delete(key string) error
{
	return ErrReadOnly
}
F
function

NewEnvStore

NewEnvStore creates a new environment-backed secret store.

Returns

pkg/secrets/secrets.go:69-71
func NewEnvStore() *EnvStore

{
	return &EnvStore{}
}
S
struct
Implements: Store

VaultStore

VaultStore is a placeholder for an external secret manager implementation.

pkg/secrets/secrets.go:93-93
type VaultStore struct

Methods

Set
Method

Set reports that the placeholder Vault store is not implemented yet.

Parameters

key string
value []byte

Returns

error
func (*VaultStore) Set(key string, value []byte) error
{
	return ErrNotImplemented
}
Get
Method

Get reports that the placeholder Vault store is not implemented yet.

Parameters

key string

Returns

[]byte
error
func (*VaultStore) Get(key string) ([]byte, error)
{
	return nil, ErrNotImplemented
}
Delete
Method

Delete reports that the placeholder Vault store is not implemented yet.

Parameters

key string

Returns

error
func (*VaultStore) Delete(key string) error
{
	return ErrNotImplemented
}
F
function

NewVaultStore

NewVaultStore creates a placeholder Vault-backed store.

Returns

pkg/secrets/secrets.go:96-98
func NewVaultStore() *VaultStore

{
	return &VaultStore{}
}