fs

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2024 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 ChallengeDirectory

func ChallengeDirectory(id string) string

func CheckChallenge

func CheckChallenge(id string) error

CheckChallenge returns an error if there is no challenge with the given id.

func CheckInstance

func CheckInstance(challId, sourceId string) error

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

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 InstanceDirectory

func InstanceDirectory(challId, sourceId string) string

func ListChallenges

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

func ListInstances

func ListInstances(challId string) (iids []string, merr error)

Types

type Challenge

type Challenge struct {
	ID        string         `json:"id"`
	Directory string         `json:"directory"`
	Hash      string         `json:"hash"` // must be kept up coherent with directory content as its sha256 sum of base64(zip(content))
	Until     *time.Time     `json:"until,omitempty"`
	Timeout   *time.Duration `json:"timeout,omitempty"`
}

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

func LoadChallenge

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

func (*Challenge) Delete

func (chall *Challenge) Delete() error

func (*Challenge) Save

func (chall *Challenge) Save() error

type Instance

type Instance struct {
	Identity       string     `json:"identity"`
	ChallengeID    string     `json:"challenge_id"`
	SourceID       string     `json:"source_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"`
	Flag           *string    `json:"flag,omitempty"`
}

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

func LoadInstance

func LoadInstance(challId, sourceId string) (*Instance, error)

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