Compare commits

..

2 Commits

Author SHA1 Message Date
c688db5e62 chore(deps): update dependency @sveltejs/kit to v2.20.2
All checks were successful
continuous-integration/drone/push Build is passing
2025-03-24 22:20:59 +00:00
7df675346c challenge-sync-airbus: 2025 API ready
All checks were successful
continuous-integration/drone/push Build is passing
2025-03-24 19:31:59 +01:00
6 changed files with 62 additions and 60 deletions

View File

@ -14,10 +14,18 @@ import (
type AirbusAPI struct {
BaseURL string
Token string
SessionID int64
SessionUUID string
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
@ -51,7 +59,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(out); err != nil {
if err := jdec.Decode(&AirbusAPIResponse{Data: out}); err != nil {
return fmt.Errorf("an error occurs when trying to decode response: %w", err)
}
}
@ -87,7 +95,7 @@ type AirbusUser struct {
}
func (a *AirbusAPI) GetUsers() (users AirbusUserData, err error) {
err = a.request("GET", fmt.Sprintf("/sessions/%d/users", a.SessionID), nil, &users)
err = a.request("GET", fmt.Sprintf("/sessions/%s/users", a.SessionUUID), nil, &users)
return
}
@ -137,7 +145,7 @@ type AirbusChallenge struct {
}
func (a *AirbusAPI) GetChallenges() (challenges AirbusChallengeData, err error) {
err = a.request("GET", fmt.Sprintf("/v1/sessions/%d/challenges", a.SessionID), nil, &challenges)
err = a.request("GET", fmt.Sprintf("/v1/sessions/%s/challenges", a.SessionUUID), nil, &challenges)
return
}
@ -157,24 +165,22 @@ func (a *AirbusAPI) GetChallengeFromName(name string) (*AirbusChallenge, error)
}
func (a *AirbusAPI) ValidateChallengeFromUser(team *AirbusTeam, challengeId AirbusChallengeId) (err error) {
log.Printf("ValidateChallenge: %d, %s, %d", a.SessionID, challengeId.String(), team.Members[0].ID)
log.Printf("ValidateChallenge: %s, %s, %s", a.SessionUUID, challengeId.String(), team.Members[0].UUID)
if dryRun {
return
}
err = a.request("GET", fmt.Sprintf("/v1/sessions/%d/%s/%d/validate", a.SessionID, challengeId.String(), team.Members[0].ID), nil, nil)
err = a.request("GET", fmt.Sprintf("/v1/sessions/%s/%s/%s/validate", a.SessionUUID, challengeId.String(), team.Members[0].UUID), nil, nil)
return
}
type AirbusUserAwards struct {
UserId int64 `json:"gaming_user_id"`
Message string `json:"name"`
Value int64 `json:"value"`
}
func (a *AirbusAPI) AwardUser(team *AirbusTeam, value int64, message string) (err error) {
awards := AirbusUserAwards{
UserId: team.Members[0].ID,
Message: message,
Value: value,
}
@ -190,7 +196,7 @@ func (a *AirbusAPI) AwardUser(team *AirbusTeam, value int64, message string) (er
return
}
err = a.request("POST", fmt.Sprintf("/v1/sessions/%d/awards", a.SessionID), bytes.NewReader(marshalled), nil)
err = a.request("POST", fmt.Sprintf("/v1/sessions/%s/%s/awards", a.SessionUUID, team.Members[0].UUID), bytes.NewReader(marshalled), nil)
if err != nil {
return err
}

View File

@ -77,12 +77,8 @@ func main() {
fd.Close()
}
if v, exists := os.LookupEnv("AIRBUS_SESSIONID"); exists {
var err error
api.SessionID, err = strconv.ParseInt(v, 10, 64)
if err != nil {
log.Fatal("AIRBUS_SESSIONID is invalid: ", err.Error())
}
if v, exists := os.LookupEnv("AIRBUS_SESSION_UUID"); exists {
api.SessionUUID = v
} else if v, exists := os.LookupEnv("AIRBUS_SESSION_NAME_FILE"); exists {
fd, err := os.Open(v)
if err != nil {
@ -101,15 +97,15 @@ func main() {
for _, session := range sessions {
if session.Name == v {
api.SessionID = session.ID
api.SessionUUID = session.UUID
break
}
}
if api.SessionID == 0 {
if api.SessionUUID == "" {
log.Fatal("Session ID not found")
} else {
log.Println("Session ID discovered: ", api.SessionID)
log.Println("Session ID discovered: ", api.SessionUUID)
}
} else if v, exists := os.LookupEnv("AIRBUS_SESSION_NAME"); exists {
sessions, err := api.GetSessions()
@ -117,17 +113,19 @@ func main() {
log.Fatal("Unable to retrieve session: ", err)
}
found := false
for _, session := range sessions {
if session.Name == v {
api.SessionID = session.ID
api.SessionUUID = session.UUID
found = true
break
}
}
if api.SessionID == 0 {
if !found {
log.Fatal("Session ID not found")
} else {
log.Println("Session ID discovered: ", api.SessionID)
log.Println("Session ID discovered: ", api.SessionUUID)
}
} else {
sessions, err := api.GetSessions()
@ -138,7 +136,7 @@ func main() {
log.Println("Please define your AIRBUS_SESSIONID or AIRBUS_SESSION_NAME.")
log.Println("Existing sessions are:")
for _, session := range sessions {
log.Printf(" - %d: %q", session.ID, session.Name)
log.Printf(" - %s: %q", session.UUID, session.Name)
}
os.Exit(1)
}
@ -154,13 +152,14 @@ func main() {
log.Println("Unable to retrieve teams:", err)
os.Exit(1)
}
log.Println(teams)
fmt.Println("## Airbus' registered teams:")
fmt.Println("-------------------------------------------")
fmt.Println(" ID | Name | Nb. | Score | Rank")
fmt.Println("-------------------------------------------")
fmt.Println("----------------------------------------------------------------------------------")
fmt.Println(" UUID | Name | Nb. | Score | Rank")
fmt.Println("----------------------------------------------------------------------------------")
for _, team := range teams {
fmt.Printf("% 2d | % 15s | % 3d | % 5d | % 3d\n", team.ID, team.Name, len(team.Members), team.Score, team.Rank)
fmt.Printf(" %s | % 20s | % 3d | % 5d | % 3d\n", team.UUID, team.Name, len(team.Members), team.Score, team.Rank)
}
case "rank":
teams, err := api.GetTeams()
@ -178,11 +177,11 @@ func main() {
sort.Sort(sort.Reverse(ByScore(ranking)))
fmt.Println("## Airbus' ranking:")
fmt.Println("-------------------------------------")
fmt.Println(" Rank | Name | ID | Score")
fmt.Println("-------------------------------------")
fmt.Println("----------------------------------------------------------------------------")
fmt.Println(" Rank | Name | UUID | Score")
fmt.Println("----------------------------------------------------------------------------")
for _, team := range ranking {
fmt.Printf("% 5d | % 15s |% 3d | % 5d\n", team.Rank, team.Name, team.ID, team.Score)
fmt.Printf("% 5d | % 20s | %s | % 5d\n", team.Rank, team.Name, team.UUID, team.Score)
}
case "get":
teams, err := api.GetTeams()
@ -191,22 +190,18 @@ func main() {
os.Exit(1)
}
teamid, err := strconv.ParseInt(args[1], 10, 64)
if err != nil {
log.Println(err)
os.Exit(1)
}
teamid := args[1]
for _, team := range teams {
if team.ID == teamid {
fmt.Printf("## Airbus' registered team %d:\n\nID: %d\nName: %s\nScore: %d\nRank: %d\nMembers:\n", teamid, team.ID, team.Name, team.Score, team.Rank)
if team.UUID == teamid {
fmt.Printf("## Airbus' registered team %s:\n\nUUID: %s\nName: %s\nScore: %d\nRank: %d\nMembers:\n", teamid, team.UUID, team.Name, team.Score, team.Rank)
for _, member := range team.Members {
fmt.Printf(" - ID: %d\n Name: %s\n Nickname: %s\n E-mail: %s\n", member.ID, member.Name, member.Nickname, member.EMail)
fmt.Printf(" - UUID: %s\n Name: %s\n Nickname: %s\n E-mail: %s\n", member.UUID, member.Name, member.Nickname, member.EMail)
}
os.Exit(0)
}
}
fmt.Printf("Team %d not found. Use 'list' to view all existing teams\n", teamid)
fmt.Printf("Team %s not found. Use 'list' to view all existing teams\n", teamid)
case "award":
if len(args) < 3 {
fmt.Println("award <TEAM_ID> <VALUE> <MESSAGE>")
@ -219,11 +214,7 @@ func main() {
os.Exit(1)
}
teamid, err := strconv.ParseInt(args[1], 10, 64)
if err != nil {
log.Println("Invalid team id", err)
os.Exit(1)
}
teamid := args[1]
value, err := strconv.ParseInt(args[2], 10, 64)
if err != nil {
@ -232,7 +223,7 @@ func main() {
}
for _, team := range teams {
if team.ID == teamid {
if team.UUID == teamid {
err = api.AwardUser(&team, value, strings.Join(args[3:], " "))
if err != nil {
log.Println("Unable to award team:", err)
@ -243,7 +234,7 @@ func main() {
os.Exit(0)
}
}
fmt.Printf("Team %d not found. Use 'list' to view all existing teams\n", teamid)
fmt.Printf("Team %s not found. Use 'list' to view all existing teams\n", teamid)
}
os.Exit(0)

View File

@ -1,12 +1,18 @@
package main
import ()
import (
"time"
)
type Session struct {
Name string `json:"name"`
QuestionValidation string `json:"question_validation"`
Status string `json:"status"`
ID int64 `json:"id"`
UUID string `json:"uuid"`
Mode string `json:"mode"`
Difficulty int `json:"difficulty"`
StartedAt time.Time `json:"start_at"`
FinishAt time.Time `json:"finish_at"`
}
func (a *AirbusAPI) GetSessions() (ret []Session, err error) {

View File

@ -5,7 +5,7 @@ import (
)
type AirbusTeam struct {
ID int64 `json:"id"`
UUID string `json:"session_uuid"`
Members []TeamMember `json:"members"`
Name string `json:"name"`
Score int64 `json:"score"`
@ -13,23 +13,21 @@ type AirbusTeam struct {
}
type TeamMember struct {
ID int64 `json:"id"`
UUID string `json:"session_uuid"`
Name string `json:"name"`
Nickname string `json:"nickname"`
EMail string `json:"email"`
}
type airbusDataTeam struct {
Data []AirbusTeam `json:"data"`
}
type airbusDataTeam []AirbusTeam
func (a *AirbusAPI) GetTeams() ([]AirbusTeam, error) {
var data airbusDataTeam
err := a.request("GET", fmt.Sprintf("/v1/sessions/%d/teams", a.SessionID), nil, &data)
err := a.request("GET", fmt.Sprintf("/v1/sessions/%s/teams", a.SessionUUID), nil, &data)
if err != nil {
return nil, err
} else {
return data.Data, nil
return data, nil
}
}

View File

@ -1,6 +1,7 @@
[
{
"name": "#D\u00e9fendonsEnsemble",
"external_id": "89b35c67-1aa4-43e2-b9da-7f9e7fdfa649",
"score": 0
},
{

View File

@ -39,7 +39,7 @@ func (w *Walker) fetchTeams() error {
for tid, team := range w.Teams {
for i, t := range teams {
if team.Name == t.Name || team.ExternalId == t.Name {
if team.Name == t.Name || team.ExternalId == t.Name || team.ExternalId == t.UUID {
w.TeamBindings[tid] = &teams[i]
break
}