catalog

package
v0.29.2 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package catalog reads and repairs the plugin catalog stored in MongoDB by plugin-service.

Index

Constants

This section is empty.

Variables

View Source
var ErrHashChanged = errors.New("the recorded hash is not the expected one")

ErrHashChanged is returned when the catalog changed since it was read.

Functions

This section is empty.

Types

type Conflict

type Conflict struct {
	Key    string `json:"key"`
	Source string `json:"source"`
	Target string `json:"target"`
}

Conflict is a hash entry recorded with different values in the source and the target.

type Entry

type Entry struct {
	Module   string `json:"module"`
	Version  string `json:"version"`
	Runtime  string `json:"runtime,omitempty"`
	Stars    int    `json:"stars"`
	Listed   bool   `json:"listed"`
	Disabled bool   `json:"disabled,omitempty"`
	Hidden   bool   `json:"hidden,omitempty"`
	Hash     string `json:"recordedHash"`
}

Entry is one archive hash recorded by plugin-service, with the plugin it belongs to.

func (Entry) IsWasm

func (e Entry) IsWasm() bool

IsWasm reports whether the plugin is served from a GitHub release asset.

func (Entry) Key

func (e Entry) Key() string

Key returns the hash name used by plugin-service: <module>@<version>.

type Removal

type Removal struct {
	Versions      []string `json:"versions"`
	LatestVersion string   `json:"latestVersion"`
	Hidden        bool     `json:"hidden"`
}

Removal is the outcome of RemoveVersions.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store gives access to one plugin catalog database.

func Open

func Open(uri, database string) (*Store, error)

Open connects to the catalog stored in the given database.

func (*Store) Close

func (s *Store) Close(ctx context.Context) error

Close disconnects from MongoDB.

func (*Store) Entries

func (s *Store) Entries(ctx context.Context) ([]Entry, error)

Entries returns every recorded hash, sorted by module then version.

func (*Store) RemoveVersions

func (s *Store) RemoveVersions(ctx context.Context, module string, versions map[string]string, dryRun bool) (Removal, error)

RemoveVersions removes versions, given as version → recorded hash, from the versions and hashes of module. latestVersion moves to the newest version left, and the plugin is hidden when none is left. The removed versions are recorded in removedVersions for Sync. Nothing is written if a recorded hash or the version list changed in the meantime, or in dry-run.

func (*Store) SetHash

func (s *Store) SetHash(ctx context.Context, module, version, oldHash, newHash string) error

SetHash replaces the recorded hash of module@version, only if it still holds oldHash.

type SyncResult

type SyncResult struct {
	// Inserted are the plugins created in the source after the dump.
	Inserted []string `json:"inserted"`
	// Updated are the plugins whose metadata, versions or hashes changed in the source.
	Updated []string `json:"updated"`
	// Hashes are the hash entries copied to the target.
	Hashes []Entry `json:"hashes"`
	// Conflicts are hash entries recorded on both sides with different values. The target value is kept.
	Conflicts []Conflict `json:"conflicts"`
	// Skipped are plugins missing in the target but created before the dump, so removed from it on purpose.
	Skipped []string `json:"skipped"`
	// Changed are plugins written in the target while Sync ran, left as is: run it again.
	Changed []string `json:"changed"`
	// MissingInSource are plugins of the target the source does not have, deleted after the dump or added to the target.
	// They are left as is: review them by hand.
	MissingInSource []string `json:"missingInSource"`
}

SyncResult describes what Sync copied, or would copy in dry-run.

func Sync

func Sync(ctx context.Context, src, dst *Store, since time.Time, dryRun bool) (SyncResult, error)

Sync copies into dst what was added to src after the dump taken at since.

Plugins created after since are inserted as is. For the other plugins, metadata is copied, versions missing from dst are appended unless RemoveVersions removed them from dst, and hash entries missing from dst are added for the versions dst lists. Nothing is removed from dst and no dst hash is changed, so the fixes applied to dst survive. A plugin written in dst while Sync runs is left as is and reported in Changed. Plugins of dst that src lacks are only reported, in MissingInSource.

Jump to

Keyboard shortcuts

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