Documentation
¶
Index ¶
- Constants
- type BuildId
- type BuildMetadata
- type ChallengeId
- type ChallengeMetadata
- type ChallengeUpdates
- type Image
- type ImageId
- type InstanceId
- type InstanceMetadata
- type LogLevel
- type Manager
- func (m *Manager) Build(challenge ChallengeId, seeds []int, flagFormat string) ([]BuildId, error)
- func (m *Manager) CheckInstance(instance InstanceId) error
- func (m *Manager) Destroy(build BuildId) error
- func (m *Manager) DetectChanges(fp string) *ChallengeUpdates
- func (m *Manager) DumpState(challenges []ChallengeId) ([]*ChallengeMetadata, error)
- func (m *Manager) GetBuildMetadata(build BuildId) (*BuildMetadata, error)
- func (m *Manager) GetChallengeMetadata(challenge ChallengeId) (*ChallengeMetadata, error)
- func (m *Manager) GetInstanceMetadata(instance InstanceId) (*InstanceMetadata, error)
- func (m *Manager) ListChallenges() []ChallengeId
- func (m *Manager) Start(build BuildId) (InstanceId, error)
- func (m *Manager) Stop(instance InstanceId) error
- func (m *Manager) Update(fp string) *ChallengeUpdates
- Bugs
Constants ¶
const ( DB_ENV string = "CMGR_DB" DIR_ENV string = "CMGR_DIR" ARTIFACT_DIR_ENV string = "CMGR_ARTIFACT_DIR" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BuildMetadata ¶
type BuildMetadata struct { Id BuildId `json:"id"` Flag string `json:"flag"` LookupData map[string]string `json:"lookup_data,omitempty"` Seed int `json:"seed"` Format string `json:"format"` Images []Image `json:"images"` HasArtifacts bool `json:"has_artifacts"` LastSolved int `json:"last_solved"` Challenge ChallengeId `json:"challenge_id"` Instances []*InstanceMetadata `json:"instances,omitempty"` }
type ChallengeId ¶
type ChallengeId string
type ChallengeMetadata ¶
type ChallengeMetadata struct { Id ChallengeId `json:"id"` Name string `json:"name,omitempty"` Namespace string `json:"namespace"` ChallengeType string `json:"challenge_type"` Description string `json:"description,omitempty"` Details string `json:"details,omitempty"` Hints []string `json:"hints,omitempty"` SourceChecksum uint32 `json:"source_checksum"` MetadataChecksum uint32 `json:"metadata_checksum` Path string `json:"path"` Templatable bool `json:"templatable,omitempty"` PortMap map[string]int `json:"port_map,omitempty"` MaxUsers int `json:"max_users,omitempty"` Category string `json:"category,omitempty"` Points int `json:"points,omitempty"` Tags []string `json:"tags,omitempty"` Attributes map[string]string `json:"attributes,omitempty"` SolveScript bool `json:"has_solve_script,omitempty"` Builds []*BuildMetadata `json:"builds,omitempty"` }
type ChallengeUpdates ¶
type ChallengeUpdates struct { Added []*ChallengeMetadata `json:"added"` Refreshed []*ChallengeMetadata `json:"refreshed"` Updated []*ChallengeMetadata `json:"updated"` Removed []*ChallengeMetadata `json:"removed"` Unmodified []*ChallengeMetadata `json:"unmodified"` Errors []error `json:"errors"` }
type InstanceId ¶
type InstanceId int64
type InstanceMetadata ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
func NewManager ¶
Creates a new instance of the challenge manager validating the appropriate environment variables in the process. A return value of `nil` indicates a fatal error occurred during intitialization.
func (*Manager) Build ¶
Templates out a challenge and generates concrete images, flags, and lookup values for the seeds provided. This function may take a significant amount of time because it will implicitly download base docker images and build the artifacts.
@param challenge The challenge to build @param seeds The seeds to use for randomization and the flag @param flagFormat The requested flag format
@return A list of build IDs (same order as seeds that were passed) or
an error.
func (*Manager) CheckInstance ¶
func (m *Manager) CheckInstance(instance InstanceId) error
func (*Manager) DetectChanges ¶
func (m *Manager) DetectChanges(fp string) *ChallengeUpdates
Traverses the entire directory and captures all valid challenge descriptions it comes across. In general, it will continue even when it encounters errors (permission, poorly formatted JSON, etc.) in order to give the as much feedback as possible to the caller. However, it will fail fast on two challenges with the same name and namespace.
This function does not have any side-effects on the database or built/running challenge state, but changes that it detects will effect new builds. It is important to resolve any issues/errors it raises before making any other API calls for affected challenges. Failure to follow this guidance could result in inconsistencies in deployed challenges.
@param fp The filepath to a directory to check for changes
(defaults to root of the challenge directory if passed the empty string)
@return A struct with a list of the challenges
func (*Manager) DumpState ¶
func (m *Manager) DumpState(challenges []ChallengeId) ([]*ChallengeMetadata, error)
func (*Manager) GetBuildMetadata ¶
func (m *Manager) GetBuildMetadata(build BuildId) (*BuildMetadata, error)
func (*Manager) GetChallengeMetadata ¶
func (m *Manager) GetChallengeMetadata(challenge ChallengeId) (*ChallengeMetadata, error)
func (*Manager) GetInstanceMetadata ¶
func (m *Manager) GetInstanceMetadata(instance InstanceId) (*InstanceMetadata, error)
func (*Manager) ListChallenges ¶
func (m *Manager) ListChallenges() []ChallengeId
func (*Manager) Stop ¶
func (m *Manager) Stop(instance InstanceId) error
func (*Manager) Update ¶
func (m *Manager) Update(fp string) *ChallengeUpdates
This will update the global system state based off the changes that are detected by a call to `DetectChanges`. Specifically, in addition to updating challenge metadata (new and existing) it will rebuild and, if successful restart, existing challenges and then remove the metadata for challenges that can no longer be found. Challenges that have not been modified should not be affected.
In the presence of errors, this function will do addition and updates as best it can in order to preserve a consistent system state. However, if a build fails, it will keep the existing instance running and rollback the challenge metadata. Additionally, in the presence of errors it will not perform any removals of challenge metadata (removing a built challenge is considered an error).
@param fp The filepath to a directory to check for changes
(defaults to root of the challenge directory if passed the empty string)
@return A struct with a list of the challenges
Notes ¶
Bugs ¶
Need to actually implement more validation such as verifying that published ports are referenced and that there are no clearly invalid format strings in the details and hints.