Documentation
¶
Index ¶
- Constants
- Variables
- func Add(name string, repoConf ConfigMap) error
- func BleveIndexPath(repo Repo) string
- func Remove(name string) error
- func Rename(oldName, newName string) error
- func SetConfig(name string, repoConf ConfigMap) error
- func ToggleEnabled(name string) error
- func UpdateRepoIndex(ctx context.Context, repo Repo) error
- type CodedError
- type Config
- type ConfigMap
- type ErrTMIDConflict
- type FileRepo
- func (f *FileRepo) CanonicalRoot() string
- func (f *FileRepo) CheckIntegrity(ctx context.Context, filter model.ResourceFilter) (results []model.CheckResult, err error)
- func (f *FileRepo) Delete(ctx context.Context, id string) error
- func (f *FileRepo) DeleteAttachment(ctx context.Context, ref model.AttachmentContainerRef, attachmentName string) error
- func (f *FileRepo) Fetch(ctx context.Context, id string) (string, []byte, error)
- func (f *FileRepo) FetchAttachment(ctx context.Context, ref model.AttachmentContainerRef, attachmentName string) ([]byte, error)
- func (f *FileRepo) GetTMMetadata(ctx context.Context, tmID string) ([]model.FoundVersion, error)
- func (f *FileRepo) Import(ctx context.Context, id model.TMID, raw []byte, opts ImportOptions) (ImportResult, error)
- func (f *FileRepo) ImportAttachment(ctx context.Context, container model.AttachmentContainerRef, ...) error
- func (f *FileRepo) Index(ctx context.Context, ids ...string) error
- func (f *FileRepo) List(ctx context.Context, search *model.Filters) (model.SearchResult, error)
- func (f *FileRepo) ListCompletions(ctx context.Context, kind string, args []string, toComplete string) ([]string, error)
- func (f *FileRepo) Spec() model.RepoSpec
- func (f *FileRepo) Versions(ctx context.Context, name string) ([]model.FoundVersion, error)
- type HttpRepo
- func (h *HttpRepo) CanonicalRoot() string
- func (h *HttpRepo) CheckIntegrity(ctx context.Context, filter model.ResourceFilter) (results []model.CheckResult, err error)
- func (h *HttpRepo) Delete(ctx context.Context, id string) error
- func (h *HttpRepo) DeleteAttachment(ctx context.Context, container model.AttachmentContainerRef, ...) error
- func (h *HttpRepo) Fetch(ctx context.Context, id string) (string, []byte, error)
- func (h *HttpRepo) FetchAttachment(ctx context.Context, container model.AttachmentContainerRef, ...) ([]byte, error)
- func (h *HttpRepo) GetTMMetadata(ctx context.Context, tmID string) ([]model.FoundVersion, error)
- func (h *HttpRepo) Import(ctx context.Context, id model.TMID, raw []byte, opts ImportOptions) (ImportResult, error)
- func (h *HttpRepo) ImportAttachment(ctx context.Context, container model.AttachmentContainerRef, ...) error
- func (h *HttpRepo) Index(context.Context, ...string) error
- func (h *HttpRepo) List(ctx context.Context, search *model.Filters) (model.SearchResult, error)
- func (h *HttpRepo) ListCompletions(ctx context.Context, kind string, args []string, toComplete string) ([]string, error)
- func (h *HttpRepo) Spec() model.RepoSpec
- func (h *HttpRepo) Versions(ctx context.Context, name string) ([]model.FoundVersion, error)
- type IdConflictType
- type ImportOptions
- type ImportResult
- type ImportResultType
- type Repo
- type RepoAccessError
- type S3Client
- type S3ObjectInfo
- type S3Repo
- func (s *S3Repo) CanonicalRoot() string
- func (s *S3Repo) CheckIntegrity(ctx context.Context, filter model.ResourceFilter) (results []model.CheckResult, err error)
- func (s *S3Repo) Delete(ctx context.Context, id string) error
- func (s *S3Repo) DeleteAttachment(ctx context.Context, ref model.AttachmentContainerRef, attachmentName string) error
- func (s *S3Repo) Fetch(ctx context.Context, id string) (string, []byte, error)
- func (s *S3Repo) FetchAttachment(ctx context.Context, ref model.AttachmentContainerRef, attachmentName string) ([]byte, error)
- func (s *S3Repo) GetTMMetadata(ctx context.Context, tmID string) ([]model.FoundVersion, error)
- func (s *S3Repo) Import(ctx context.Context, id model.TMID, raw []byte, opts ImportOptions) (ImportResult, error)
- func (s *S3Repo) ImportAttachment(ctx context.Context, container model.AttachmentContainerRef, ...) error
- func (s *S3Repo) Index(ctx context.Context, ids ...string) error
- func (s *S3Repo) List(ctx context.Context, search *model.Filters) (model.SearchResult, error)
- func (s *S3Repo) ListCompletions(ctx context.Context, kind string, args []string, toComplete string) ([]string, error)
- func (s *S3Repo) Spec() model.RepoSpec
- func (s *S3Repo) Versions(ctx context.Context, name string) ([]model.FoundVersion, error)
- type TmcRepo
- func (t *TmcRepo) CanonicalRoot() string
- func (t *TmcRepo) CheckIntegrity(ctx context.Context, filter model.ResourceFilter) (results []model.CheckResult, err error)
- func (t *TmcRepo) Delete(ctx context.Context, id string) error
- func (t *TmcRepo) DeleteAttachment(ctx context.Context, container model.AttachmentContainerRef, ...) error
- func (t *TmcRepo) Fetch(ctx context.Context, id string) (string, []byte, error)
- func (t *TmcRepo) FetchAttachment(ctx context.Context, container model.AttachmentContainerRef, ...) ([]byte, error)
- func (t *TmcRepo) GetSubRepos(ctx context.Context) ([]model.RepoDescription, error)
- func (t *TmcRepo) GetTMMetadata(ctx context.Context, tmID string) ([]model.FoundVersion, error)
- func (t *TmcRepo) Import(ctx context.Context, id model.TMID, raw []byte, opts ImportOptions) (ImportResult, error)
- func (t *TmcRepo) ImportAttachment(ctx context.Context, container model.AttachmentContainerRef, ...) error
- func (t *TmcRepo) Index(context.Context, ...string) error
- func (t *TmcRepo) List(ctx context.Context, search *model.Filters) (model.SearchResult, error)
- func (t *TmcRepo) ListCompletions(ctx context.Context, kind string, args []string, toComplete string) ([]string, error)
- func (t *TmcRepo) Spec() model.RepoSpec
- func (t *TmcRepo) Versions(ctx context.Context, name string) ([]model.FoundVersion, error)
- type Union
- func (u *Union) Fetch(ctx context.Context, id string) (string, []byte, error, []*RepoAccessError)
- func (u *Union) GetTMMetadata(ctx context.Context, tmID string) ([]model.FoundVersion, []*RepoAccessError)
- func (u *Union) List(ctx context.Context, search *model.Filters) (model.SearchResult, []*RepoAccessError)
- func (u *Union) ListCompletions(ctx context.Context, kind string, args []string, toComplete string) []string
- func (u *Union) Search(ctx context.Context, query string) (model.SearchResult, []*RepoAccessError)
- func (u *Union) Versions(ctx context.Context, name string) ([]model.FoundVersion, []*RepoAccessError)
Constants ¶
View Source
const ( IdConflictSameContent = iota + 1 IdConflictSameTimestamp )
View Source
const ( KeyRepos = "repos" KeyRepoType = "type" KeyRepoLoc = "loc" KeyRepoAuth = "auth" KeyRepoHeaders = "headers" KeyRepoEnabled = "enabled" KeyRepoDescription = "description" KeyRepoAWSRegion = "aws_region" KeyRepoAWSBucket = "aws_bucket" KeyRepoAWSAccessKeyId = "aws_access_key_id" KeyRepoAWSSecretAccessKey = "aws_secret_access_key" AuthMethodNone = "none" AuthMethodBearerToken = "bearer" AuthMethodBasic = "basic" RepoTypeFile = "file" RepoTypeHttp = "http" RepoTypeTmc = "tmc" RepoTypeS3 = "s3" CompletionKindNames = "names" CompletionKindFetchNames = "fetchNames" CompletionKindNamesOrIds = "namesOrIds" CompletionKindAttachments = "attachments" RepoConfDir = ".tmc" IndexFilename = "tm-catalog.toc.json" TmNamesFile = "tmnames.txt" TmIgnoreFile = ".tmcignore" )
View Source
const ( ImportResultOK = ImportResultType(iota + 1) ImportResultWarning // imported but with warning ImportResultError // not imported because of error )
View Source
const RelFileUriPlaceholder = "{{ID}}"
View Source
const (
TMExt = ".tm.json"
)
Variables ¶
View Source
var ( ErrAmbiguous = errors.New("multiple repos configured, but target repo not specified") ErrRepoNotFound = errors.New("repo not found") ErrInvalidRepoName = errors.New("invalid repo name") ErrRepoExists = errors.New("named repo already exists") ErrAttachmentExists = errors.New("attachment already exists") ErrInvalidErrorCode = errors.New("invalid error code") ErrInvalidCompletionParams = errors.New("invalid completion parameters") ErrNotSupported = errors.New("method not supported") ErrNoIndex = errors.New("no table of contents found. Run `index` for this repo") )
View Source
var All = func() ([]Repo, error) { conf, err := ReadConfig() if err != nil { return nil, err } conf = filterEnabled(conf) var rs []Repo for n, rc := range conf { r, err := createRepo(rc, model.NewRepoSpec(n)) if err != nil { return rs, err } rs = append(rs, r) } return rs, err }
View Source
var ErrRootInvalid = errors.New("root is not a directory")
View Source
var ErrS3NotExists = errors.New("file does not exist in S3")
View Source
var ErrS3Op = errors.New("operational error")
View Source
var ErrS3Unknown = errors.New("unknown error")
View Source
var Get = func(spec model.RepoSpec) (Repo, error) { if spec.Dir() != "" { if spec.RepoName() != "" { return nil, fmt.Errorf("could not initialize a repo instance for %s: %w\ncheck config", spec, model.ErrInvalidSpec) } return NewFileRepo(map[string]any{KeyRepoType: "file", KeyRepoLoc: spec.Dir()}, spec) } repos, err := ReadConfig() if err != nil { return nil, fmt.Errorf("could not initialize a repo instance for %s: could not read config: %w", spec, err) } repos = filterEnabled(repos) parent, child := splitRepoName(spec.RepoName()) spec = model.NewRepoSpec(parent) rc, ok := repos[parent] if parent == "" { switch len(repos) { case 0: return nil, fmt.Errorf("could not initialize a repo instance for %s: %w\ncheck config", spec, ErrRepoNotFound) case 1: for n, v := range repos { rc = v spec = model.NewRepoSpec(n) } default: return nil, fmt.Errorf("could not initialize a repo instance for %s: %w\ncheck config", spec, ErrAmbiguous) } } else { if !ok { return nil, fmt.Errorf("could not initialize a repo instance for %s: %w\ncheck config", spec, ErrRepoNotFound) } } if child != "" { rc[keySubRepo] = child } repo, err := createRepo(rc, spec) if err != nil { return nil, fmt.Errorf("could not initialize a repo instance for %s: %w\ncheck config", spec, err) } return repo, err }
View Source
var GetDescriptions = func(ctx context.Context, spec model.RepoSpec) ([]model.RepoDescription, error) { if spec.Dir() != "" { r := model.RepoDescription{ Name: spec.Dir(), Type: RepoTypeFile, Description: "Repo generated from the directory specified in the arguments of serve command", } return []model.RepoDescription{r}, nil } conf, err := ReadConfig() if err != nil { return nil, err } conf = filterEnabled(conf) var rs []model.RepoDescription for n, rc := range conf { if spec.RepoName() == "" || n == spec.RepoName() { ds, _ := rc[KeyRepoDescription].(string) r := model.RepoDescription{ Name: n, Type: fmt.Sprintf("%v", rc[KeyRepoType]), Description: ds, } rs = append(rs, r) } } rs, err = expandTmcRepos(ctx, rs) return rs, err }
GetDescriptions returns the list of descriptions of repositories that could be used as targets for write operations or be returned as "found-in" sources when reading from catalog
View Source
var SupportedTypes = []string{RepoTypeFile, RepoTypeHttp, RepoTypeTmc, RepoTypeS3}
View Source
var ValidRepoNameRegex = regexp.MustCompile("^[a-zA-Z0-9][\\w\\-_:]*$")
Functions ¶
func BleveIndexPath ¶ added in v0.1.3
func ToggleEnabled ¶
Types ¶
type CodedError ¶
type CodedError interface {
Code() string
}
type Config ¶
func ReadConfig ¶
type ConfigMap ¶ added in v0.1.3
func AsRepoConfig ¶
func NewRepoConfig ¶ added in v0.1.3
type ErrTMIDConflict ¶
type ErrTMIDConflict struct {
Type IdConflictType
ExistingId string
}
func ParseErrTMIDConflict ¶
func ParseErrTMIDConflict(errCode string) (*ErrTMIDConflict, error)
func (*ErrTMIDConflict) Code ¶
func (e *ErrTMIDConflict) Code() string
Code returns a machine-readable string error code, which can be parsed by ParseErrTMIDConflict
func (*ErrTMIDConflict) Error ¶
func (e *ErrTMIDConflict) Error() string
type FileRepo ¶
type FileRepo struct {
// contains filtered or unexported fields
}
FileRepo implements a Repo TM repository backed by a file system
func (*FileRepo) CanonicalRoot ¶ added in v0.1.3
func (*FileRepo) CheckIntegrity ¶ added in v0.1.3
func (f *FileRepo) CheckIntegrity(ctx context.Context, filter model.ResourceFilter) (results []model.CheckResult, err error)
func (*FileRepo) DeleteAttachment ¶
func (*FileRepo) FetchAttachment ¶
func (*FileRepo) GetTMMetadata ¶
func (*FileRepo) Import ¶
func (f *FileRepo) Import(ctx context.Context, id model.TMID, raw []byte, opts ImportOptions) (ImportResult, error)
func (*FileRepo) ImportAttachment ¶
func (f *FileRepo) ImportAttachment(ctx context.Context, container model.AttachmentContainerRef, attachment model.Attachment, content []byte, force bool) error
func (*FileRepo) ListCompletions ¶
type HttpRepo ¶
type HttpRepo struct {
// contains filtered or unexported fields
}
HttpRepo implements a Repo backed by a http server. It does not allow writing to the repository and is thus a read-only view
func (*HttpRepo) CanonicalRoot ¶ added in v0.1.3
func (*HttpRepo) CheckIntegrity ¶ added in v0.1.3
func (h *HttpRepo) CheckIntegrity(ctx context.Context, filter model.ResourceFilter) (results []model.CheckResult, err error)
func (*HttpRepo) DeleteAttachment ¶
func (*HttpRepo) FetchAttachment ¶
func (*HttpRepo) GetTMMetadata ¶
func (*HttpRepo) Import ¶
func (h *HttpRepo) Import(ctx context.Context, id model.TMID, raw []byte, opts ImportOptions) (ImportResult, error)
func (*HttpRepo) ImportAttachment ¶
func (h *HttpRepo) ImportAttachment(ctx context.Context, container model.AttachmentContainerRef, attachment model.Attachment, content []byte, force bool) error
func (*HttpRepo) ListCompletions ¶
type IdConflictType ¶
type IdConflictType int
func (IdConflictType) String ¶
func (t IdConflictType) String() string
type ImportOptions ¶
type ImportResult ¶
type ImportResult struct {
Type ImportResultType `json:"type"`
// TmID is not empty when the result is successful, i.e. Type is OK or Warning
TmID string `json:"-"`
Message string `json:"message,omitempty"`
// Err is not nil when there was an ID conflict or another error during import, i.e. Type is TMExists or Warning or Error
Err error `json:"-"`
}
func ImportResultFromError ¶
func ImportResultFromError(err error) (ImportResult, error)
func (ImportResult) IsSuccessful ¶
func (r ImportResult) IsSuccessful() bool
func (ImportResult) String ¶
func (r ImportResult) String() string
type ImportResultType ¶
type ImportResultType int
func (ImportResultType) MarshalJSON ¶ added in v0.1.3
func (t ImportResultType) MarshalJSON() ([]byte, error)
func (ImportResultType) String ¶
func (t ImportResultType) String() string
type Repo ¶
type Repo interface {
// Import writes the Thing Model file into the path under root that corresponds to id.
// Returns ErrTMIDConflict if the same file is already stored with a different timestamp or
// there is a file with the same semantic version and timestamp but different content
Import(ctx context.Context, id model.TMID, raw []byte, opts ImportOptions) (ImportResult, error)
// Fetch retrieves the Thing Model file from repo
// Returns the actual id of the retrieved Thing Model (it may differ in the timestamp from the id requested), the file contents, and an error
Fetch(ctx context.Context, id string) (string, []byte, error)
// Index updates repository's index file with data from given TM files. For ids that refer to non-existing files,
// removes those from index. Performs a full update if no updatedIds given
Index(ctx context.Context, updatedIds ...string) error
// CheckIntegrity checks the internal resources for integrity and consistency
CheckIntegrity(ctx context.Context, filter model.ResourceFilter) (results []model.CheckResult, err error)
// List searches the catalog for TMs matching search parameters
List(ctx context.Context, search *model.Filters) (model.SearchResult, error)
// Versions lists versions of a TM with given name
Versions(ctx context.Context, name string) ([]model.FoundVersion, error)
// Spec returns the spec this Repo has been created from
Spec() model.RepoSpec
// CanonicalRoot returns the canonical representation of the repository's root location
CanonicalRoot() string
// Delete deletes the TM with given id from repo. Returns ErrTMNotFound if TM does not exist
Delete(ctx context.Context, id string) error
ListCompletions(ctx context.Context, kind string, args []string, toComplete string) ([]string, error)
GetTMMetadata(ctx context.Context, tmID string) ([]model.FoundVersion, error)
ImportAttachment(ctx context.Context, container model.AttachmentContainerRef, attachment model.Attachment, content []byte, force bool) error
FetchAttachment(ctx context.Context, container model.AttachmentContainerRef, attachmentName string) ([]byte, error)
DeleteAttachment(ctx context.Context, container model.AttachmentContainerRef, attachmentName string) error
}
type RepoAccessError ¶
type RepoAccessError struct {
// contains filtered or unexported fields
}
func NewRepoAccessError ¶
func NewRepoAccessError(spec model.RepoSpec, err error) *RepoAccessError
func (*RepoAccessError) Error ¶
func (e *RepoAccessError) Error() string
func (*RepoAccessError) Unwrap ¶
func (e *RepoAccessError) Unwrap() error
type S3Client ¶ added in v0.1.3
type S3Client interface {
GetObject(ctx context.Context, params *s3.GetObjectInput, optFns ...func(*s3.Options)) (*s3.GetObjectOutput, error)
ListObjectsV2(ctx context.Context, params *s3.ListObjectsV2Input, optFns ...func(*s3.Options)) (*s3.ListObjectsV2Output, error)
DeleteObject(ctx context.Context, params *s3.DeleteObjectInput, optFns ...func(*s3.Options)) (*s3.DeleteObjectOutput, error)
DeleteObjects(ctx context.Context, params *s3.DeleteObjectsInput, optFns ...func(*s3.Options)) (*s3.DeleteObjectsOutput, error)
PutObject(ctx context.Context, params *s3.PutObjectInput, optFns ...func(*s3.Options)) (*s3.PutObjectOutput, error)
HeadObject(ctx context.Context, params *s3.HeadObjectInput, optFns ...func(*s3.Options)) (*s3.HeadObjectOutput, error)
Options() s3.Options
}
type S3ObjectInfo ¶ added in v0.1.3
type S3Repo ¶ added in v0.1.3
type S3Repo struct {
// contains filtered or unexported fields
}
func (*S3Repo) CanonicalRoot ¶ added in v0.1.3
func (*S3Repo) CheckIntegrity ¶ added in v0.1.3
func (s *S3Repo) CheckIntegrity(ctx context.Context, filter model.ResourceFilter) (results []model.CheckResult, err error)
func (*S3Repo) DeleteAttachment ¶ added in v0.1.3
func (*S3Repo) FetchAttachment ¶ added in v0.1.3
func (*S3Repo) GetTMMetadata ¶ added in v0.1.3
func (*S3Repo) Import ¶ added in v0.1.3
func (s *S3Repo) Import(ctx context.Context, id model.TMID, raw []byte, opts ImportOptions) (ImportResult, error)
func (*S3Repo) ImportAttachment ¶ added in v0.1.3
func (s *S3Repo) ImportAttachment(ctx context.Context, container model.AttachmentContainerRef, attachment model.Attachment, content []byte, force bool) error
func (*S3Repo) ListCompletions ¶ added in v0.1.3
type TmcRepo ¶
type TmcRepo struct {
// contains filtered or unexported fields
}
TmcRepo implements a Repo TM repository backed by an instance of TM catalog REST API server
func (*TmcRepo) CanonicalRoot ¶ added in v0.1.3
func (*TmcRepo) CheckIntegrity ¶ added in v0.1.3
func (t *TmcRepo) CheckIntegrity(ctx context.Context, filter model.ResourceFilter) (results []model.CheckResult, err error)
func (*TmcRepo) DeleteAttachment ¶
func (*TmcRepo) FetchAttachment ¶
func (*TmcRepo) GetSubRepos ¶
func (*TmcRepo) GetTMMetadata ¶
func (*TmcRepo) Import ¶
func (t *TmcRepo) Import(ctx context.Context, id model.TMID, raw []byte, opts ImportOptions) (ImportResult, error)
func (*TmcRepo) ImportAttachment ¶
func (t *TmcRepo) ImportAttachment(ctx context.Context, container model.AttachmentContainerRef, attachment model.Attachment, content []byte, force bool) error
func (*TmcRepo) ListCompletions ¶
type Union ¶
type Union struct {
// contains filtered or unexported fields
}
func GetUnion ¶ added in v0.1.3
GetUnion returns a union containing the repo specified by spec, or a union of all repos, if the spec is empty
func (*Union) GetTMMetadata ¶
func (u *Union) GetTMMetadata(ctx context.Context, tmID string) ([]model.FoundVersion, []*RepoAccessError)
func (*Union) List ¶
func (u *Union) List(ctx context.Context, search *model.Filters) (model.SearchResult, []*RepoAccessError)
func (*Union) ListCompletions ¶
func (*Union) Search ¶ added in v0.1.3
func (u *Union) Search(ctx context.Context, query string) (model.SearchResult, []*RepoAccessError)
func (*Union) Versions ¶
func (u *Union) Versions(ctx context.Context, name string) ([]model.FoundVersion, []*RepoAccessError)
Click to show internal directories.
Click to hide internal directories.