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 ¶
- func CheckChallenge(id string) error
- func CheckInstance(challID, identity string) error
- func Claim(challID, identity, sourceID string) error
- func FindInstance(challID, sourceID string) (string, error)
- func Hash(id string) string
- func ListChallenges() (ids []string, merr error)
- func ListInstances(challID string) ([]string, error)
- func LookupClaim(challID, identity string) (string, error)
- type Challenge
- type Instance
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckChallenge ¶
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 ¶
CheckInstance returns an error if there is no instance with the given ids.
func FindInstance ¶ added in v0.4.3
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 ¶
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 ¶
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 LookupClaim ¶ added in v0.4.3
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 ¶
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.
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`)