diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2023-09-01 16:19:29 +0200 |
|---|---|---|
| committer | Jeroen Wijenbergh <46386452+jwijenbergh@users.noreply.github.com> | 2023-09-01 17:15:52 +0000 |
| commit | 0c14a204ae13f7692a5708451b40f87832f7388a (patch) | |
| tree | 0d9c48397e143adcce2b227c7cf7a6fc48f82adf /internal | |
| parent | 1ee57ae13a4d42c44fe6259f2a2d48f0cd20519a (diff) | |
Client + Server: Increase endpoint update frequency and update secure internet handling
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/server/instituteaccess.go | 22 | ||||
| -rw-r--r-- | internal/server/secureinternet.go | 37 | ||||
| -rw-r--r-- | internal/server/server.go | 25 |
3 files changed, 63 insertions, 21 deletions
diff --git a/internal/server/instituteaccess.go b/internal/server/instituteaccess.go index 050e721..a51409f 100644 --- a/internal/server/instituteaccess.go +++ b/internal/server/instituteaccess.go @@ -1,6 +1,7 @@ package server import ( + "github.com/eduvpn/eduvpn-common/internal/discovery" "github.com/eduvpn/eduvpn-common/internal/oauth" "github.com/go-errors/errors" ) @@ -72,6 +73,27 @@ func (ias *InstituteAccessServer) OAuth() *oauth.OAuth { return &ias.Auth } +func (ias *InstituteAccessServer) RefreshEndpoints(_ *discovery.Discovery) error { + // Re-initialize the endpoints + b, err := ias.Base() + if err != nil { + return err + } + + err = b.InitializeEndpoints() + if err != nil { + return err + } + + // update OAuth + auth := ias.OAuth() + if auth != nil { + auth.BaseAuthorizationURL = b.Endpoints.API.V3.Authorization + auth.TokenURL = b.Endpoints.API.V3.Token + } + return nil +} + func (ias *InstituteAccessServer) init( url string, name map[string]string, diff --git a/internal/server/secureinternet.go b/internal/server/secureinternet.go index 9b1d394..3c40253 100644 --- a/internal/server/secureinternet.go +++ b/internal/server/secureinternet.go @@ -1,6 +1,7 @@ package server import ( + "github.com/eduvpn/eduvpn-common/internal/discovery" "github.com/eduvpn/eduvpn-common/internal/oauth" "github.com/eduvpn/eduvpn-common/internal/util" "github.com/eduvpn/eduvpn-common/types" @@ -136,3 +137,39 @@ func (s *SecureInternetHomeServer) init( s.Auth.Init(b.URL, b.Endpoints.API.V3.Authorization, b.Endpoints.API.V3.Token) return nil } + +func (s *SecureInternetHomeServer) RefreshEndpoints(disco *discovery.Discovery) error { + // update OAuth for home server + auth := s.OAuth() + if auth != nil && s.HomeOrganizationID != "" { + _, srv, err := disco.SecureHomeArgs(s.HomeOrganizationID) + if err != nil { + return err + } + if hb, ok := s.BaseMap[srv.CountryCode]; ok && hb != nil { + err := hb.InitializeEndpoints() + if err != nil { + return err + } + auth.BaseAuthorizationURL = hb.Endpoints.API.V3.Authorization + auth.TokenURL = hb.Endpoints.API.V3.Token + } + // already updated, return + if srv.CountryCode == s.CurrentLocation { + return nil + } + } + + // refresh the current location endpoints + // Re-initialize the endpoints + b, err := s.Base() + if err != nil { + return err + } + + err = b.InitializeEndpoints() + if err != nil { + return err + } + return nil +} diff --git a/internal/server/server.go b/internal/server/server.go index f62b882..775095c 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -4,6 +4,7 @@ import ( "os" "time" + "github.com/eduvpn/eduvpn-common/internal/discovery" "github.com/eduvpn/eduvpn-common/internal/oauth" "github.com/eduvpn/eduvpn-common/internal/wireguard" "github.com/go-errors/errors" @@ -25,6 +26,9 @@ type Server interface { // Base returns the server base Base() (*Base, error) + + // RefreshEndpoints + RefreshEndpoints(*discovery.Discovery) error } type EndpointList struct { @@ -251,27 +255,6 @@ func HasValidProfile(srv Server, wireguardSupport bool) (bool, error) { return true, nil } -func RefreshEndpoints(srv Server) error { - // Re-initialize the endpoints - b, err := srv.Base() - if err != nil { - return err - } - - err = b.InitializeEndpoints() - if err != nil { - return err - } - - // update OAuth - auth := srv.OAuth() - if auth != nil { - auth.BaseAuthorizationURL = b.Endpoints.API.V3.Authorization - auth.TokenURL = b.Endpoints.API.V3.Token - } - return nil -} - func Config(server Server, wireguardSupport bool, preferTCP bool) (*ConfigData, error) { p, err := CurrentProfile(server) if err != nil { |
