Documentation
¶
Overview ¶
Package store resolves named connections from typed Connection resources (connection/crd) kept as files, in layers a later one of which overrides an earlier one by name: by default the connections every Flanksource tool shares, then an app's own, then the working directory's. A Store attached to a context (Attach) answers connection:// references before the connections table does.
Index ¶
- Constants
- func ConfigDir(name string) (string, error)
- type Entry
- type Layer
- type Store
- func (s *Store) Attach(ctx dbcontext.Context) dbcontext.Context
- func (s *Store) Delete(layer, reference string) error
- func (s *Store) Entries() ([]Entry, error)
- func (s *Store) Find(reference string) (*Entry, error)
- func (s *Store) Layers() []Layer
- func (s *Store) ListConnections() ([]*models.Connection, error)
- func (s *Store) ResolveConnection(_ dbcontext.Context, reference string) (*models.Connection, error)
- func (s *Store) Save(layer string, resource *crd.Connection) error
Constants ¶
const ( LayerGlobal = "global" LayerApp = "app" LayerCWD = "cwd" )
Default layer names.
const GlobalApp = "flanksource"
GlobalApp is the config dir name the connections every Flanksource tool shares live under.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Entry ¶
type Entry struct {
Layer Layer
Path string
Connection models.Connection
// Problem is why the file does not define a usable connection; the
// connection then carries it in Warnings, and hydrating it fails.
Problem error
}
Entry is one connection a layer's file defines.
type Layer ¶
type Layer struct {
// Name identifies the layer, such as "global", "app" or "cwd".
Name string
Dir string
}
Layer is a directory of connection files.
func DefaultLayers ¶
DefaultLayers are the connections every Flanksource tool shares (<config>/flanksource/connections), then app's own (<config>/<app>/connections), then the working directory's (./.connections), each overriding the one before.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the connections its layers' files define, a later layer's connection replacing an earlier one's of the same namespace and name. It reads the files on every call, so an edit applies at once.
func (*Store) Attach ¶
Attach is ctx answering connection references from the store first, then from the resolver ctx already had, then from the connections table.
func (*Store) Delete ¶
Delete removes the file in layer that defines the connection reference names; one the layer does not define is os.ErrNotExist.
func (*Store) Entries ¶
Entries are the entries in effect, by namespace and name, each with the layer and file that define it.
func (*Store) Find ¶
Find is the entry in effect that reference names, with the layer and file that define it, on the terms of ResolveConnection: (nil, nil) for a reference the store does not define.
func (*Store) ListConnections ¶
func (s *Store) ListConnections() ([]*models.Connection, error)
ListConnections are the connections in effect, by namespace and name.
func (*Store) ResolveConnection ¶
func (s *Store) ResolveConnection(_ dbcontext.Context, reference string) (*models.Connection, error)
ResolveConnection is the connection reference names: its id, connection://name, connection://namespace/name, the deprecated connection://type/namespace/name, or a bare name. A connection with no namespace answers any namespace a reference names that defines no connection of that name. It is (nil, nil) for a reference the store does not define, and an error for a name more than one namespace defines. A file that defines no usable connection resolves to a connection carrying the problem in Warnings, which dbcontext.HydrateConnection refuses to use. It is a dbcontext.ConnectionResolver.