challenge-sync-airbus: Refactor and prefer calling it cyberrange
This commit is contained in:
parent
98d9f2daf3
commit
cb4ceecbf5
6 changed files with 46 additions and 37 deletions
|
|
@ -9,6 +9,8 @@ import (
|
|||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"srs.epita.fr/fic-server/libfic"
|
||||
)
|
||||
|
||||
type AirbusAPI struct {
|
||||
|
|
@ -18,14 +20,6 @@ type AirbusAPI struct {
|
|||
InsecureSkipVerify bool
|
||||
}
|
||||
|
||||
type AirbusAPIResponse struct {
|
||||
Data interface{}
|
||||
CurrentPage int `json:"current_page"`
|
||||
PerPage int `json:"per_page"`
|
||||
LastPage int `json:"last_page"`
|
||||
Total int `json:"total"`
|
||||
}
|
||||
|
||||
func (a *AirbusAPI) request(method, endpoint string, data io.Reader, out interface{}) error {
|
||||
var req *http.Request
|
||||
var err error
|
||||
|
|
@ -59,7 +53,7 @@ func (a *AirbusAPI) request(method, endpoint string, data io.Reader, out interfa
|
|||
if out != nil {
|
||||
jdec := json.NewDecoder(resp.Body)
|
||||
|
||||
if err := jdec.Decode(&AirbusAPIResponse{Data: out}); err != nil {
|
||||
if err := jdec.Decode(&fic.CyberrangeAPIResponse{Data: out}); err != nil {
|
||||
return fmt.Errorf("an error occurs when trying to decode response: %w", err)
|
||||
}
|
||||
}
|
||||
|
|
@ -164,7 +158,7 @@ func (a *AirbusAPI) GetChallengeFromName(name string) (*AirbusChallenge, error)
|
|||
return nil, fmt.Errorf("unable to find challenge %q", name)
|
||||
}
|
||||
|
||||
func (a *AirbusAPI) ValidateChallengeFromUser(team *AirbusTeam, challengeId AirbusChallengeId) (err error) {
|
||||
func (a *AirbusAPI) ValidateChallengeFromUser(team *fic.CyberrangeTeam, challengeId AirbusChallengeId) (err error) {
|
||||
log.Printf("ValidateChallenge: %s, %s, %s", a.SessionUUID, challengeId.String(), team.Members[0].UUID)
|
||||
if dryRun {
|
||||
return
|
||||
|
|
@ -179,7 +173,7 @@ type AirbusUserAwards struct {
|
|||
Value int64 `json:"value"`
|
||||
}
|
||||
|
||||
func (a *AirbusAPI) AwardUser(team *AirbusTeam, value int64, message string) (err error) {
|
||||
func (a *AirbusAPI) AwardUser(team *fic.CyberrangeTeam, value int64, message string) (err error) {
|
||||
awards := AirbusUserAwards{
|
||||
Message: message,
|
||||
Value: value,
|
||||
|
|
|
|||
Reference in a new issue