index

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2023 License: Apache-2.0 Imports: 14 Imported by: 1

Documentation

Overview

Package index implements all the logic for handling indexes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Configs []ConfigEntry `yaml:"configs"`
}

Config aggregates the info about ConfigEntries.

func NewConfig

func NewConfig(path string) (*Config, error)

NewConfig loads an index config from a file.

func (*Config) Add

func (c *Config) Add(entry ConfigEntry)

Add adds a new config to Config.

func (*Config) Get

func (c *Config) Get(name string) *ConfigEntry

Get returns a pointer to an entry in a Config.

func (*Config) Remove

func (c *Config) Remove(name string)

Remove removes a config by name from an Config.

func (*Config) Upsert

func (c *Config) Upsert(entry ConfigEntry)

Upsert replaces the entry if already exists otherwise just appends it.

func (*Config) Write

func (c *Config) Write(path string) error

Write writes a Config to disk.

type ConfigEntry

type ConfigEntry struct {
	AddedTimestamp string `yaml:"added_timestamp"`
	// CaFile                string `yaml:"caFile"`
	// CertFile              string `yaml:"certFile"`
	// InsecureSkipTLSVerify string `yaml:"insecure_skip_tls_verify"`
	// KeyFile               string `yaml:"keyFile"`
	Name string `yaml:"name"`
	// PassCredentialsAll    string `yaml:"pass_credentials_all"`
	// Password              string `yaml:"password"`
	UpdatedTimestamp string `yaml:"updated_timestamp"`
	URL              string `yaml:"url"`
}

ConfigEntry contains information about one of the index that were cached locally. TODO: add support for all the other fields.

type Entry

type Entry struct {
	// Mandatory fields
	Name       string `yaml:"name"`
	Type       string `yaml:"type"`
	Registry   string `yaml:"registry"`
	Repository string `yaml:"repository"`
	// Optional fields
	Description string   `yaml:"description"`
	Home        string   `yaml:"home"`
	Keywords    []string `yaml:"keywords"`
	License     string   `yaml:"license"`
	Maintainers []struct {
		Email string `yaml:"email"`
		Name  string `yaml:"name"`
	} `yaml:"maintainers"`
	Sources []string `yaml:"sources"`
}

Entry describes an entry of the index stored remotely and cached locally.

type Index

type Index struct {
	Name    string
	Entries []*Entry
	// contains filtered or unexported fields
}

Index represents an index.

func Fetch

func Fetch(ctx context.Context, url, name string) (*Index, error)

Fetch retrieves a remote index using its URL.

func New

func New(name string) *Index

New returns a new empty Index.

func (*Index) EntryByName

func (i *Index) EntryByName(name string) (*Entry, bool)

EntryByName returns a Entry by passing its name.

func (*Index) Normalize

func (i *Index) Normalize() error

Normalize the index to the canonical form (i.e., entries sorted by name, lexically byte-wise in ascending order).

Since only one possible representation of a normalized index exists, a digest of a normalized index is suitable for integrity checking or similar purposes. Return an error if the index is not in a consistent state.

func (*Index) Read

func (i *Index) Read(path string) error

Read reads entries from a file.

func (*Index) Remove

func (i *Index) Remove(entry *Entry) error

Remove removes an entry from the Index.

func (*Index) SearchByKeywords

func (i *Index) SearchByKeywords(minScore float64, keywords ...string) []*Entry

SearchByKeywords search for entries matching the given keywords in MergedIndexes. minScore is the minimum score to consider a match between a name of an artifact and a keyword. if minScore is not reached, we fallback to a simple partial matching on keywords.

func (*Index) Upsert

func (i *Index) Upsert(entry *Entry)

Upsert adds a new entry to the Index or updates an existing one.

func (*Index) Write

func (i *Index) Write(path string) error

Write writes entries to a file.

type MergedIndexes

type MergedIndexes struct {
	Index
	// contains filtered or unexported fields
}

MergedIndexes is used to aggregate all indexes and perform search operations.

func NewMergedIndexes

func NewMergedIndexes() *MergedIndexes

NewMergedIndexes initializes a MergedIndex.

func (*MergedIndexes) IndexByEntry

func (m *MergedIndexes) IndexByEntry(entry *Entry) *Index

IndexByEntry is used to retrieve the original index from an entry in MergedIndexes.

func (*MergedIndexes) Merge

func (m *MergedIndexes) Merge(indexes ...*Index)

Merge creates a new index by merging all the indexes that are passed. Orders matters. Be sure to pass an ordered list of indexes. For our use case, sort by added time.

func (*MergedIndexes) ResolveReference

func (m *MergedIndexes) ResolveReference(name string) (string, error)

ResolveReference is a helper function that parse with the followig logic:

  1. if name is the name of an artifact, it will use the merged index to compute its reference. The tag latest is always appended. e.g "cloudtrail" -> "ghcr.io/falcosecurity/plugins/cloudtrail:latest" if instead a tag or a digest is specified, the name will be used to look up into mergedIndexes, then the tag or digest will be appended. e.g "cloudtrail:0.5.1" -> "ghcr.io/falcosecurity/plugins/cloudtrail:0.5.1" e.g "cloudtrail@sha256:123abc..." -> "ghcr.io/falcosecurity/plugins/cloudtrail@sha256:123abc...

  2. if name is a reference without tag or digest, tag latest is appended. e.g. "ghcr.io/falcosecurity/plugins/cloudtrail" -> "ghcr.io/falcosecurity/plugins/cloudtrail:latest"

  3. if name is a complete reference, it will be returned as is.

Directories

Path Synopsis
Package cache implements in memory cache for the index files.
Package cache implements in memory cache for the index files.

Jump to

Keyboard shortcuts

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