fs

package
v0.6.5 Latest Latest
Warning

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

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

Documentation

Overview

Package fs wraps filesystem operations to provide a simple and resilient API.

This enable low development and maintainenance effort, while avoiding breaking changes introduced on the high level of the chall-manager gRPC API (keep it as simple and readable as possible).

The storage is based on a filesystem, future works could move this to an object store such a S3-compliant solution.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckChallenge

func CheckChallenge(id string) error

CheckChallenge returns an *errs.ChallengeExist if there is no challenge with the given id. It avoids reading the whole file and loading the corresponding challenge in memory, when not necessary.

func CheckInstance

func CheckInstance(challID, identity string) error

CheckInstance returns an error if there is no instance with the given ids.

func Claim added in v0.4.3

func Claim(challID, identity, sourceID string) error

Claim a challenge instance (by its identity) for a source.

func FindInstance added in v0.4.3

func FindInstance(challID, sourceID string) (string, error)

FindInstance loads all Instances until finding the one claimed by a source. It opens every Instance information file for claim lookup, so usage should be avoided when an alternative exist.

Returns the identity claimed by the sourceID for the challenge, or an error. Errors could be of type *errors.InstanceExist if it was not found, or anything else if something unexpected happened (e.g., filesystem read failure).

func Hash

func Hash(id string) string

Hash computes the Hash of the given ID. It is used to get a standard identifier (both in size and format) while avoiding filesystem manipulation (e.g. path traversal).

func ListChallenges

func ListChallenges() (ids []string, merr error)

ListChallenges loads all Challenges. It opens every Challenge information file for ID lookup, so usage should be avoided when an alternative exist.

func ListInstances

func ListInstances(challID string) ([]string, error)

func LookupClaim added in v0.4.3

func LookupClaim(challID, identity string) (string, error)

LookupClaim returns the source that claims an instance.

Types

type Challenge

type Challenge struct {
	ID         string            `json:"id"`
	Scenario   string            `json:"scenario"`
	Until      *time.Time        `json:"until,omitempty"`
	Timeout    *time.Duration    `json:"timeout,omitempty"`
	Additional map[string]string `json:"additional,omitempty"`
	Min        int64             `json:"min"`
	Max        int64             `json:"max"`
}

Challenge is the internal model of an API Challenge as it is stored on the filesystem (at `<global.Conf.Directory>/chall/hash(<id>)/info.json`).

func LoadChallenge

func LoadChallenge(id string) (*Challenge, error)

LoadChallenge opens the Challenge information file and returns it. Returns an *errs.ChallengeExist when the Challenge does not exist.

For existence check, please use CheckChallenge intead.

func (*Challenge) Delete

func (chall *Challenge) Delete() error

Delete the Challenge, so delete it from disk.

func (*Challenge) Save

func (chall *Challenge) Save() error

Save the Challenge, so write it to disk.

type Instance

type Instance struct {
	Identity       string            `json:"identity"`
	ChallengeID    string            `json:"challenge_id"`
	State          any               `json:"state"`
	Since          time.Time         `json:"since"`
	LastRenew      time.Time         `json:"last_renew"`
	Until          *time.Time        `json:"until,omitempty"`
	ConnectionInfo string            `json:"connection_info"`
	Flags          []string          `json:"flags,omitempty"`
	Additional     map[string]string `json:"additional,omitempty"`
}

Instance is the internal model of an API Instance as it is stored on the filesystem (at `<global.Conf.Directory>/chall/hash(<id>)/instance/hash(<id>)/info.json`)

func LoadInstance

func LoadInstance(challID, identity string) (*Instance, error)

func (*Instance) Claim added in v0.4.3

func (ist *Instance) Claim(sourceID string) error

Claim the instance for a source.

func (*Instance) Delete

func (ist *Instance) Delete() error

func (*Instance) Save

func (ist *Instance) Save() error

Jump to

Keyboard shortcuts

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