From e9f8db8ee8fccf60e58deb1d72766f94a053bb16 Mon Sep 17 00:00:00 2001 From: jwijenbergh Date: Mon, 28 Nov 2022 11:18:14 +0100 Subject: Document: Add comments for most functions and packages Errors and test files still need to be done. Also some getters are changed by removing the 'get' prefix --- client/client.go | 21 +++++++++++---------- client/fsm.go | 4 ---- client/server.go | 8 ++++---- 3 files changed, 15 insertions(+), 18 deletions(-) (limited to 'client') diff --git a/client/client.go b/client/client.go index 6ef9a9f..34981db 100644 --- a/client/client.go +++ b/client/client.go @@ -1,3 +1,4 @@ +// package client implements the public interface for creating eduVPN/Let's Connect! clients package client import ( @@ -89,9 +90,9 @@ func (client *Client) Register( client.Language = language // Initialize the logger - logLevel := log.LogWarning + logLevel := log.LevelWarning if debug { - logLevel = log.LogDebug + logLevel = log.LevelDebug } loggerErr := client.Logger.Init(logLevel, directory) @@ -126,11 +127,11 @@ func (client *Client) Register( } // Check if we are able to fetch discovery, and log if something went wrong - _, discoServersErr := client.GetDiscoServers() + _, discoServersErr := client.DiscoServers() if discoServersErr != nil { client.Logger.Warning("Failed to get discovery servers: %v", discoServersErr) } - _, discoOrgsErr := client.GetDiscoOrganizations() + _, discoOrgsErr := client.DiscoOrganizations() if discoOrgsErr != nil { client.Logger.Warning("Failed to get discovery organizations: %v", discoOrgsErr) } @@ -167,18 +168,18 @@ func (client *Client) askProfile(chosenServer server.Server) error { return nil } -// GetDiscoOrganizations gets the organizations list from the discovery server +// DiscoOrganizations gets the organizations list from the discovery server // If the list cannot be retrieved an error is returned. // If this is the case then a previous version of the list is returned if there is any. // This takes into account the frequency of updates, see: https://github.com/eduvpn/documentation/blob/v3/SERVER_DISCOVERY.md#organization-list. -func (client *Client) GetDiscoOrganizations() (*types.DiscoveryOrganizations, error) { +func (client *Client) DiscoOrganizations() (*types.DiscoveryOrganizations, error) { errorMessage := "failed getting discovery organizations list" // Not supported with Let's Connect! if client.isLetsConnect() { return nil, client.handleError(errorMessage, LetsConnectNotSupportedError{}) } - orgs, orgsErr := client.Discovery.GetOrganizationsList() + orgs, orgsErr := client.Discovery.Organizations() if orgsErr != nil { return nil, client.handleError( errorMessage, @@ -188,11 +189,11 @@ func (client *Client) GetDiscoOrganizations() (*types.DiscoveryOrganizations, er return orgs, nil } -// GetDiscoServers gets the servers list from the discovery server +// DiscoServers gets the servers list from the discovery server // If the list cannot be retrieved an error is returned. // If this is the case then a previous version of the list is returned if there is any. // This takes into account the frequency of updates, see: https://github.com/eduvpn/documentation/blob/v3/SERVER_DISCOVERY.md#server-list. -func (client *Client) GetDiscoServers() (*types.DiscoveryServers, error) { +func (client *Client) DiscoServers() (*types.DiscoveryServers, error) { errorMessage := "failed getting discovery servers list" // Not supported with Let's Connect! @@ -200,7 +201,7 @@ func (client *Client) GetDiscoServers() (*types.DiscoveryServers, error) { return nil, client.handleError(errorMessage, LetsConnectNotSupportedError{}) } - servers, serversErr := client.Discovery.GetServersList() + servers, serversErr := client.Discovery.Servers() if serversErr != nil { return nil, client.handleError( errorMessage, diff --git a/client/fsm.go b/client/fsm.go index 2ce60ba..159464a 100644 --- a/client/fsm.go +++ b/client/fsm.go @@ -119,7 +119,6 @@ func newFSM( {To: StateLoadingServer, Description: "User clicks a server in the UI"}, {To: StateNoServer, Description: "Cancel or Error"}, }, - BackState: StateNoServer, }, StateAskLocation: FSMState{ Transitions: []FSMTransition{ @@ -137,7 +136,6 @@ func newFSM( }, {To: StateNoServer, Description: "Go back or Error"}, }, - BackState: StateNoServer, }, StateChosenServer: FSMState{ Transitions: []FSMTransition{ @@ -151,7 +149,6 @@ func newFSM( {To: StateNoServer, Description: "Go back or Error"}, {To: StateSearchServer, Description: "Cancel or Error"}, }, - BackState: StateNoServer, }, StateAuthorized: FSMState{ Transitions: []FSMTransition{ @@ -182,7 +179,6 @@ func newFSM( {To: StateNoServer, Description: "User wants to choose a new server"}, {To: StateOAuthStarted, Description: "Re-authorize with OAuth"}, }, - BackState: StateNoServer, }, StateDisconnecting: FSMState{ Transitions: []FSMTransition{ diff --git a/client/server.go b/client/server.go index 12e5932..5b1a32b 100644 --- a/client/server.go +++ b/client/server.go @@ -121,7 +121,7 @@ func (client *Client) SetSecureLocation(countryCode string) error { return client.handleError(errorMessage, LetsConnectNotSupportedError{}) } - server, serverErr := client.Discovery.GetServerByCountryCode(countryCode, "secure_internet") + server, serverErr := client.Discovery.ServerByCountryCode(countryCode, "secure_internet") if serverErr != nil { client.goBackInternal() return client.handleError(errorMessage, serverErr) @@ -221,7 +221,7 @@ func (client *Client) AddInstituteServer(url string) (server.Server, error) { // FIXME: Do nothing with discovery here as the client already has it // So pass a server as the parameter - instituteServer, discoErr := client.Discovery.GetServerByURL(url, "institute_access") + instituteServer, discoErr := client.Discovery.ServerByURL(url, "institute_access") if discoErr != nil { client.goBackInternal() return nil, client.handleError(errorMessage, discoErr) @@ -273,7 +273,7 @@ func (client *Client) AddSecureInternetHomeServer(orgID string) (server.Server, client.FSM.GoTransition(StateLoadingServer) // Get the secure internet URL from discovery - secureOrg, secureServer, discoErr := client.Discovery.GetSecureHomeArgs(orgID) + secureOrg, secureServer, discoErr := client.Discovery.SecureHomeArgs(orgID) if discoErr != nil { client.goBackInternal() return nil, client.handleError(errorMessage, discoErr) @@ -480,7 +480,7 @@ func (client *Client) GetConfigCustomServer(url string, preferTCP bool) (string, // askSecureLocation asks the user to choose a Secure Internet location by moving the FSM to the STATE_ASK_LOCATION state. func (client *Client) askSecureLocation() error { errorMessage := "failed settings secure location" - locations := client.Discovery.GetSecureLocationList() + locations := client.Discovery.SecureLocationList() // Ask for the location in the callback goTransitionErr := client.FSM.GoTransitionRequired(StateAskLocation, locations) -- cgit v1.2.3