spec

package
v0.40.4 Latest Latest
Warning

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

Go to latest
Published: May 19, 2022 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package spec provides builders and parsers for spelling Noms databases, datasets and values.

Index

Constants

View Source
const (
	Separator              = "::"
	DefaultAWSRegion       = "us-west-2"
	DefaultAWSCredsProfile = "default"
)
View Source
const CommitMetaDateFormat = time.RFC3339

Variables

View Source
var ExternalProtocols = map[string]ProtocolImpl{}

Functions

func CommitMetaFromFlags

func CommitMetaFromFlags(ctx context.Context) (*datas.CommitMeta, error)

Return the CommitMeta for an invocation of `noms` with CLI flags.

func CreateDatabaseSpecString

func CreateDatabaseSpecString(protocol, db string) string

func CreateHashSpecString

func CreateHashSpecString(protocol, db string, h hash.Hash) string

func CreateValueSpecString

func CreateValueSpecString(protocol, db, path string) string

func ReadAbsolutePaths

func ReadAbsolutePaths(ctx context.Context, db datas.Database, vrw types.ValueReadWriter, paths ...string) ([]types.Value, error)

ReadAbsolutePaths attempts to parse each path in 'paths' and resolve them. If any path fails to parse correctly or if any path can be resolved to an existing Noms Value, then this function returns (nil, error).

func RegisterCommitMetaFlags

func RegisterCommitMetaFlags(flags *flag.FlagSet)

RegisterCommitMetaFlags registers command line flags used for creating commit meta structs.

Types

type AWSCredentialSource

type AWSCredentialSource int
const (
	InvalidCS AWSCredentialSource = iota - 1

	// Auto will try env first and fall back to role (This is the default)
	AutoCS

	// Role Uses the AWS IAM role of the instance for auth
	RoleCS

	// Env uses the credentials stored in the environment variables AWS_ACCESS_KEY_ID, and AWS_SECRET_ACCESS_KEY
	EnvCS

	// Uses credentials stored in a file
	FileCS
)

func AWSCredentialSourceFromStr

func AWSCredentialSourceFromStr(str string) AWSCredentialSource

func (AWSCredentialSource) String

func (ct AWSCredentialSource) String() string

type AbsolutePath

type AbsolutePath struct {
	// Dataset is the dataset this AbsolutePath is rooted at. Only one of
	// Dataset and Hash should be set.
	Dataset string
	// Hash is the hash this AbsolutePath is rooted at. Only one of Dataset and
	// Hash should be set.
	Hash hash.Hash
	// Path is the relative path from Dataset or Hash. This can be empty. In
	// that case, the AbsolutePath describes the value at either Dataset or
	// Hash.
	Path types.Path
}

AbsolutePath describes the location of a Value within a Noms database.

To locate a value relative to some other value, see Path. To locate a value globally, see Spec.

For more on paths, absolute paths, and specs, see: https://github.com/attic-labs/noms/blob/master/doc/spelling.md.

func NewAbsolutePath

func NewAbsolutePath(str string) (AbsolutePath, error)

NewAbsolutePath attempts to parse 'str' and return an AbsolutePath.

func (AbsolutePath) IsEmpty

func (p AbsolutePath) IsEmpty() bool

func (AbsolutePath) Resolve

func (p AbsolutePath) Resolve(ctx context.Context, db datas.Database, vrw types.ValueReadWriter) (val types.Value, err error)

Resolve returns the Value reachable by 'p' in 'db'.

func (AbsolutePath) String

func (p AbsolutePath) String() (str string)

type ProtocolImpl

type ProtocolImpl interface {
	NewChunkStore(sp Spec) (chunks.ChunkStore, error)
}

type Spec

type Spec struct {
	// Protocol is one of "mem", "aws", "gs", "nbs"
	Protocol string

	// DatabaseName is the name of the Spec's database, which is the string after
	// "protocol:". specs include their leading "//" characters.
	DatabaseName string

	// Options are the SpecOptions that the Spec was constructed with.
	Options SpecOptions

	// Path is nil unless the spec was created with ForPath.
	Path AbsolutePath
	// contains filtered or unexported fields
}

