store

package
v29.6.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2026 License: Apache-2.0 Imports: 20 Imported by: 602

Documentation

Overview

Package store provides a generic way to store credentials to connect to virtually any kind of remote system. The term `context` comes from the similar feature in Kubernetes kubectl config files.

Conceptually, a context is a set of metadata and TLS data, that can be used to connect to various endpoints of a remote system. TLS data and metadata are stored separately, so that in the future, we will be able to store sensitive information in a more secure way, depending on the os we are running on (e.g.: on Windows we could use the user Certificate Store, on macOS the user Keychain...).

Current implementation is purely file based with the following structure:

${CONTEXT_ROOT}
  meta/
    <context id>/meta.json: contains context medata (key/value pairs) as
                            well as a list of endpoints (themselves containing
                            key/value pair metadata).
  tls/
    <context id>/endpoint1/: directory containing TLS data for the endpoint1
                             in the corresponding context.

The context store itself has absolutely no knowledge about what a docker endpoint should contain in term of metadata or TLS config. Client code is responsible for generating and parsing endpoint metadata and TLS files. The multi-endpoints approach of this package allows to combine many different endpoints in the same "context".

Context IDs are actually SHA256 hashes of the context name, and are there only to avoid dealing with special characters in context names.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Export

func Export(name string, s Reader) io.ReadCloser

Export exports an existing namespace into an opaque data stream This stream is actually a tarball containing context metadata and TLS materials, but it does not map 1:1 the layout of the context store (don't try to restore it manually without calling store.Import)

func Import

func Import(name string, s Writer, reader io.Reader) error

Import imports an exported context into a store

func Names

func Names(s Lister) ([]string, error)

Names return Metadata names for a Lister

func ValidateContextName

func ValidateContextName(name string) error

ValidateContextName checks a context name is valid.

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

Config is used to configure the metadata marshaler of the context ContextStore

func NewConfig

func NewConfig(contextType TypeGetter, endpoints ...NamedTypeGetter) Config

NewConfig creates a config object

func (Config) ForeachEndpointType

func (c Config) ForeachEndpointType(cb func(string, TypeGetter) error) error

ForeachEndpointType calls cb on every endpoint type registered with the Config

func (Config) SetEndpoint

func (c Config) SetEndpoint(name string, getter TypeGetter)

SetEndpoint set an endpoint typing information

type ContextStore

type ContextStore struct {
	// contains filtered or unexported fields
}

ContextStore implements Store.

func New

func New(dir string, cfg Config) *ContextStore

New creates a store from a given directory. If the directory does not exist or is empty, initialize it

func (*ContextStore) CreateOrUpdate