summaryrefslogtreecommitdiff
path: root/internal/server
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-11-24 15:40:39 +0100
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-11-24 15:40:39 +0100
commit8be555e5f91c6069c3d51cb014f1849fd182b1dc (patch)
tree9c78f2ee1f5122da1e1ed3e452682f7f6744778f /internal/server
parent791fffebff4499e4fad3217e2160596e1b8b3eea (diff)
Style: Use stylecheck and fix errors
Diffstat (limited to 'internal/server')
-rw-r--r--internal/server/api.go12
-rw-r--r--internal/server/common.go13
-rw-r--r--internal/server/custom.go6
-rw-r--r--internal/server/instituteaccess.go6
-rw-r--r--internal/server/secureinternet.go40
5 files changed, 38 insertions, 39 deletions
diff --git a/internal/server/api.go b/internal/server/api.go
index be7281c..d315ada 100644
--- a/internal/server/api.go
+++ b/internal/server/api.go
@@ -20,7 +20,9 @@ func APIGetEndpoints(baseURL string) (*ServerEndpoints, error) {
return nil, types.NewWrappedError(errorMessage, urlErr)
}
- url.Path = path.Join(url.Path, WellKnownPath)
+ wellKnownPath := "/.well-known/vpn-user-portal"
+
+ url.Path = path.Join(url.Path, wellKnownPath)
_, body, bodyErr := httpw.HTTPGet(url.String())
if bodyErr != nil {
@@ -140,7 +142,7 @@ func GetPreferTCPString(preferTCP bool) string {
func APIConnectWireguard(
server Server,
- profile_id string,
+ profileID string,
pubkey string,
preferTCP bool,
supportsOpenVPN bool,
@@ -158,7 +160,7 @@ func APIConnectWireguard(
}
urlForm := url.Values{
- "profile_id": {profile_id},
+ "profile_id": {profileID},
"public_key": {pubkey},
"prefer_tcp": {GetPreferTCPString(preferTCP)},
}
@@ -191,7 +193,7 @@ func APIConnectWireguard(
return string(connectBody), content, pTime, nil
}
-func APIConnectOpenVPN(server Server, profile_id string, preferTCP bool) (string, time.Time, error) {
+func APIConnectOpenVPN(server Server, profileID string, preferTCP bool) (string, time.Time, error) {
errorMessage := "failed obtaining an OpenVPN configuration"
headers := http.Header{
"content-type": {"application/x-www-form-urlencoded"},
@@ -199,7 +201,7 @@ func APIConnectOpenVPN(server Server, profile_id string, preferTCP bool) (string
}
urlForm := url.Values{
- "profile_id": {profile_id},
+ "profile_id": {profileID},
"prefer_tcp": {GetPreferTCPString(preferTCP)},
}
diff --git a/internal/server/common.go b/internal/server/common.go
index 6cd5dc2..8f4eabc 100644
--- a/internal/server/common.go
+++ b/internal/server/common.go
@@ -92,9 +92,6 @@ type ServerEndpoints struct {
V string `json:"v"`
}
-// Make this a var which we can overwrite in the tests
-var WellKnownPath string = "/.well-known/vpn-user-portal"
-
func (servers *Servers) GetCurrentServer() (Server, error) {
errorMessage := "failed getting current server"
if servers.IsType == SecureInternetServerType {
@@ -372,7 +369,7 @@ func wireguardGetConfig(server Server, preferTCP bool, supportsOpenVPN bool) (st
return "", "", types.NewWrappedError(errorMessage, baseErr)
}
- profile_id := base.Profiles.Current
+ profileID := base.Profiles.Current
wireguardKey, wireguardErr := wireguard.GenerateKey()
if wireguardErr != nil {
@@ -382,7 +379,7 @@ func wireguardGetConfig(server Server, preferTCP bool, supportsOpenVPN bool) (st
wireguardPublicKey := wireguardKey.PublicKey().String()
config, content, expires, configErr := APIConnectWireguard(
server,
- profile_id,
+ profileID,
wireguardPublicKey,
preferTCP,
supportsOpenVPN,
@@ -414,8 +411,8 @@ func openVPNGetConfig(server Server, preferTCP bool) (string, string, error) {
if baseErr != nil {
return "", "", types.NewWrappedError(errorMessage, baseErr)
}
- profile_id := base.Profiles.Current
- configOpenVPN, expires, configErr := APIConnectOpenVPN(server, profile_id, preferTCP)
+ profileID := base.Profiles.Current
+ configOpenVPN, expires, configErr := APIConnectOpenVPN(server, profileID, preferTCP)
// Store start and end time
base.StartTime = time.Now()
@@ -515,7 +512,7 @@ func GetConfig(server Server, clientSupportsWireguard bool, preferTCP bool) (str
config, configType, configErr = openVPNGetConfig(server, preferTCP)
// The config supports no available protocol because the profile only supports WireGuard but the client doesn't
} else {
- return "", "", types.NewWrappedError(errorMessage, errors.New("No supported protocol found"))
+ return "", "", types.NewWrappedError(errorMessage, errors.New("no supported protocol found"))
}
if configErr != nil {
diff --git a/internal/server/custom.go b/internal/server/custom.go
index 6ba6503..8bde848 100644
--- a/internal/server/custom.go
+++ b/internal/server/custom.go
@@ -15,14 +15,14 @@ func (servers *Servers) SetCustomServer(server Server) error {
}
if base.Type != "custom_server" {
- return types.NewWrappedError(errorMessage, errors.New("Not a custom server"))
+ return types.NewWrappedError(errorMessage, errors.New("not a custom server"))
}
if _, ok := servers.CustomServers.Map[base.URL]; ok {
servers.CustomServers.CurrentURL = base.URL
servers.IsType = CustomServerType
} else {
- return types.NewWrappedError(errorMessage, errors.New("Not a custom server"))
+ return types.NewWrappedError(errorMessage, errors.New("not a custom server"))
}
return nil
}
@@ -31,7 +31,7 @@ func (servers *Servers) GetCustomServer(url string) (*InstituteAccessServer, err
if server, ok := servers.CustomServers.Map[url]; ok {
return server, nil
}
- return nil, types.NewWrappedError("failed to get institute access server", fmt.Errorf("No custom server with URL: %s", url))
+ return nil, types.NewWrappedError("failed to get institute access server", fmt.Errorf("no custom server with URL: %s", url))
}
func (servers *Servers) RemoveCustomServer(url string) {
diff --git a/internal/server/instituteaccess.go b/internal/server/instituteaccess.go
index 045535a..33d8b52 100644
--- a/internal/server/instituteaccess.go
+++ b/internal/server/instituteaccess.go
@@ -30,14 +30,14 @@ func (servers *Servers) SetInstituteAccess(server Server) error {
}
if base.Type != "institute_access" {
- return types.NewWrappedError(errorMessage, errors.New("Not an institute access server"))
+ return types.NewWrappedError(errorMessage, errors.New("not an institute access server"))
}
if _, ok := servers.InstituteServers.Map[base.URL]; ok {
servers.InstituteServers.CurrentURL = base.URL
servers.IsType = InstituteAccessServerType
} else {
- return types.NewWrappedError(errorMessage, errors.New("No such institute access server"))
+ return types.NewWrappedError(errorMessage, errors.New("no such institute access server"))
}
return nil
}
@@ -46,7 +46,7 @@ func (servers *Servers) GetInstituteAccess(url string) (*InstituteAccessServer,
if server, ok := servers.InstituteServers.Map[url]; ok {
return server, nil
}
- return nil, types.NewWrappedError("failed to get institute access server", fmt.Errorf("No institute access server with URL: %s", url))
+ return nil, types.NewWrappedError("failed to get institute access server", fmt.Errorf("no institute access server with URL: %s", url))
}
func (servers *Servers) RemoveInstituteAccess(url string) {
diff --git a/internal/server/secureinternet.go b/internal/server/secureinternet.go
index cfe9ea1..f0b308f 100644
--- a/internal/server/secureinternet.go
+++ b/internal/server/secureinternet.go
@@ -26,7 +26,7 @@ type SecureInternetHomeServer struct {
func (servers *Servers) GetSecureInternetHomeServer() (*SecureInternetHomeServer, error) {
if !servers.HasSecureLocation() {
- return nil, errors.New("No secure internet home server")
+ return nil, errors.New("no secure internet home server")
}
return &servers.SecureInternetHomeServer, nil
}
@@ -39,7 +39,7 @@ func (servers *Servers) SetSecureInternet(server Server) error {
}
if base.Type != "secure_internet" {
- return types.NewWrappedError(errorMessage, errors.New("Not a secure internet server"))
+ return types.NewWrappedError(errorMessage, errors.New("not a secure internet server"))
}
// The location should already be configured
@@ -58,13 +58,13 @@ func (servers *Servers) RemoveSecureInternet() {
}
}
-func (secure *SecureInternetHomeServer) GetOAuth() *oauth.OAuth {
- return &secure.OAuth
+func (server *SecureInternetHomeServer) GetOAuth() *oauth.OAuth {
+ return &server.OAuth
}
-func (secure *SecureInternetHomeServer) GetTemplateAuth() func(string) string {
+func (server *SecureInternetHomeServer) GetTemplateAuth() func(string) string {
return func(authURL string) string {
- return util.ReplaceWAYF(secure.AuthorizationTemplate, authURL, secure.HomeOrganizationID)
+ return util.ReplaceWAYF(server.AuthorizationTemplate, authURL, server.HomeOrganizationID)
}
}
@@ -92,23 +92,23 @@ func (servers *Servers) HasSecureLocation() bool {
return servers.SecureInternetHomeServer.CurrentLocation != ""
}
-func (secure *SecureInternetHomeServer) addLocation(
+func (server *SecureInternetHomeServer) addLocation(
locationServer *types.DiscoveryServer,
) (*ServerBase, error) {
errorMessage := "failed adding a location"
// Initialize the base map if it is non-nil
- if secure.BaseMap == nil {
- secure.BaseMap = make(map[string]*ServerBase)
+ if server.BaseMap == nil {
+ server.BaseMap = make(map[string]*ServerBase)
}
// Add the location to the base map
- base, exists := secure.BaseMap[locationServer.CountryCode]
+ base, exists := server.BaseMap[locationServer.CountryCode]
if !exists || base == nil {
// Create the base to be added to the map
base = &ServerBase{}
base.URL = locationServer.BaseURL
- base.DisplayName = secure.DisplayName
+ base.DisplayName = server.DisplayName
base.SupportContact = locationServer.SupportContact
base.Type = "secure_internet"
endpointsErr := base.InitializeEndpoints()
@@ -118,37 +118,37 @@ func (secure *SecureInternetHomeServer) addLocation(
}
// Ensure it is in the map
- secure.BaseMap[locationServer.CountryCode] = base
+ server.BaseMap[locationServer.CountryCode] = base
return base, nil
}
// Initializes the home server and adds its own location
-func (secure *SecureInternetHomeServer) init(
+func (server *SecureInternetHomeServer) init(
homeOrg *types.DiscoveryOrganization,
homeLocation *types.DiscoveryServer,
) error {
errorMessage := "failed initializing secure internet home server"
- if secure.HomeOrganizationID != homeOrg.OrgId {
+ if server.HomeOrganizationID != homeOrg.OrgID {
// New home organisation, clear everything
- *secure = SecureInternetHomeServer{}
+ *server = SecureInternetHomeServer{}
}
// Make sure to set the organization ID
- secure.HomeOrganizationID = homeOrg.OrgId
- secure.DisplayName = homeOrg.DisplayName
+ server.HomeOrganizationID = homeOrg.OrgID
+ server.DisplayName = homeOrg.DisplayName
// Make sure to set the authorization URL template
- secure.AuthorizationTemplate = homeLocation.AuthenticationURLTemplate
+ server.AuthorizationTemplate = homeLocation.AuthenticationURLTemplate
- base, baseErr := secure.addLocation(homeLocation)
+ base, baseErr := server.addLocation(homeLocation)
if baseErr != nil {
return types.NewWrappedError(errorMessage, baseErr)
}
// Make sure oauth contains our endpoints
- secure.OAuth.Init(base.URL, base.Endpoints.API.V3.Authorization, base.Endpoints.API.V3.Token)
+ server.OAuth.Init(base.URL, base.Endpoints.API.V3.Authorization, base.Endpoints.API.V3.Token)
return nil
}