Commit 05f70ff3 authored by Miklós Tóth's avatar Miklós Tóth 🤷
Browse files

All done.

parent facdc40a
Pipeline #8884 failed with stages
in 1 minute and 11 seconds
......@@ -5,7 +5,7 @@ replace git.sch.bme.hu/kszk/schmatrix/games/qpa-team-puller => ./
go 1.17
require (
git.sch.bme.hu/kszk/schmatrix/games/aggregator-backend v0.0.0-20211002191021-b2ba927df5b8 // indirect
git.sch.bme.hu/kszk/schmatrix/games/aggregator-backend v0.0.0-20211002224548-6fd8cdcf4aec // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/caarlos0/env/v6 v6.7.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
......@@ -17,7 +17,10 @@ require (
github.com/go-playground/validator/v10 v10.9.0 // indirect
github.com/go-redis/redis/v8 v8.11.3 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/heptiolabs/healthcheck v0.0.0-20180807145615-6ff867650f40 // indirect
github.com/igm/sockjs-go/v3 v3.0.1 // indirect
github.com/jinzhu/copier v0.3.2 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
......@@ -27,7 +30,7 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/prometheus/client_golang v1.11.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.31.0 // indirect
github.com/prometheus/common v0.31.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/ugorji/go/codec v1.2.6 // indirect
gitlab.com/MikeTTh/env v0.0.0-20210102155928-2e9be3823cc7 // indirect
......
......@@ -33,6 +33,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
git.sch.bme.hu/kszk/schmatrix/games/aggregator-backend v0.0.0-20211002191021-b2ba927df5b8 h1:8hnkKtBaRZ2xXoar9KVI+9JUoqXXBXRtfdRP/84dlMI=
git.sch.bme.hu/kszk/schmatrix/games/aggregator-backend v0.0.0-20211002191021-b2ba927df5b8/go.mod h1:caV41v/g+/OA8m222XhQ6JUmYP4sY1IBIYn7m2YlnpY=
git.sch.bme.hu/kszk/schmatrix/games/aggregator-backend v0.0.0-20211002224548-6fd8cdcf4aec h1:NX6Y3aD1vC9VthMtbMjAdUQyADL+64j8AUjuvDXAz/g=
git.sch.bme.hu/kszk/schmatrix/games/aggregator-backend v0.0.0-20211002224548-6fd8cdcf4aec/go.mod h1:caV41v/g+/OA8m222XhQ6JUmYP4sY1IBIYn7m2YlnpY=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
......@@ -146,14 +148,20 @@ github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hf
github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/heptiolabs/healthcheck v0.0.0-20180807145615-6ff867650f40 h1:GT4RsKmHh1uZyhmTkWJTDALRjSHYQp6FRKrotf0zhAs=
github.com/heptiolabs/healthcheck v0.0.0-20180807145615-6ff867650f40/go.mod h1:NtmN9h8vrTveVQRLHcX2HQ5wIPBDCsZ351TGbZWgg38=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/igm/sockjs-go/v3 v3.0.1 h1:rmgEkeKqBHCFf7uIAipYrYSX8x9LBB2nOxAac2sooak=
github.com/igm/sockjs-go/v3 v3.0.1/go.mod h1:UqchsOjeagIBFHvd+RZpLaVRbCwGilEC08EDHsD1jYE=
github.com/jinzhu/copier v0.3.2 h1:QdBOCbaouLDYaIPFfi1bKv5F5tPpeTwXe4sD0jqtz5w=
github.com/jinzhu/copier v0.3.2/go.mod h1:24xnZezI2Yqac9J61UC6/dG/k76ttpq0DdJI3QmUvro=
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
......@@ -223,6 +231,8 @@ github.com/prometheus/common v0.26.0 h1:iMAkS2TDoNWnKM+Kopnx/8tnEStIfpYA0ur0xQzz
github.com/prometheus/common v0.26.0/go.mod h1:M7rCNAaPfAosfx8veZJCuw84e35h3Cfd9VFqTh1DIvc=
github.com/prometheus/common v0.31.0 h1:FTJdLTjtrh4dXlCjpzdZJXMnejSTL5F/nVQm5sNwD34=
github.com/prometheus/common v0.31.0/go.mod h1:vu+V0TpY+O6vW9J44gczi3Ap/oXXR10b+M/gUGO4Hls=
github.com/prometheus/common v0.31.1 h1:d18hG4PkHnNAKNMOmFuXFaiY8Us0nird/2m60uS1AMs=
github.com/prometheus/common v0.31.1/go.mod h1:vu+V0TpY+O6vW9J44gczi3Ap/oXXR10b+M/gUGO4Hls=
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
......
......@@ -12,10 +12,12 @@ var _ = func() error {
}()
func main() {
er := sync.Do()
if er != nil {
panic(er)
}
go func() {
e := sync.RunLoop()
if e != nil {
log.Fatal(e)
}
}()
e := monitor.Run(c.MgmtPort)
if e != nil {
......
......@@ -2,7 +2,7 @@ package qpa
import (
"encoding/json"
"fmt"
"errors"
)
type Team struct {
......@@ -12,10 +12,16 @@ type Team struct {
Score int
}
var ErrorUnauth = errors.New("unauthorized")
func GetTeams() ([]Team, error) {
r, e := client.Get("https://schq.party/api/up/server/api/team/listActiveTeamsWithScores")
if e != nil {
fmt.Println(e)
return nil, e
}
if r.StatusCode == 403 {
return nil, ErrorUnauth
}
dec := json.NewDecoder(r.Body)
......
......@@ -15,17 +15,14 @@ import (
"time"
)
func login() error {
/*
X-Oauth2-Override-Redirection-Origin: https://schq.party
*/
func Login() error {
req, e := http.NewRequest(http.MethodGet, "https://schq.party/api/up/server/login/oauth2/authsch", nil)
if e != nil {
return e
}
req.Header.Set("X-Oauth2-Override-Redirection-Origin", "https://schq.party")
req.Header.Set("Return-Api-Oauth-Redirection-Response", "true")
req.Header.Set("Return-Api-Oauth-Redirection-Response", "true") // WTF?
r, e := client.Do(req)
if e != nil {
......@@ -125,7 +122,7 @@ func init() {
Jar: j,
}
e = login()
e = Login()
if e != nil {
log.Fatal(e)
}
......
package sync
import (
"fmt"
"context"
"git.sch.bme.hu/kszk/schmatrix/games/aggregator-backend/db"
"git.sch.bme.hu/kszk/schmatrix/games/qpa-team-puller/qpa"
"github.com/google/uuid"
"log"
"time"
)
func Do() error {
log.Println("Syncing...")
ctx := context.Background()
teams, e := qpa.GetTeams()
if e == qpa.ErrorUnauth {
e = qpa.Login()
}
if e != nil {
return e
}
dbTeams, e := db.GetTeams(ctx)
if e != nil {
return e
}
fmt.Println(teams)
i := 0
for _, t := range teams {
found := false
for _, t2 := range dbTeams {
if t.Name == t2 {
found = true
}
}
if !found {
id := ""
for id == "" {
u, e := uuid.NewUUID()
if e != nil {
return e
}
id = u.String()
if _, ok := dbTeams[id]; ok {
id = ""
}
}
e := db.AddTeam(ctx, id, t.Name)
if e != nil {
return e
}
i++
}
}
log.Println(i, "new teams added")
return nil
}
func RunLoop() error {
for {
e := Do()
if e != nil {
return e
}
time.Sleep(5 * time.Minute)
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment