manager

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2021 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const CHALLENGE_HOST = "127.0.0.1"
View Source
const MAX_RETRIES = 3

Variables

Functions

func ChallengesHealthProber

func ChallengesHealthProber(waitTime int)

func CommitChallengeContainer

func CommitChallengeContainer(challName string) error

Function which commits the deployed challenge provided

func CopyDir

func CopyDir(src string, dst string) error

Dir copies a whole directory recursively

func CopyFile

func CopyFile(src, dst string) error

File copies a single file from src to dst

func CopyToStaticContent

func CopyToStaticContent(challengeName, staticContentDir string) error

Copies the Static content to the staging/static/folder

func DeployChallenge

func DeployChallenge(challengeName string) error

func DeployChallengePipeline

func DeployChallengePipeline(challengeDir string) error

Main function which starts the deploy of a challenge provided directory inside the hack git database. We validate the challenge config first and return early starting a goroutine to start out the deploy process. The early return consist of validation of the provided challenge config in the directory.

func DeployStaticChallenge

func DeployStaticChallenge(challConf *cfg.BeastChallengeConfig, challenge *database.Challenge, challengeDir string)

Deploy a static challenge

func DeployStaticContentContainer

func DeployStaticContentContainer() error

Deploy the static content container for beast The image for the static container should be prebuilt, which can be found in /extras/static-content/ of the root of the project The image name for the static content docker image shoule be specified in the BEAST_STATIC_CONTAINER_NAME:latest variable This function does not build the image for static containers. The port for the deployment of the static container is specified in the variable BEAST_CHALLENGES_STATIC_PORT, this port should be free and will be the port on which nginx container for static files will be running.

Each challenges have its own static file folder inside the challenges directory. The whole staging area of beast configuration is mounted on the docker container to serve the static files to the user. The location of the static content for each challenge for staging area is $BEAST_ROOT/staging/$CHALLENGE/static This directory is automatically populated with the desired challenge static files when the challenge is commanded to be staged.

func GenerateChallengeDockerfileCtx

func GenerateChallengeDockerfileCtx(config *cfg.BeastChallengeConfig) (string, error)

Generate dockerfile context for the challnge from the challenge config file path provided as an argument. The config provided must be a valid beast configuration, which is to be ensured by the caller. It does not check if the config even exist or is valid. The validation for the dockerfile should be done before calling this function. If the file does not exist or there is some error while parsing the setup file this function will simply return the error without logging anything.

func GenerateDockerfile

func GenerateDockerfile(config *cfg.BeastChallengeConfig) (string, error)

From the provided configFIle path it generates the dockerfile for the challenge and returns it as a string. This function again assumes that the validation for the configFile is done beforehand before calling this function.

func GetAvailableChallenges

func GetAvailableChallenges() ([]string, error)

func GetCommandAndImageForWebChall

func GetCommandAndImageForWebChall(webRoot, port string, challengeInfo []string) (string, string)

This function provides the run command and image for a particular type of web challenge

  • webRoot: relative path to web challenge directory

  • port: web port

  • challengeInfo

    It returns the run command for challenge and the docker base image corresponding to language

func GetDeployWork

func GetDeployWork(challengeName string) (*wpool.Task, error)

Start deploying a challenge using the challenge Name(we are not using ID here), if the challenge is already present and the container is running, then don't do anything. If the challenge does not exist then first check if the challenge is in staged state, if it is then deploy challenge from there on or else start deploy pipeline for the challenge.

This will start deploy pipeline if it finds there is no problem in deployment, else it will notify the user via return value if there is an error or if the deployement request cannot be processed.

func GetStaticContentDir

func GetStaticContentDir(configFile, contextDir string) (string, error)

Provides the Static Content Folder Name from the config

func HandleAll

func HandleAll(action string, user string) []string

Handle all challenges.

func HandleTagRelatedChallenges

func HandleTagRelatedChallenges(action string, tag string, user string) []string

Handle tag related challenges.

func LogTransaction

func LogTransaction(identifier string, action string, authorization string) error

Takes and save the data to transaction table

func PurgeChallenge

func PurgeChallenge(challengeName string) error

func RedeployChallenge

func RedeployChallenge(challengeName string) error

func ResetBeastRemote

func ResetBeastRemote() error

func RunBeastBootsetps

func RunBeastBootsetps() error

func StartDeployPipeline

func StartDeployPipeline(challengeDir string, skipStage bool, skipCommit bool)

This is just a decorator function over bootstrapDeployPipeline and generate notifications to slack on the basis of the result of the deploy pipeline.

func StartUndeployChallenge

func StartUndeployChallenge(challengeName string, purge bool) error

func SyncBeastRemote

func SyncBeastRemote() error

Sync the beast remote directory with the actual git repository.

func UnTarChallengeFolder

func UnTarChallengeFolder(tarContextPath, dstPath string) (string, error)

UnTars challenge folder in a destination directory

func UndeployChallenge

func UndeployChallenge(challengeName string) error

func UndeployStaticContentContainer

func UndeployStaticContentContainer()

This cleans up the container deployed by DeployStaticContentContainer function The image is preserved after calling the function and thus need not be build again.

func UpdateChallenges

func UpdateChallenges()

func UpdateOrCreateChallengeDbEntry

func UpdateOrCreateChallengeDbEntry(challEntry *database.Challenge, config cfg.BeastChallengeConfig) error

TODO: Refactor this.

func ValidateChallengeConfig

func ValidateChallengeConfig(challengeDir string) error

This if the function which validates the challenge directory which is provided as an arguments. This validtions includes * A valid directory pointed by challengeDir * Valid config file for the challenge in the challengeDir root named as beast.toml * Valid challenge directory name in accordance to the challenge config.

func ValidateChallengeDir

func ValidateChallengeDir(challengeDir string) error

Validates a directory which is considered as a challenge directory The function returns an error if the directory is not valid or if it does not have valid structure required by beast.

Types

type BeastBareDockerfile

type BeastBareDockerfile struct {
	DockerBaseImage string
	Ports           string
	AptDeps         string
	SetupScripts    []string
	Executables     []string
	RunCmd          string
	RunScript       string
	MountVolume     string
	XinetdService   bool
	Entrypoint      string
}

type BeastXinetdConf

type BeastXinetdConf struct {
	Port        string
	ServicePath string
	ServiceName string
}

type ChallengePreview

type ChallengePreview struct {
	Name     string
	Category string
	Ports    []database.Port
	Hints    string
	Desc     string
	Points   uint
}

type TaskInfo

type TaskInfo struct {
	Action     string
	ChallDir   string
	SkipStage  bool
	SkipCommit bool
	Purge      bool
}

type Worker

type Worker struct {
}

a struct which implements the wpool.Worker interface for performing tasks

func (*Worker) PerformTask

func (worker *Worker) PerformTask(w wpool.Task) *wpool.Task

This function is used by the worker nodes or goroutines to perform the task which is pushed in the queue by the beast manager

Jump to

Keyboard shortcuts

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