repository

package
v0.0.0-...-e75a48e Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package repository contains utilities abstracting git repositories configuration and source code pulling

Index

Constants

This section is empty.

Variables

View Source
var ErrClientNotAllowed = errors.New("client is not allowed to access the requested resource")

ErrClientNotAllowed is returned whenever a client tries to access a repository it has not been whitelisted for

View Source
var ErrRepositoryNotFound = errors.New("the requested repository does not exist")

ErrRepositoryNotFound is returned whenever a client requests a repository which is not existing

Functions

This section is empty.

Types

type Beholder

type Beholder struct {
	Active bool // true if the repository is actively monitored and can be used
	// contains filtered or unexported fields
}

Beholder are responsible for maintaining local copies of git repositories up to date based on the provided configuration As they are running in background they make use of a heartbeat channel towards their initiator to communicate about repositories update event

func NewBeholder

func NewBeholder(checkoutLocation string, configuration *configuration.Repository, heartbeat chan UpdateEvent) *Beholder

NewBeholder initiates a new beholder for the provided configuration a call to Watch() is mandatory to start the beholder process

func (*Beholder) File

func (w *Beholder) File(filepath string) ([]byte, error)

File retrieves the requested path from the managed repository File will ensure no file can be read if the repository is being updated

func (*Beholder) Watch

func (w *Beholder) Watch()

Watch initiates the creation of a local copy of the configured repository and will periodically update the repository to its latest state

type Manager

type Manager struct {
	Configuration *config.Repositories   // git configuration
	Repositories  map[string]*Repository // list of configured repository
	Heartbeat     chan UpdateEvent       // uplink channel used by beholders to communicate
}

Manager is one-stop shop for managing multiple repositories configured via yaml files

func NewManager

func NewManager(configuration *config.Repositories) (*Manager, error)

NewManager creates a new repository manager by parsing the provided target repository configuration location

func (*Manager) Get

func (mgr *Manager) Get(repository string, path string, clientID string) ([]byte, error)

Get scans the target repository for the file pointed by the provided path

func (*Manager) Start

func (mgr *Manager) Start()

Start will generate a repository beholder for each found configuration and will attempt to create a local copy

func (*Manager) Statistics

func (mgr *Manager) Statistics() map[string]*Statistics

Statistics returns underlying git repository access statistics

type Repository

type Repository struct {
	Configuration *configuration.Repository // repository configuration
	Statistics    *Statistics               // repository access statistics
	Beholder      *Beholder                 // beholder process managing the repository
}

Repository is a handle on a git repository

func (*Repository) IsClientAllowed

func (repo *Repository) IsClientAllowed(ClientID string) bool

IsClientAllowed verifies if the provided ClientID is allowed to access the repository based on its configuration

type Statistics

type Statistics struct {
	HitCount   int64     `json:"hitCount"`
	LastUpdate time.Time `json:"lastUpdate"`
	NextUpdate time.Time `json:"nextUpdate"`
	LastError  error     `json:"lastError"`
}

Statistics allows to maintain some stats about repository access

type UpdateEvent

type UpdateEvent struct {
	RepositoryName string
	LastUpdate     time.Time
	NextUpdate     time.Time
	LastError      error
	Active         bool
}

UpdateEvent as generated by beholders

Jump to

Keyboard shortcuts

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