Documentation
¶
Overview ¶
Package segment is the semaphore-cli segment command group: import, add, remove and stat for the members of a dynamic segment in a Valkey or Redis store. The segment is named by its published definition (key, layout, connection and version key) and the connection by the bootstrap file, so nothing that those already say is typed again. No member id is printed or logged: only counts and line numbers are.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoControlPlane is returned when --segments is not given and the bootstrap file has no controlPlane section. ErrNoControlPlane = errors.New("give --segments, or a bootstrap file with a controlPlane section") // ErrNoStore is returned for a connection of the control plane that cannot hold objects. ErrNoStore = errors.New("the connection holds no objects (it must be s3 or file)") // ErrNoSegmentsObject is returned when the manifest lists no segments document. ErrNoSegmentsObject = errors.New("the manifest lists no segments object") )
var ( // ErrNoSegment is returned for a name that the segments document does not define. ErrNoSegment = errors.New("the segments document does not define this segment") // ErrStatic is returned for a segment that has no connection: its members are in the document. ErrStatic = errors.New("the segment is static (no connection): its members are in the document") // ErrNoConnection is returned for a connection that the bootstrap file does not define. ErrNoConnection = errors.New("the bootstrap file does not define the connection of the segment") // ErrNotStore is returned for a connection that is neither valkey nor redis. ErrNotStore = errors.New("the connection of the segment is not a valkey or redis connection") // ErrAmbiguous is returned for a name that two segments documents of the control plane define. ErrAmbiguous = errors.New("more than one segments document defines this segment") )
var ErrNoInput = errors.New("give at least one id, or --from <file|->")
ErrNoInput is the failure of add or remove without an id and without --from.
var ErrNoVersionKey = errors.New("the definition has no version.key to bump")
ErrNoVersionKey is the failure of bump for a definition without a version key.
var ErrSourceConnection = errors.New("no s3 connection for the source")
ErrSourceConnection is returned when the s3 connection of a source cannot be told from the bootstrap file.
Functions ¶
Types ¶
type AddCmd ¶
type AddCmd struct {
Common `embed:""`
From string `help:"${helpSegFrom}" name:"from"`
IDs []string `arg:"" help:"${helpSegIDs}" name:"id" optional:""`
}
AddCmd adds ids.
type BumpCmd ¶
type BumpCmd struct {
Common `embed:""`
}
BumpCmd bumps the version key of a segment.
type Cmd ¶
type Cmd struct {
Add AddCmd `cmd:"" help:"${helpSegAdd}"`
Remove RemoveCmd `cmd:"" help:"${helpSegRemove}"`
Stat StatCmd `cmd:"" help:"${helpSegStat}"`
Bump BumpCmd `cmd:"" help:"${helpSegBump}"`
Import ImportCmd `cmd:"" help:"${helpSegImport}"`
Sync SyncCmd `cmd:"" help:"${helpSegSync}"`
Debug bool `help:"${helpSegDebug}" name:"debug"`
}
Cmd is the segment command group.
type Common ¶
type Common struct {
Config string `help:"${helpSegConfig}" name:"config" short:"c"`
Segments string `help:"${helpSegDoc}" name:"segments"`
Segment string `help:"${helpSegName}" name:"segment" required:"true"`
}
Common are the flags that name the segment and the store.
type Connector ¶
type Connector func(context.Context, *bootstrap.Connection, bootstrap.LoadOptions) (segmentadmin.Store, error)
Connector connects to the store of a connection of the bootstrap file.
type Deps ¶
type Deps struct {
// LookupEnv reads an environment variable (secrets and SEMAPHORE_* overrides).
LookupEnv func(string) (string, bool)
// ReadFile reads the bootstrap file, the segments document and file secrets.
ReadFile func(string) ([]byte, error)
// Stdin is the input of --from -.
Stdin io.Reader
// Open opens the input of --from.
Open func(string) (io.ReadCloser, error)
// Connect connects to a store.
Connect Connector
// NewS3 builds the client of an S3 source. Nil means the connection factory of the relay, which honours
// ConnectionOptions.
NewS3 func(ctx context.Context, spec *connection.S3Spec, name string) (S3Client, error)
// ConnectionOptions are passed to the connection factory (a round tripper that counts requests, for example).
ConnectionOptions []connection.Option
}
Deps are the parts of the outside world that the commands use.
func DefaultDeps ¶
func DefaultDeps() Deps
DefaultDeps returns the dependencies of the real command.
type ImportCmd ¶
type ImportCmd struct {
Common `embed:""`
SourceConnection string `help:"${helpSegSrc}" name:"source-connection"`
From string `help:"${helpSegFrom}" name:"from" required:"true"`
Format string `default:"lines" enum:"lines,csv" help:"${helpSegFormat}" name:"format"`
MaxObjects int `default:"1000" help:"${helpSegMaxObj}" name:"max-objects"`
Column int `default:"1" help:"${helpSegColumn}" name:"column"`
BatchSize int `default:"1000" help:"${helpSegBatch}" name:"batch-size"`
MaxLineBytes int `default:"65536" help:"${helpSegMaxLine}" name:"max-line-bytes"`
TempTTL time.Duration `default:"1h" help:"${helpSegTTL}" name:"temp-ttl"`
AllowEmpty bool `help:"${helpSegEmpty}" name:"allow-empty"`
DryRun bool `help:"${helpSegDry}" name:"dry-run"`
}
ImportCmd replaces the members of a segment.
func (*ImportCmd) Run ¶
func (cmd *ImportCmd) Run(ctx context.Context, parent *Cmd, streams *helper.Streams, deps *Deps) error
Run imports the ids. A file or standard input is opened before the store is, so that a bad input fails first; an s3 source needs the bootstrap file, which the session has read.
type RemoveCmd ¶
type RemoveCmd struct {
Common `embed:""`
From string `help:"${helpSegFrom}" name:"from"`
IDs []string `arg:"" help:"${helpSegIDs}" name:"id" optional:""`
}
RemoveCmd removes ids.
type S3Client ¶
type S3Client interface {
HeadObject(ctx context.Context, in *s3.HeadObjectInput, opts ...func(*s3.Options)) (*s3.HeadObjectOutput, error)
GetObject(ctx context.Context, in *s3.GetObjectInput, opts ...func(*s3.Options)) (*s3.GetObjectOutput, error)
ListObjectsV2(
ctx context.Context, in *s3.ListObjectsV2Input, opts ...func(*s3.Options),
) (*s3.ListObjectsV2Output, error)
}
S3Client is the part of the S3 client that a source needs: *s3.Client implements it.
type S3Objects ¶
type S3Objects struct {
// contains filtered or unexported fields
}
S3Objects is a bucket of an S3 client as segmentadmin.ObjectAPI.
func NewS3Objects ¶
NewS3Objects returns the objects of a bucket, read with client.
func (*S3Objects) Get ¶
Get implements segmentadmin.ObjectAPI: one GET, conditional on the ETag, whose body is read as it arrives.
func (*S3Objects) Head ¶
func (o *S3Objects) Head(ctx context.Context, key string) (segmentadmin.ObjectInfo, error)
Head implements segmentadmin.ObjectAPI.
func (*S3Objects) List ¶
func (o *S3Objects) List(ctx context.Context, prefix, token string) (segmentadmin.ObjectPage, error)
List implements segmentadmin.ObjectAPI.
type StatCmd ¶
type StatCmd struct {
Common `embed:""`
ScanLimit int `default:"100000" help:"${helpSegScan}" name:"scan-limit"`
}
StatCmd shows a segment.
type SyncCmd ¶
type SyncCmd struct {
Common `embed:""`
SourceConnection string `help:"${helpSegSrc}" name:"source-connection"`
From string `help:"${helpSegFrom}" name:"from" required:"true"`
Format string `default:"lines" enum:"lines,csv" help:"${helpSegFormat}" name:"format"`
MaxObjects int `default:"1000" help:"${helpSegMaxObj}" name:"max-objects"`
Column int `default:"1" help:"${helpSegColumn}" name:"column"`
BatchSize int `default:"1000" help:"${helpSegBatch}" name:"batch-size"`
MaxLineBytes int `default:"65536" help:"${helpSegMaxLine}" name:"max-line-bytes"`
TempTTL time.Duration `default:"1h" help:"${helpSegTTL}" name:"temp-ttl"`
Interval time.Duration `default:"1m" help:"${helpSegInterval}" name:"interval"`
AllowEmpty bool `help:"${helpSegEmpty}" name:"allow-empty"`
Once bool `help:"${helpSegOnce}" name:"once"`
}
SyncCmd keeps the segment in step with an s3 object or prefix.
func (*SyncCmd) Run ¶
func (cmd *SyncCmd) Run(ctx context.Context, parent *Cmd, streams *helper.Streams, deps *Deps) error
Run checks the source, and imports it when its fingerprint is not the one recorded with the live set. It runs until the context ends, or once with --once: then a failed round is the error of the command.