@@ -2,7 +2,10 @@ package main
22
33import (
44 "context"
5+ "encoding/json"
56 "fmt"
7+ "io"
8+ "net/http"
69 "os"
710 "strings"
811 "time"
@@ -71,16 +74,27 @@ func InitConstitution() {
7174
7275// GetEligibleVoters returns a string slice of usernames of eligible voters
7376func GetEligibleVoters () []string {
74- ret := make ([]string , 0 )
75- allactive := oidcClient .GetActiveUsers ()
76- //todo: figure out why this is slow as FORK
77- for _ , a := range allactive {
78- oidcClient .GetUserGatekeep (& a )
79- if a .Gatekeep {
80- ret = append (ret , a .Username )
81- }
77+ htclient := & http.Client {}
78+ req , err := http .NewRequest ("GET" , CONDITIONAL_GATEKEEP_URL , nil )
79+ if err != nil {
80+ logging .Logger .WithFields (logrus.Fields {"method" : "GetUserGatekeep" }).Error (err )
81+ return nil
82+ }
83+ req .Header .Add ("X-VOTE-TOKEN" , VOTE_TOKEN )
84+ resp , err := htclient .Do (req )
85+ if err != nil {
86+ logging .Logger .WithFields (logrus.Fields {"method" : "GetUserGatekeep" }).Error (err )
87+ return nil
88+ }
89+ defer resp .Body .Close ()
90+ b , _ := io .ReadAll (resp .Body )
91+ if strings .Contains (string (b ), "Users" ) {
92+ logging .Logger .WithFields (logrus.Fields {"method" : "GetUserGatekeep" }).Error ("Conditional Gatekeep token is incorrect" )
93+ return nil
8294 }
83- return ret
95+ res := make ([]string , 0 )
96+ err = json .Unmarshal (b , & res )
97+ return res
8498}
8599
86100func EvaluatePolls () {
0 commit comments