cache

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SaveState

func SaveState(state *State, cacheDir string) error

Types

type Cache

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

Cache manages per-policy OCI Layout stores under ~/.complytime/policies/{policy-id}/.

func NewCache

func NewCache(cacheDir string) *Cache

func (*Cache) Dir

func (c *Cache) Dir() string

func (*Cache) ListPolicies

func (c *Cache) ListPolicies() ([]string, error)

func (*Cache) NewPolicyStore

func (c *Cache) NewPolicyStore(policyID string) (*oci.Store, error)

NewPolicyStore creates or opens an OCI Layout store for the given policy ID.

func (*Cache) PolicyStoreExists

func (c *Cache) PolicyStoreExists(policyID string) bool

func (*Cache) PolicyStorePath

func (c *Cache) PolicyStorePath(policyID string) string

type PolicySource

type PolicySource interface {
	DefinitionVersion(ctx context.Context, policyID string) (digest string, version string, err error)
	CopyPolicy(ctx context.Context, policyID, tag string, dst *ocistore.Store) (ocispec.Descriptor, error)
}

PolicySource abstracts remote policy access for sync operations.

type PolicyState

type PolicyState struct {
	Version     string    `json:"version"`
	Digest      string    `json:"digest"`
	LastUpdated time.Time `json:"last_updated"`
}

PolicyState holds version, digest, and timestamp for a single cached policy.

type RegistrySource

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

RegistrySource wraps a registry.Client to implement PolicySource. Uses oras.Copy() for atomic remote-to-local transfer with digest verification.

func NewRegistrySource

func NewRegistrySource(client *registry.Client) *RegistrySource

func (*RegistrySource) CopyPolicy

func (s *RegistrySource) CopyPolicy(ctx context.Context, policyID, tag string, dst *ocistore.Store) (ocispec.Descriptor, error)

func (*RegistrySource) DefinitionVersion

func (s *RegistrySource) DefinitionVersion(ctx context.Context, policyID string) (string, string, error)

type State

type State struct {
	LastSync time.Time              `json:"last_sync"`
	Policies map[string]PolicyState `json:"policies"`
}

State tracks sync metadata for all cached policies, persisted as state.json.

func LoadState

func LoadState(cacheDir string) (*State, error)

func (*State) GetPolicyState

func (s *State) GetPolicyState(policyID string) (PolicyState, bool)

func (*State) UpdatePolicyState

func (s *State) UpdatePolicyState(policyID, version, digest string)

type Sync

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

Sync provides incremental sync using oras.Copy() for remote-to-local transfer.

func NewSync

func NewSync(cache *Cache, state *State, source PolicySource) *Sync

func (*Sync) SyncPolicy

func (s *Sync) SyncPolicy(ctx context.Context, policyID, version string) error

SyncPolicy performs incremental synchronization of a policy. Compares local digest against remote manifest digest; if they match, sync is skipped. On failure, the OCI Layout store retains its previous state.

Directories

Path Synopsis
Package cachetest provides test doubles for the cache package.
Package cachetest provides test doubles for the cache package.

Jump to

Keyboard shortcuts

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