From eb57e36d3c017bef80277e97db1009c38893ce2d Mon Sep 17 00:00:00 2001 From: jwijenbergh Date: Wed, 22 Mar 2023 12:16:54 +0100 Subject: Exports + Client: Refactor registering a client - Make sure the global exports state is only set on successful creating - Only call discovery when adding a server to ensure we get the most up to date args. Creating a client should have no network calls. Fixes #12 - Split creating a client in New and Register in the GO api --- client/server.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'client/server.go') diff --git a/client/server.go b/client/server.go index 6c0b4d2..7a14d00 100644 --- a/client/server.go +++ b/client/server.go @@ -9,8 +9,8 @@ import ( "github.com/eduvpn/eduvpn-common/internal/oauth" "github.com/eduvpn/eduvpn-common/internal/server" discotypes "github.com/eduvpn/eduvpn-common/types/discovery" - srvtypes "github.com/eduvpn/eduvpn-common/types/server" "github.com/eduvpn/eduvpn-common/types/protocol" + srvtypes "github.com/eduvpn/eduvpn-common/types/server" "github.com/go-errors/errors" ) @@ -264,6 +264,15 @@ func (c *Client) AddInstituteServer(url string) (err error) { // Indicate that we're loading the server c.FSM.GoTransition(StateLoadingServer) + // Check if we are able to fetch discovery, and log if something went wrong + if _, err := c.DiscoServers(); err != nil { + log.Logger.Warningf("Failed to get discovery servers: %v", err) + } + + if _, err := c.DiscoOrganizations(); err != nil { + log.Logger.Warningf("Failed to get discovery organizations: %v", err) + } + // FIXME: Do nothing with discovery here as the client already has it // So pass a server as the parameter var dSrv *discotypes.Server @@ -317,6 +326,15 @@ func (c *Client) AddSecureInternetHomeServer(orgID string) (err error) { // Indicate that we're loading the server c.FSM.GoTransition(StateLoadingServer) + // Check if we are able to fetch discovery, and log if something went wrong + if _, err := c.DiscoServers(); err != nil { + log.Logger.Warningf("Failed to get discovery servers: %v", err) + } + + if _, err := c.DiscoOrganizations(); err != nil { + log.Logger.Warningf("Failed to get discovery organizations: %v", err) + } + // Get the secure internet URL from discovery org, dSrv, err := c.Discovery.SecureHomeArgs(orgID) if err != nil { -- cgit v1.2.3