Documentation
¶
Index ¶
- Constants
- Variables
- func New(conf *Config) (*daemon, error)
- func NewAgentConnection(config ServiceConfig) (*grpc.ClientConn, uint64, error)
- func NewExerciseClientConn(config ServiceConfig) (eproto.ExerciseStoreClient, error)
- func TranslateRPCErr(err error) error
- type APICreds
- type APIResponse
- type AdminClaims
- type AdminUserNoPw
- type AdminUserReponse
- type Agent
- type AgentLab
- type AgentPool
- type AgentRequest
- type AgentResources
- type AgentResponse
- type Category
- type Config
- type Creds
- type Event
- type EventConfig
- type EventExercisesResponse
- type EventInfoResponse
- type EventPool
- type EventResponse
- type EventType
- type Exercise
- type ExerciseProfile
- type ExerciseProfileRequest
- type ExerciseStatus
- type Lab
- type LabRequest
- type LabResponse
- type Logging
- type Machine
- type Organization
- type ParentAgent
- type ResourceEstimates
- type ScoreResponse
- type ServiceConfig
- type Solve
- type SolveExerciseRequest
- type State
- type Team
- type TeamClaims
- type TeamLoginRequest
- type TeamResponse
- type TeamScore
- type TeamSignupRequest
- type TeamSolve
- type TeamStatus
- type TestDelay
Constants ¶
View Source
const ( StatusRunning int32 = iota StatusSuspended StatusClosed )
View Source
const ( NoTokenErrMsg = "token contains an invalid number of segments" AUTH_KEY = "au" )
Variables ¶
View Source
var ( AllAgentsReturnedErr = errors.New("all agents returned error on creating environment") NoAgentsConnected = errors.New("no agents connected") NoResourcesError = errors.New("estimated memory usage of event is larger than what is available") MemoryThreshHold uint64 = 5 // In GB )
View Source
var ( UnreachableDBErr = errors.New("Database seems to be unreachable") )
Functions ¶
func NewAgentConnection ¶
func NewAgentConnection(config ServiceConfig) (*grpc.ClientConn, uint64, error)
func NewExerciseClientConn ¶
func NewExerciseClientConn(config ServiceConfig) (eproto.ExerciseStoreClient, error)
NewExerciseClientConn does not require CA file to communicate due to the fact that a script is running on Gitlab CI to push exercises to the service
func TranslateRPCErr ¶
Types ¶
type APIResponse ¶
type APIResponse struct {
Status string `json:"status,omitempty"`
Message string `json:"message,omitempty"`
Token string `json:"token,omitempty"`
UserInfo *AdminUserReponse `json:"userinfo,omitempty"`
Users []AdminUserReponse `json:"users,omitempty"`
Exercises []*proto.Exercise `json:"exercises,omitempty"`
Profiles []ExerciseProfile `json:"profiles,omitempty"`
EventExercises *EventExercisesResponse `json:"eventExercises,omitempty"`
TeamLab *LabResponse `json:"teamLab,omitempty"`
Categories []*proto.GetCategoriesResponse_Category `json:"categories,omitempty"`
Orgs []Organization `json:"orgs,omitempty"`
Agents []AgentResponse `json:"agents,omitempty"`
Events []EventResponse `json:"events,omitempty"`
TeamInfo *TeamResponse `json:"teaminfo,omitempty"`
EventInfo *EventInfoResponse `json:"eventinfo,omitempty"`
LabHosts []string `json:"labHosts,omitempty"`
}
type AdminClaims ¶
type AdminUserNoPw ¶ added in v1.0.0
type AdminUserReponse ¶
type AdminUserReponse struct {
User AdminUserNoPw `json:"user,omitempty"`
Perms map[string]string `json:"perms,omitempty"`
}
type Agent ¶
type Agent struct {
M sync.RWMutex `json:"-"`
Name string
Url string
Tls bool
Conn *grpc.ClientConn `json:"-"`
Close context.CancelFunc `json:"-"`
Resources AgentResources
Weight int32
RequestsLeft int32 // Used for round robin algorithm
QueuedTasks uint32
Heartbeat string
StateLock bool
Errors []error
}
type AgentLab ¶
type AgentLab struct {
ParentAgent ParentAgent `json:"parentAgent,omitempty"`
EstimatedMemoryUsage uint64 `json:"estimatedMemoryUsage,omitempty"`
Conn *grpc.ClientConn `json:"-"`
LabInfo *aproto.Lab `json:"labInfo,omitempty"`
IsAssigned bool `json:"isAssigned,omitempty"`
ExpiresAtTime time.Time `json:"expiresAtTime,omitempty"`
}
type AgentPool ¶
func (*AgentPool) GetAllAgents ¶ added in v1.0.0
type AgentRequest ¶
type AgentResources ¶
type AgentResponse ¶
type Config ¶
type Config struct {
Host string `yaml:"host"` // Host is is not really important at this time
Port uint `yaml:"port"` // Port to be listening on
ListeningIp string `yaml:"listening-ip,omitempty"` // ex. "127.0.0.1", "0.0.0.0". Default is "0.0.0.0"
VmName string `yaml:"vm-name,omitempty"` // Name of the VM
AuditLog Logging `yaml:"auditLog"` // Audit log, used for admin endpoints to log admin events. See Logging struct below
Database db.DbConfig `yaml:"db-config,omitempty"` // Creds and host for the postgres database
ExerciseService ServiceConfig `yaml:"exercise-service"` // Creds and host information for the exercise service
Production bool `yaml:"prodmode,omitempty"` // Currently unused
JwtSecret string `yaml:"jwtSecret,omitempty"` // Secret used to sign JWT's
Rechaptcha string `yaml:"recaptcha-key,omitempty"` // Recaptcha keys, currently not used
APICreds APICreds `yaml:"api-creds,omitempty"` // Currently unused
StatePath string `yaml:"state-path,omitempty"` // Path of the state file
TestDelay TestDelay `yaml:"test-delay,omitempty"` // Can be enabled or disabled, used to delay api responses to test long response times
LabExpiryDuration time.Duration `yaml:"lab-expiry-duration,omitempty"` // Base duration before lab expires without extension in minutes
LabExpiryExtension time.Duration `yaml:"lab-expiry-extension,omitempty"` // Duration to extend lab expiration time by in minutes
EventRetention uint16 `yaml:"eventRetention"` // time in days before a closed event is deleted
}
func NewConfigFromFile ¶
type Event ¶
type Event struct {
M sync.RWMutex `json:"-"`
DbId int32 `json:"dbId"`
StartedAt time.Time `json:"startedAt"`
Config EventConfig `json:"config,omitempty"`
Teams map[string]*Team `json:"teams,omitempty"`
Labs map[string]*AgentLab `json:"labs,omitempty"`
UnassignedBrowserLabs chan *AgentLab `json:"-"`
UnassignedVpnLabs chan *AgentLab `json:"-"`
TeamsWaitingForBrowserLabs *list.List `json:"-"` // Using linked list in order to remove teams from the queue again
TeamsWaitingForVpnLabs *list.List `json:"-"`
EstimatedMemoryUsage uint64 `json:"estimatedMemoryUsage,omitempty"`
EstimatedMemoryUsagePerLab uint64 `json:"estimatedMemoryUsagePerLab,omitempty"`
}
func (*Event) GetConfig ¶ added in v1.0.0
func (event *Event) GetConfig() EventConfig
func (*Event) IsMaxLabsReached ¶
Calculates the current amount of labs for an event then checks if it has passed or equal to the configured amount of maximum labs for event
type EventConfig ¶
type EventConfig struct {
Type int32 `json:"type"`
Name string `json:"name" binding:"required"`
Tag string `json:"tag" binding:"required"`
TeamSize int32 `json:"teamSize" binding:"required"`
MaxLabs int32 `json:"maxLabs" binding:"required"`
VmName string `json:"vmName,omitempty"`
ExerciseTags []string `json:"exerciseTags" binding:"required"`
ExpectedFinishDate time.Time `json:"expectedFinishDate" binding:"required"`
PublicScoreBoard bool `json:"publicScoreBoard,omitempty"`
SecretKey string `json:"secretKey,omitempty"`
DynamicScoring bool `json:"dynamicScoring,omitempty"`
DynamicMax int32 `json:"dynamicMax,omitempty"`
DynamicMin int32 `json:"dynamicMin,omitempty"`
DynamicSolveThreshold int32 `json:"dynamicSolveThreshold,omitempty"`
ExerciseConfigs []*aproto.ExerciseConfig
}
type EventExercisesResponse ¶
type EventExercisesResponse struct {
Categories []Category `json:"categories"`
}
type EventInfoResponse ¶
type EventPool ¶
type EventPool struct {
M sync.RWMutex `json:"-"`
Events map[string]*Event `json:"events,omitempty"`
}
func (*EventPool) GetAllAgentLabsForAgent ¶
func (*EventPool) GetAllEvents ¶ added in v1.0.0
func (*EventPool) RemoveEvent ¶
Removes an event from the event pool TODO make sure to close channels
type EventResponse ¶ added in v1.0.0
type EventResponse struct {
Id uint `json:"id"`
Tag string `json:"tag"`
Name string `json:"name"`
Type string `json:"type"`
Organization string `json:"organization"`
Status string `json:"status"`
LabsRunning uint `json:"labsRunning"`
Exercises uint `json:"exercises"`
Teams uint `json:"teams"`
MaxLabs uint `json:"maxLabs"`
SecretKey string `json:"secretKey"`
CreatedBy string `json:"createdBy"`
CreatedAt string `json:"createdAt"`
FinishesAt string `json:"finishesAt"`
FinishedAt string `json:"finishedAt"`
}
type Exercise ¶
type Exercise struct {
ParentExerciseTag string `json:"parentExerciseTag"`
Static bool `json:"static"` // False if no docker containers for challenge
Name string `json:"name"`
Tag string `json:"tag"`
Points int `json:"points"`
Category string `json:"category"`
Description string `json:"description"`
Solved bool `json:"solved"`
Solves []Solve `json:"solves"`
}
type ExerciseProfile ¶
type ExerciseProfileRequest ¶
type ExerciseStatus ¶
type LabRequest ¶
type LabRequest struct {
IsVpn bool `json:"isVpn"`
}
type LabResponse ¶
type LabResponse struct {
ParentAgent ParentAgent `json:"parentAgent,omitempty"`
Lab Lab `json:"labInfo,omitempty"`
}
type Organization ¶ added in v1.0.0
type ParentAgent ¶
type ResourceEstimates ¶
type ScoreResponse ¶
type ServiceConfig ¶
type SolveExerciseRequest ¶
type Team ¶
type Team struct {
M sync.RWMutex `json:"-"`
Username string `json:"username,omitempty"`
Email string `json:"email,omitempty"`
Status TeamStatus `json:"status"`
Lab *AgentLab `json:"lab,omitempty"`
QueueElement *list.Element `json:"-"`
ActiveWebsocketConnections map[string]*websocket.Conn `json:"-"`
}
func (*Team) ExtendLabExpiry ¶
func (*Team) LockForFunc ¶ added in v1.0.0
func (team *Team) LockForFunc(function func())
type TeamClaims ¶
type TeamLoginRequest ¶
type TeamResponse ¶
type TeamResponse struct {
Username string `json:"username,omitempty"`
Email string `json:"email,omitempty"`
Status string `json:"status,omitempty"`
Lab *LabResponse `json:"lab,omitempty"`
}
type TeamSignupRequest ¶
type TeamSignupRequest struct {
Username string `json:"username" binding:"required"`
Password string `json:"password" binding:"required"`
ConfirmPassword string `json:"confirmPassword" binding:"required"`
Email string `json:"email" binding:"required"`
EventTag string `json:"eventTag"`
SecretKey string `json:"secretKey"`
}
type TeamStatus ¶
type TeamStatus uint8
const ( WaitingForLab TeamStatus = iota InQueue RunningExerciseCommand RunningVmCommand Idle )
func (TeamStatus) String ¶
func (status TeamStatus) String() string
Source Files
¶
Click to show internal directories.
Click to hide internal directories.