summaryrefslogtreecommitdiff
path: root/internal/server/institute.go
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2024-03-13 16:22:32 +0100
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2024-03-13 16:27:24 +0100
commitd182c9d52e7e27bb3d5a698d4788a3f0919012bc (patch)
tree3e9bd451bb4c6e3b880cc8c18198915a6d3d5d8c /internal/server/institute.go
parente604b1e1424edff72f4f0e7f447e66ffee850110 (diff)
Client + Server: Refactor adding a server by first adding then auth
Otherwise we go to the main state after auth is done and the server is not yet added
Diffstat (limited to 'internal/server/institute.go')
-rw-r--r--internal/server/institute.go31
1 files changed, 16 insertions, 15 deletions
diff --git a/internal/server/institute.go b/internal/server/institute.go
index aa032c7..195c2ef 100644
--- a/internal/server/institute.go
+++ b/internal/server/institute.go
@@ -2,7 +2,6 @@ package server
import (
"context"
- "time"
"github.com/eduvpn/eduvpn-common/internal/api"
"github.com/eduvpn/eduvpn-common/internal/config/v2"
@@ -16,11 +15,11 @@ import (
// `disco` are the discovery servers
// `id` is the identifier for the server, the base url
// `na` is true when authorization should not be triggered
-func (s *Servers) AddInstitute(ctx context.Context, disco *discovery.Discovery, id string, na bool) (*Server, error) {
+func (s *Servers) AddInstitute(ctx context.Context, disco *discovery.Discovery, id string, na bool) error {
// This is basically done to double check if the server is part of the institute access section of disco
dsrv, err := disco.ServerByURL(id, "institute_access")
if err != nil {
- return nil, err
+ return err
}
sd := api.ServerData{
@@ -30,22 +29,24 @@ func (s *Servers) AddInstitute(ctx context.Context, disco *discovery.Discovery,
BaseAuthWK: dsrv.BaseURL,
}
- var a *api.API
- if !na {
- // Authorize by creating the API object
- a, err = api.NewAPI(ctx, s.clientID, sd, s.cb, nil)
- if err != nil {
- return nil, err
- }
+ err = s.config.AddServer(dsrv.BaseURL, server.TypeInstituteAccess, v2.Server{})
+ if err != nil {
+ return err
}
- err = s.config.AddServer(dsrv.BaseURL, server.TypeInstituteAccess, v2.Server{LastAuthorizeTime: time.Now()})
- if err != nil {
- return nil, err
+ // no authorization should be triggered, return
+ if na {
+ return nil
}
- inst := s.NewServer(dsrv.BaseURL, server.TypeInstituteAccess, a)
- return &inst, nil
+ // Authorize by creating the API object
+ _, err = api.NewAPI(ctx, s.clientID, sd, s.cb, nil)
+ if err != nil {
+ // authorization has failed, remove the server again
+ s.config.RemoveServer(dsrv.BaseURL, server.TypeInstituteAccess)
+ return err
+ }
+ return nil
}
// GetInstitute gets an institute access server