Spec locates a Noms database, dataset, or value globally. Spec caches its database instance so it therefore does not reflect new commits in the db, by (legacy) design.

func ForDatabase

func ForDatabase(spec string) (Spec, error)

ForDatabase parses a spec for a Database.

func ForDatabaseOpts

func ForDatabaseOpts(spec string, opts SpecOptions) (Spec, error)

ForDatabaseOpts parses a spec for a Database.

func ForDataset

func ForDataset(spec string) (Spec, error)

ForDataset parses a spec for a Dataset.

func ForDatasetOpts

func ForDatasetOpts(spec string, opts SpecOptions) (Spec, error)

ForDatasetOpts parses a spec for a Dataset.

func ForPath

func ForPath(spec string) (Spec, error)

ForPath parses a spec for a path to a Value.

func ForPathOpts

func ForPathOpts(spec string, opts SpecOptions) (Spec, error)

ForPathOpts parses a spec for a path to a Value.

func (Spec) Close

func (sp Spec) Close() error

func (Spec) GetDatabase

func (sp Spec) GetDatabase(ctx context.Context) datas.Database

GetDatabase returns the Database instance that this Spec's DatabaseName describes. The same Database instance is returned every time, unless Close is called. If the Spec is closed, it is re-opened with a new Database.

func (Spec) GetDataset

func (sp Spec) GetDataset(ctx context.Context) (ds datas.Dataset)

GetDataset returns the current Dataset instance for this Spec's Database. GetDataset is live, so if Commit is called on this Spec's Database later, a new up-to-date Dataset will returned on the next call to GetDataset. If this is not a Dataset spec, returns nil.

func (Spec) GetVRW

func (sp Spec) GetVRW(ctx context.Context) types.ValueReadWriter

func (Spec) GetValue

func (sp Spec) GetValue(ctx context.Context) (val types.Value, err error)

GetValue returns the Value at this Spec's Path within its Database, or nil if this isn't a Path Spec or if that path isn't found.

func (Spec) Href

func (sp Spec) Href() string

Href treats the Protocol and DatabaseName as a URL, and returns its href. For example, the spec http://example.com/path::ds returns "http://example.com/path". If the Protocol is not "http" or "http", returns an empty string.

func (Spec) NewChunkStore

func (sp Spec) NewChunkStore(ctx context.Context) chunks.ChunkStore

NewChunkStore returns a new ChunkStore instance that this Spec's DatabaseName describes. It's unusual to call this method, GetDatabase is more useful. Unlike GetDatabase, a new ChunkStore instance is returned every time. If there is no ChunkStore, for example remote databases, returns nil.

func (Spec) Pin

func (sp Spec) Pin(ctx context.Context) (Spec, bool)

Pin returns a Spec in which the dataset component, if any, has been replaced with the hash of the HEAD of that dataset. This "pins" the path to the state of the database at the current moment in time. Returns itself if the PathSpec is already "pinned".

func (Spec) String

func (sp Spec) String() string

type SpecOptions

type SpecOptions struct {
	// Authorization token for requests. For example, if the database is HTTP
	// this will used for an `Authorization: Bearer ${authorization}` header.
	Authorization string

	// Region that should be used when creating the aws session
	AWSRegion string

	// The type of credentials that should be used when creating the aws session
	AWSCredSource AWSCredentialSource

	// Credential file to use when using auto or file credentials
	AWSCredFile string
}

SpecOptions customize Spec behavior.

func (*SpecOptions) AwsCredFileOrDefault

func (so *SpecOptions) AwsCredFileOrDefault() string

func (*SpecOptions) AwsRegionOrDefault

func (so *SpecOptions) AwsRegionOrDefault() string

Jump to

Keyboard shortcuts

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