config

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2024 License: Apache-2.0 Imports: 29 Imported by: 1

Documentation

Overview

Package config defines the configuration settings shared by the subcommands of the ffs command-line tool.

Index

Constants

View Source
const DefaultPath = "$HOME/.config/ffs/config.yml"

DefaultPath is the configuration file path used if not overridden by the FFS_CONFIG environment variable.

Variables

This section is empty.

Functions

func Dial

func Dial(ntype, addr string) (net.Conn, error)

Dial calls net.Dial with the specified arguments. If they succeed and ntype is not "unix", the resulting connection is wrapped to redial the address if the connection fails during a read or write (ECONNRESET or ECONNABORTED).

If redial succeeds, the failed Read or Write operation is transparently retried; otherwise the original error is propagated to the caller.

func ExpandString

func ExpandString(s *string)

ExpandString calls os.ExpandEnv to expand environment variables in *s. The value of *s is replaced.

func FormatKey added in v0.1.12

func FormatKey(key string) string

FormatKey converts key into a base64 value.

func LoadIndex

func LoadIndex(ctx context.Context, s blob.CAS, key string) (*index.Index, error)

LoadIndex loads the contents of an index blob.

func ParseKey

func ParseKey(s string) (string, error)

ParseKey parses the string encoding of a key. A key must be a hex string, a base64 string, or a literal string prefixed with "@":

@foo     encodes "foo"
@@foo    encodes "@foo"
414243   encodes "ABC"
eHl6enk= encodes "xyzzy"

func Path

func Path() string

Path returns the effective configuration file path. If FFS_CONFIG is set, its value is used; otherwise DefaultPath is expanded.

func PrintableKey

func PrintableKey(key string) any

PrintableKey converts key into a value that will marshal into JSON as a sensible human-readable string.

func SplitPath

func SplitPath(s string) (first, rest string)

SplitPath parses s as a slash-separated path specification. The first segment of s identifies the storage key of a root or file, the rest indicates a sequence of child names starting from that file. The rest may be empty.

func ToJSON

func ToJSON(msg any) string

ToJSON converts a value to indented JSON.

Types

type CAS

type CAS struct {
	affixed.CAS
}

CAS is a wrapper around a blob.CAS that adds methods to expose the root and data buckets.

Tools using this package partition the keyspace into two buckets. The "data" bucket comprises all content-addressed keys; the "roots" bucket is for all other (non-content-addressed) keys. This is mapped onto the underlying store by appending the suffix "." (Unicode 46) to data keys, and "@" (Unicode 64) to root keys.

The methods of the CAS access the data keyspace by default; call Roots to derive a view of the root keyspace.

func (CAS) Roots

func (c CAS) Roots() blob.CAS

Roots returns the root view of c.

func (CAS) SyncKeys added in v0.5.1

func (c CAS) SyncKeys(ctx context.Context, keys []string) ([]string, error)

SyncKeys implements the extension method of blob.SyncKeyer.

type Filter

type Filter struct {
	Base string
	Rule []Rule
	// contains filtered or unexported fields
}

Filter is a collection of path filters used to control what parts of a file tree get copied by "put" operations. Each line of a filter file specifies a glob matching a filename. By default, all files are included, and any file matching a rule is filtered out.

Each directory is checked for a filter file, which governs paths under that directory. If a rule is prefixed with "!", a match of that rule inverts the sense of the parent directory for that path, including if it was filtered and vice versa.

func (*Filter) Load

func (f *Filter) Load(name string) (*Filter, error)

Load loads a list of path filters from a file.

Blank lines and lines beginning with "#" are ignored. Otherwise, each line gives a path glob that the filter should match.

func (*Filter) Match

func (f *Filter) Match(path string) bool

Match reports whether path should be excluded.

type PathInfo

type PathInfo struct {
	Path    string     // the original input path (unparsed)
	Base    *file.File // the root or starting file of the path
	BaseKey string     // the storage key of the base file
	File    *file.File // the target file of the path
	FileKey string     // the storage key of the target file
	Root    *root.Root // the specified root, or nil if none
	RootKey string     // the key of root, or ""
}

PathInfo is the result of parsing and opening a path spec.

func OpenPath

func OpenPath(ctx context.Context, s CAS, path string) (*PathInfo, error)

OpenPath parses and opens the specified path in s. The path has either the form "<root-key>/some/path" or "@<file-key>/some/path".

func (*PathInfo) Flush

func (p *PathInfo) Flush(ctx context.Context) (string, error)

Flush flushes the base file to reflect any changes and returns its updated storage key. If p is based on a root, the root is also updated and saved.

type Rule

type Rule struct {
	*regexp.Regexp      // the compiled glob expression
	Negate         bool // whether this rule negates a parent match
}

A Rule is a single filter rule.

type Settings

type Settings struct {
	// The default address for the blob store service (required).  This must be
	// either a store tag (@name) or an address.
	DefaultStore string `json:"defaultStore" yaml:"default-store"`

	// Enable debug logging for the storage service.
	EnableDebugLogging bool `json:"enableDebugLogging" yaml:"enable-debug-logging"`

	// Well-known store specifications, addressable by tag.
	Stores []*StoreSpec `json:"stores" yaml:"stores"`
}

Settings represents the stored configuration settings for the ffs tool.

func Load

func Load(path string) (*Settings, error)

Load reads and parses the contents of a config file from path. If the specified path does not exist, an empty config is returned without error.

func (*Settings) FindAddress

func (s *Settings) FindAddress() (string, bool)

FindAddress reports whether s has a storage server address, and returns it if so. If a tag was selected but not matched, it is returned.

func (*Settings) OpenStore

func (s *Settings) OpenStore(ctx context.Context) (CAS, error)

OpenStore connects to the store service address in the configuration. The caller is responsible for closing the store when it is no longer needed.

func (*Settings) OpenStoreAddress

func (s *Settings) OpenStoreAddress(_ context.Context, addr string) (CAS, error)

OpenStoreAddress connects to the store service at addr. The caller is responsible for closing the store when it is no longer needed.

func (*Settings) ResolveAddress

func (s *Settings) ResolveAddress(addr string) string

ResolveAddress resolves the given address against the settings. If addr is of the form @tag and that tag exists in the settings, the expanded form of the tag is returned; otherwise addr is returned unmodified.

func (*Settings) WithStore

func (s *Settings) WithStore(ctx context.Context, f func(CAS) error) error

WithStore calls f with a store opened from the configuration. The store is closed after f returns. The error returned by f is returned by WithStore.

func (*Settings) WithStoreAddress

func (s *Settings) WithStoreAddress(ctx context.Context, addr string, f func(CAS) error) error

WithStoreAddress calls f with a store opened at addr. The store is closed after f returns. The error returned by f is returned by WithStore.

type StoreSpec

type StoreSpec struct {
	Tag     string `json:"tag" yaml:"tag"`
	Address string `json:"address" yaml:"address"`
}

A StoreSpec associates a tag (handle) with a storage address.

Jump to

Keyboard shortcuts

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