From 7d67ce7f6a15970677b7d0b8f4912fe379862515 Mon Sep 17 00:00:00 2001 From: jwijenbergh Date: Thu, 7 Jul 2022 15:41:16 +0200 Subject: Format: Run gofumpt --- cmd/cli/main.go | 1 + internal/discovery/discovery.go | 6 +++--- internal/server/server.go | 25 +++++++++++-------------- internal/types/server.go | 29 ++++++++++++++--------------- internal/util/util.go | 3 +-- state.go | 5 +---- 6 files changed, 31 insertions(+), 38 deletions(-) diff --git a/cmd/cli/main.go b/cmd/cli/main.go index 93b81e0..d3d3dbb 100644 --- a/cmd/cli/main.go +++ b/cmd/cli/main.go @@ -14,6 +14,7 @@ import ( ) type ServerTypes int8 + const ( ServerTypeInstituteAccess ServerTypes = iota ServerTypeSecureInternet diff --git a/internal/discovery/discovery.go b/internal/discovery/discovery.go index c61469d..2331491 100644 --- a/internal/discovery/discovery.go +++ b/internal/discovery/discovery.go @@ -70,7 +70,7 @@ func (discovery *Discovery) Init(fsm *fsm.FSM, logger *log.FileLogger) { // - [TODO] when the user tries to add new server AND the user did NOT yet choose an organization before; // - [TODO] when the authorization for the server associated with an already chosen organization is triggered, e.g. after expiry or revocation. func (discovery *Discovery) DetermineOrganizationsUpdate() bool { - return discovery.Organizations.Timestamp == 0 + return discovery.Organizations.Timestamp == 0 } func (discovery *Discovery) GetSecureLocationList() []string { @@ -189,7 +189,7 @@ func (e GetOrgByIDNotFoundError) Error() string { } type GetServerByURLNotFoundError struct { - URL string + URL string Type string } @@ -199,7 +199,7 @@ func (e GetServerByURLNotFoundError) Error() string { type GetServerByCountryCodeNotFoundError struct { CountryCode string - Type string + Type string } func (e GetServerByCountryCodeNotFoundError) Error() string { diff --git a/internal/server/server.go b/internal/server/server.go index 5bc2ea1..719d8c8 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -36,8 +36,8 @@ type InstituteAccessServer struct { // A secure internet server which has its own OAuth tokens // It specifies the current location url it is connected to type SecureInternetHomeServer struct { - DisplayName string `json:"display_name"` - OAuth oauth.OAuth `json:"oauth"` + DisplayName string `json:"display_name"` + OAuth oauth.OAuth `json:"oauth"` // The home server has a list of info for each configured server location BaseMap map[string]*ServerBase `json:"base_map"` @@ -45,7 +45,7 @@ type SecureInternetHomeServer struct { // We have the authorization URL template, the home organization ID and the current location AuthorizationTemplate string `json:"authorization_template"` HomeOrganizationID string `json:"home_organization_id"` - CurrentLocation string `json:"current_location"` + CurrentLocation string `json:"current_location"` } type InstituteServers struct { @@ -107,17 +107,16 @@ func (secure *SecureInternetHomeServer) GetOAuth() *oauth.OAuth { return &secure.OAuth } - -func (institute *InstituteAccessServer) GetTemplateAuth() (func(string) string) { - return func(authURL string) string { - return authURL - } +func (institute *InstituteAccessServer) GetTemplateAuth() func(string) string { + return func(authURL string) string { + return authURL + } } -func (secure *SecureInternetHomeServer) GetTemplateAuth() (func(string) string) { - return func(authURL string) string { - return util.ReplaceWAYF(secure.AuthorizationTemplate, authURL, secure.HomeOrganizationID) - } +func (secure *SecureInternetHomeServer) GetTemplateAuth() func(string) string { + return func(authURL string) string { + return util.ReplaceWAYF(secure.AuthorizationTemplate, authURL, secure.HomeOrganizationID) + } } func (institute *InstituteAccessServer) GetBase() (*ServerBase, error) { @@ -186,7 +185,6 @@ func (secure *SecureInternetHomeServer) addLocation(locationServer *types.Discov return base, nil } - // Initializes the home server and adds its own location func (secure *SecureInternetHomeServer) init(homeOrg *types.DiscoveryOrganization, homeLocation *types.DiscoveryServer, fsm *fsm.FSM, logger *log.FileLogger) error { errorMessage := "failed initializing secure internet home server" @@ -195,7 +193,6 @@ func (secure *SecureInternetHomeServer) init(homeOrg *types.DiscoveryOrganizatio // New home organisation, clear everything *secure = *&SecureInternetHomeServer{} } - base, baseErr := secure.addLocation(homeLocation, fsm, logger) diff --git a/internal/types/server.go b/internal/types/server.go index ba9b217..31a7bcc 100644 --- a/internal/types/server.go +++ b/internal/types/server.go @@ -5,10 +5,10 @@ package types // Structs that define the json format for // url: "https://disco.eduvpn.org/v2/organization_list.json" type DiscoveryOrganizations struct { - Version uint64 `json:"v"` - List []DiscoveryOrganization `json:"organization_list"` - Timestamp int64 `json:"-"` - RawString string `json:"-"` + Version uint64 `json:"v"` + List []DiscoveryOrganization `json:"organization_list"` + Timestamp int64 `json:"-"` + RawString string `json:"-"` } type DiscoveryOrganization struct { @@ -25,18 +25,17 @@ type DiscoveryOrganization struct { // Structs that define the json format for // url: "https://disco.eduvpn.org/v2/server_list.json" type DiscoveryServers struct { - Version uint64 `json:"v"` - List []DiscoveryServer `json:"server_list"` - Timestamp int64 `json:"-"` - RawString string `json:"-"` + Version uint64 `json:"v"` + List []DiscoveryServer `json:"server_list"` + Timestamp int64 `json:"-"` + RawString string `json:"-"` } type DiscoveryServer struct { - AuthenticationURLTemplate string `json:"authentication_url_template"` - BaseURL string `json:"base_url"` - CountryCode string `json:"country_code"` - PublicKeyList []string `json:"public_key_list"` - Type string `json:"server_type"` - SupportContact []string `json:"support_contact"` + AuthenticationURLTemplate string `json:"authentication_url_template"` + BaseURL string `json:"base_url"` + CountryCode string `json:"country_code"` + PublicKeyList []string `json:"public_key_list"` + Type string `json:"server_type"` + SupportContact []string `json:"support_contact"` } - diff --git a/internal/util/util.go b/internal/util/util.go index 30767c3..f77d34c 100644 --- a/internal/util/util.go +++ b/internal/util/util.go @@ -3,12 +3,11 @@ package util import ( "crypto/rand" "fmt" + "net/url" "os" "strings" "time" - "net/url" - "github.com/jwijenbergh/eduvpn-common/internal/types" ) diff --git a/state.go b/state.go index 8306ca0..46bee4d 100644 --- a/state.go +++ b/state.go @@ -2,6 +2,7 @@ package eduvpn import ( "fmt" + "github.com/jwijenbergh/eduvpn-common/internal/config" "github.com/jwijenbergh/eduvpn-common/internal/discovery" "github.com/jwijenbergh/eduvpn-common/internal/fsm" @@ -145,7 +146,6 @@ func (state *VPNState) AskSecureLocation() error { return nil } - func (state *VPNState) addSecureInternetHomeServer(orgID string) (server.Server, error) { errorMessage := fmt.Sprintf("failed adding Secure Internet home server with organization ID %s", orgID) // Get the secure internet URL from discovery @@ -201,7 +201,6 @@ func (state *VPNState) addInstituteServer(url string) (server.Server, error) { state.FSM.GoTransition(fsm.CHOSEN_SERVER) return server, nil - } func (state *VPNState) addCustomServer(url string) (server.Server, error) { @@ -219,7 +218,6 @@ func (state *VPNState) addCustomServer(url string) (server.Server, error) { state.FSM.GoTransition(fsm.CHOSEN_SERVER) return server, nil - } func (state *VPNState) GetConfigInstituteAccess(url string, forceTCP bool) (string, string, error) { @@ -259,7 +257,6 @@ func (state *VPNState) CancelOAuth() error { return nil } - func (state *VPNState) GetDiscoOrganizations() (string, error) { if state.FSM.InState(fsm.DEREGISTERED) { return "", &types.WrappedErrorMessage{Message: "failed to get the organizations with Discovery", Err: fsm.DeregisteredError{}.CustomError()} -- cgit v1.2.3