diff --git a/daemon/exercise.go b/daemon/exercise.go index c717c672..b6e5551d 100644 --- a/daemon/exercise.go +++ b/daemon/exercise.go @@ -10,7 +10,6 @@ import ( pb "github.com/aau-network-security/haaukins/daemon/proto" eproto "github.com/aau-network-security/haaukins/exercise/ex-proto" - "github.com/aau-network-security/haaukins/lab" "github.com/aau-network-security/haaukins/store" storeProto "github.com/aau-network-security/haaukins/store/proto" "github.com/golang/protobuf/jsonpb" @@ -280,17 +279,20 @@ func (d *daemon) AddChallenge(req *pb.AddChallengeRequest, srv pb.Daemon_AddChal } } + ev.PauseSignup(true) var addChalError error - var lb interface{} - sendBackLab := make(chan lab.Lab) - go func() { - lb = <-ev.GetHub().Queue() - if err := lb.(lab.Lab).AddChallenge(ctx, exers...); err != nil { - addChalError = err - } - sendBackLab <- lb.(lab.Lab) - ev.GetHub().Update(sendBackLab) - }() + + for _, lb := range ev.GetHub().Labs() { + waitGroup.Add(1) + go func() { + if err := lb.AddChallenge(ctx, exers...); err != nil { + addChalError = err + } + waitGroup.Done() + }() + waitGroup.Wait() + } + ev.PauseSignup(false) frontendData := ev.GetFrontendData() for tid, l := range ev.GetAssignedLabs() { diff --git a/lab/hub.go b/lab/hub.go index 5a277c93..49d88d07 100644 --- a/lab/hub.go +++ b/lab/hub.go @@ -24,6 +24,7 @@ type Hub interface { Suspend(context.Context) error Resume(context.Context) error Update(labTag <-chan Lab) + Labs() map[string]Lab UpdateExercises(exercises []store.Exercise) } @@ -212,3 +213,7 @@ func (h *hub) Resume(ctx context.Context) error { return resumeError } + +func (h *hub) Labs() map[string]Lab { + return h.labs +} diff --git a/svcs/amigo/amigo.go b/svcs/amigo/amigo.go index 4da40ba0..bf362320 100644 --- a/svcs/amigo/amigo.go +++ b/svcs/amigo/amigo.go @@ -67,6 +67,7 @@ type siteInfo struct { Hosts []Hosts Notification Notification LabSubnet string + SignupPaused bool // this is used when add challenge is executed in the platform } type team struct { @@ -134,6 +135,10 @@ func (am *Amigo) SetNotification(n Notification) { am.globalInfo.Notification = n } +func (am *Amigo) PauseSignup(pause bool) { + am.globalInfo.SignupPaused = pause +} + func (am *Amigo) getSiteInfo(w http.ResponseWriter, r *http.Request) siteInfo { info := am.globalInfo diff --git a/svcs/amigo/resources/private/signup.tmpl.html b/svcs/amigo/resources/private/signup.tmpl.html index f53c47c1..f74b27f8 100644 --- a/svcs/amigo/resources/private/signup.tmpl.html +++ b/svcs/amigo/resources/private/signup.tmpl.html @@ -4,56 +4,63 @@