Documentation
¶
Index ¶
- Variables
- func AddNotification(notification *Notification) error
- func BatchUpdateChallenge(whereMap map[string]interface{}, chall Challenge) error
- func CheckPreviousSubmissions(userId uint, challId uint) (bool, error)
- func CreateChallengeEntry(challenge *Challenge) error
- func CreateUserEntry(user *User) error
- func DeleteChallengeEntry(challenge *Challenge) error
- func DeleteNotification(notification *Notification) error
- func DeleteRelatedPorts(portList []Port) error
- func GetUserRank(userID uint, userScore uint, updatedAt time.Time) (rank int64, error error)
- func QueryOrCreateTagEntry(tag *Tag) error
- func SaveFlagSubmission(user_challenges *UserChallenges) error
- func SaveTransaction(transaction *Transaction) error
- func UpdateChallenge(chall *Challenge, m map[string]interface{}) error
- func UpdateNotification(notify *Notification, m map[string]interface{}) error
- func UpdateUser(user *User, m map[string]interface{}) error
- type AuthorizedKeyTemplate
- type Challenge
- func GetRelatedChallenges(user *User) ([]Challenge, error)
- func QueryAllChallenges() ([]Challenge, error)
- func QueryChallengeEntries(key string, value string) ([]Challenge, error)
- func QueryChallengeEntriesMap(whereMap map[string]interface{}) ([]Challenge, error)
- func QueryFirstChallengeEntry(key string, value string) (Challenge, error)
- func QueryRelatedChallenges(tag *Tag) ([]Challenge, error)
- type Notification
- type Port
- type ScriptFile
- type Tag
- type Transaction
- type User
- type UserChallenges
Constants ¶
This section is empty.
Variables ¶
var ( DBMux *sync.Mutex Db *gorm.DB )
Functions ¶
func AddNotification ¶
func AddNotification(notification *Notification) error
Create an entry for the notification in the Notification table It returns an error if anything wrong happen during the transaction.
func BatchUpdateChallenge ¶
This function updates a challenge entry in the database, whereMap is the map which contains key value pairs of column and values to filter out the record to update. chall is the Challenge variable with the values to update with. This function returns any error that might occur while updating the challenge entry which includes the error in case the challenge already does not exist in the database.
func CheckPreviousSubmissions ¶
Check whether challenge is submitted by the user
func CreateChallengeEntry ¶
Create an entry for the challenge in the Challenge table It returns an error if anything wrong happen during the transaction.
func CreateUserEntry ¶
Create an entry for the user in the User table It returns an error if anything wrong happen during the transaction.
func DeleteChallengeEntry ¶
func DeleteNotification ¶
func DeleteNotification(notification *Notification) error
Remove entry for the notification in the Notification table
func DeleteRelatedPorts ¶
func GetUserRank ¶
func QueryOrCreateTagEntry ¶
Queries or Create if not Exist
func SaveFlagSubmission ¶
func SaveFlagSubmission(user_challenges *UserChallenges) error
func SaveTransaction ¶
func SaveTransaction(transaction *Transaction) error
func UpdateChallenge ¶
Update an entry for the challenge in the Challenge table
func UpdateNotification ¶
func UpdateNotification(notify *Notification, m map[string]interface{}) error
Update an entry for the notification in the Notification table
func UpdateUser ¶
Update an entry for the user in the User table
Types ¶
type AuthorizedKeyTemplate ¶
type Challenge ¶
type Challenge struct { gorm.Model Name string `gorm:"not null;type:varchar(64);unique"` Flag string `gorm:"not null;type:text"` Type string `gorm:"type:varchar(64)"` Sidecar string `gorm:"type:varchar(64)"` Hints string `gorm:"type:text"` Description string `gorm:"type:text"` Format string `gorm:"not null"` ContainerId string `gorm:"size:64;unique"` ImageId string `gorm:"size:64;unique"` Status string `gorm:"not null;default:'Undeployed'"` AuthorID uint `gorm:"not null"` HealthCheck uint `gorm:"not null;default:1"` Points uint `gorm:"default:0"` Ports []Port Tags []*Tag `gorm:"many2many:tag_challenges;"` Users []*User `gorm:"many2many:user_challenges;"` }
The `challenges` table has the following columns name author format container_id image_id status
Some hooks needs to be attached to these database transaction, and on the basis of the type of the transaction that is performed on the challenge table, we need to perform some action.
Use gorm hooks for these purpose, currently the following hooks are implemented. * AfterUpdate * AfterCreate * AfterSave * AfterDelete
All these hooks are used for generating the access shell script for the challenge to the challenge author
func GetRelatedChallenges ¶
Get Related Challenges
func QueryAllChallenges ¶
Query challenges table to get all the entries in the table
func QueryChallengeEntries ¶
Queries all the challenges entries where the column represented by key have the value in value.
func QueryChallengeEntriesMap ¶
Queries all the challenges entries where the column matches
func QueryFirstChallengeEntry ¶
Using the column value in key and value in value get the first result of the query.
func QueryRelatedChallenges ¶
Query Related Challenges
func (*Challenge) AfterCreate ¶
hook after create of challenge
func (*Challenge) AfterDelete ¶
hook after deleting the challenge
type Notification ¶
type Notification struct { gorm.Model Title string `gorm:not null;unique` Description string `gorm:not null` }
func QueryAllNotification ¶
func QueryAllNotification() ([]Notification, error)
Query Notification table to get all the entries in the table
func QueryFirstNotificationEntry ¶
func QueryFirstNotificationEntry(key string, value string) (Notification, error)
Using the column value in key and value in value get the first result of the query.
func QueryNotificationEntries ¶
func QueryNotificationEntries(key string, value string) ([]Notification, error)
Queries all the challenges entries where the column represented by key have the value in value.
type Port ¶
type Port struct { gorm.Model ChallengeID uint `gorm:"not null"` PortNo uint32 `gorm:"not null;unique"` }
func GetAllocatedPorts ¶
func PortEntryGetOrCreate ¶
Create an entry for the port in the Port table It returns an error if anything wrong happen during the transaction. If the entry already exists then it does not do anything and returns.
type ScriptFile ¶
type Tag ¶
type Transaction ¶
type User ¶
type User struct { gorm.Model auth.AuthModel Challenges []*Challenge `gorm:"many2many:user_challenges;"` Name string `gorm:"not null"` Email string `gorm:"non null;unique"` SshKey string Status uint `gorm:"not null;default:0"` // 0 for unbanned, 1 for banned Score uint `gorm:"default:0"` }
func QueryFirstUserEntry ¶
Using the column value in key and value in value get the first result of the query.
func QueryUserById ¶
func QueryUserEntries ¶
Queries all the users entries where the column represented by key have the value in value.
func (*User) AfterDelete ¶
Updating data in same transaction
type UserChallenges ¶
func QueryAllSubmissions ¶
func QueryAllSubmissions() ([]UserChallenges, error)
Query challenges table to get all the entries in the table