summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client/client.go6
-rw-r--r--client/client_test.go4
-rw-r--r--client/fsm.go28
-rw-r--r--client/server.go4
-rw-r--r--cmd/cli/main.go12
-rw-r--r--internal/config/config.go8
-rw-r--r--internal/discovery/discovery.go18
-rw-r--r--internal/fsm/fsm.go30
-rw-r--r--internal/http/http.go28
-rw-r--r--internal/log/log.go36
-rw-r--r--internal/oauth/oauth.go34
-rw-r--r--internal/server/api.go2
-rw-r--r--internal/server/common.go4
-rw-r--r--internal/server/instituteaccess.go2
-rw-r--r--internal/server/secureinternet.go4
-rw-r--r--internal/util/util.go6
-rw-r--r--internal/verify/verify.go2
-rw-r--r--internal/wireguard/wireguard.go4
-rw-r--r--types/error.go12
-rw-r--r--types/server.go2
20 files changed, 123 insertions, 123 deletions
diff --git a/client/client.go b/client/client.go
index 958dd25..3f8dbea 100644
--- a/client/client.go
+++ b/client/client.go
@@ -15,11 +15,11 @@ import (
type (
// ServerBase is an alias to the internal ServerBase
- // This contains the details for each server
+ // This contains the details for each server.
ServerBase = server.ServerBase
)
-// This wraps the error, logs it and then returns the wrapped error
+// This wraps the error, logs it and then returns the wrapped error.
func (client *Client) handleError(message string, err error) error {
if err != nil {
// Logs the error with the same level/verbosity as the error
@@ -34,7 +34,7 @@ func (client Client) isLetsConnect() bool {
return strings.HasPrefix(client.Name, "org.letsconnect-vpn.app")
}
-// Client is the main struct for the VPN client
+// Client is the main struct for the VPN client.
type Client struct {
// The name of the client
Name string `json:"-"`
diff --git a/client/client_test.go b/client/client_test.go
index a125e7e..128319c 100644
--- a/client/client_test.go
+++ b/client/client_test.go
@@ -331,7 +331,7 @@ func TestTokenInvalid(t *testing.T) {
}
}
-// Test if an invalid profile will be corrected
+// Test if an invalid profile will be corrected.
func TestInvalidProfileCorrected(t *testing.T) {
serverURI := getServerURI(t)
state := &Client{}
@@ -389,7 +389,7 @@ func TestInvalidProfileCorrected(t *testing.T) {
}
}
-// Test if prefer tcp is handled correctly by checking the returned config and config type
+// Test if prefer tcp is handled correctly by checking the returned config and config type.
func TestPreferTCP(t *testing.T) {
serverURI := getServerURI(t)
state := &Client{}
diff --git a/client/fsm.go b/client/fsm.go
index f4bfe21..2245630 100644
--- a/client/fsm.go
+++ b/client/fsm.go
@@ -17,46 +17,46 @@ type (
)
const (
- // StateDeregistered means the app is not registered with the wrapper
+ // StateDeregistered means the app is not registered with the wrapper.
StateDeregistered FSMStateID = iota
- // StateNoServer means the user has not chosen a server yet
+ // StateNoServer means the user has not chosen a server yet.
StateNoServer
- // StateAskLocation means the user selected a Secure Internet server but needs to choose a location
+ // StateAskLocation means the user selected a Secure Internet server but needs to choose a location.
StateAskLocation
- // StateSearchServer means the user is currently selecting a server in the UI
+ // StateSearchServer means the user is currently selecting a server in the UI.
StateSearchServer
- // StateLoadingServer means we are loading the server details
+ // StateLoadingServer means we are loading the server details.
StateLoadingServer
- // StateChosenServer means the user has chosen a server to connect to
+ // StateChosenServer means the user has chosen a server to connect to.
StateChosenServer
- // StateOAuthStarted means the OAuth process has started
+ // StateOAuthStarted means the OAuth process has started.
StateOAuthStarted
- // StateAuthorized means the OAuth process has finished and the user is now authorized with the server
+ // StateAuthorized means the OAuth process has finished and the user is now authorized with the server.
StateAuthorized
- // StateRequestConfig means the user has requested a config for connecting
+ // StateRequestConfig means the user has requested a config for connecting.
StateRequestConfig
- // StateAskProfile means the go code is asking for a profile selection from the UI
+ // StateAskProfile means the go code is asking for a profile selection from the UI.
StateAskProfile
- // StateDisconnected means the user has gotten a config for a server but is not connected yet
+ // StateDisconnected means the user has gotten a config for a server but is not connected yet.
StateDisconnected
- // StateDisconnecting means the OS is disconnecting and the Go code is doing the /disconnect
+ // StateDisconnecting means the OS is disconnecting and the Go code is doing the /disconnect.
StateDisconnecting
- // StateConnecting means the OS is establishing a connection to the server
+ // StateConnecting means the OS is establishing a connection to the server.
StateConnecting
- // StateConnected means the user has been connected to the server
+ // StateConnected means the user has been connected to the server.
StateConnected
)
diff --git a/client/server.go b/client/server.go
index 5fed292..5331a7d 100644
--- a/client/server.go
+++ b/client/server.go
@@ -315,7 +315,7 @@ func (client *Client) AddSecureInternetHomeServer(orgID string) (server.Server,
return server, nil
}
-// AddCustomServer adds a Custom Server by `url`
+// AddCustomServer adds a Custom Server by `url`.
func (client *Client) AddCustomServer(url string) (server.Server, error) {
errorMessage := fmt.Sprintf("failed adding Custom server with url %s", url)
@@ -501,7 +501,7 @@ func (client *Client) askSecureLocation() error {
// ChangeSecureLocation changes the location for an existing Secure Internet Server.
// Changing a secure internet location is only possible when the user is in the main screen (STATE_NO_SERVER), otherwise it returns an error.
-// It also returns an error if something has gone wrong when selecting the new location
+// It also returns an error if something has gone wrong when selecting the new location.
func (client *Client) ChangeSecureLocation() error {
errorMessage := "failed to change location from the main screen"
diff --git a/cmd/cli/main.go b/cmd/cli/main.go
index f4f17e4..0e759eb 100644
--- a/cmd/cli/main.go
+++ b/cmd/cli/main.go
@@ -19,7 +19,7 @@ const (
ServerTypeCustom
)
-// Open a browser with xdg-open
+// Open a browser with xdg-open.
func openBrowser(url interface{}) {
urlString, ok := url.(string)
@@ -34,7 +34,7 @@ func openBrowser(url interface{}) {
}
}
-// Ask for a profile in the command line
+// Ask for a profile in the command line.
func sendProfile(state *client.Client, data interface{}) {
fmt.Printf("Multiple VPN profiles found. Please select a profile by entering e.g. 1")
serverProfiles, ok := data.(*server.ServerProfileInfo)
@@ -75,7 +75,7 @@ func sendProfile(state *client.Client, data interface{}) {
// The callback function
// If OAuth is started we open the browser with the Auth URL
// If we ask for a profile, we send the profile using command line input
-// Note that this has an additional argument, the vpn state which was wrapped into this callback function below
+// Note that this has an additional argument, the vpn state which was wrapped into this callback function below.
func stateCallback(
state *client.Client,
oldState client.FSMStateID,
@@ -91,7 +91,7 @@ func stateCallback(
}
}
-// Get a config for Institute Access or Secure Internet Server
+// Get a config for Institute Access or Secure Internet Server.
func getConfig(state *client.Client, url string, serverType ServerTypes) (string, string, error) {
if !strings.HasPrefix(url, "http") {
url = "https://" + url
@@ -117,7 +117,7 @@ func getConfig(state *client.Client, url string, serverType ServerTypes) (string
return state.GetConfigSecureInternet(url, false)
}
-// Get a config for a single server, Institute Access or Secure Internet
+// Get a config for a single server, Institute Access or Secure Internet.
func printConfig(url string, serverType ServerTypes) {
state := &client.Client{}
@@ -151,7 +151,7 @@ func printConfig(url string, serverType ServerTypes) {
}
// The main function
-// It parses the arguments and executes the correct functions
+// It parses the arguments and executes the correct functions.
func main() {
customURLArg := flag.String("get-custom", "", "The url of a custom server to connect to")
urlArg := flag.String("get-institute", "", "The url of an institute to connect to")
diff --git a/internal/config/config.go b/internal/config/config.go
index fa3045b..bea97f7 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -12,7 +12,7 @@ import (
"github.com/eduvpn/eduvpn-common/types"
)
-// Config represents a configuration that saves the client's struct as JSON
+// Config represents a configuration that saves the client's struct as JSON.
type Config struct {
// Directory represents the path to where the data is saved
Directory string
@@ -21,20 +21,20 @@ type Config struct {
Name string
}
-// Init initializes the configuration using the provided directory and name
+// Init initializes the configuration using the provided directory and name.
func (config *Config) Init(directory string, name string) {
config.Directory = directory
config.Name = name
}
-// filename returns the filename of the configuration as a full path
+// filename returns the filename of the configuration as a full path.
func (config *Config) filename() string {
pathString := path.Join(config.Directory, config.Name)
return fmt.Sprintf("%s.json", pathString)
}
// Save saves a structure 'readStruct' to the configuration
-// If it was unusuccessful, an an error is returned
+// If it was unusuccessful, an an error is returned.
func (config *Config) Save(readStruct interface{}) error {
errorMessage := "failed saving configuration"
configDirErr := util.EnsureDirectory(config.Directory)
diff --git a/internal/discovery/discovery.go b/internal/discovery/discovery.go
index d7fb273..17d5b08 100644
--- a/internal/discovery/discovery.go
+++ b/internal/discovery/discovery.go
@@ -12,7 +12,7 @@ import (
)
-// Discovery is the main structure used for this package
+// Discovery is the main structure used for this package.
type Discovery struct {
// organizations represents the organizations that are returned by the discovery server
organizations types.DiscoveryOrganizations
@@ -22,7 +22,7 @@ type Discovery struct {
}
// discoFile is a helper function that gets a disco JSON and fills the structure with it
-// If it was unsuccessful it returns an error
+// If it was unsuccessful it returns an error.
func discoFile(jsonFile string, previousVersion uint64, structure interface{}) error {
errorMessage := fmt.Sprintf("failed getting file: %s from the Discovery server", jsonFile)
// Get json data
@@ -79,7 +79,7 @@ func (discovery *Discovery) DetermineOrganizationsUpdate() bool {
return discovery.organizations.Timestamp.IsZero()
}
-// SecureLocationList returns a slice of all the available locations
+// SecureLocationList returns a slice of all the available locations.
func (discovery *Discovery) SecureLocationList() []string {
var locations []string
for _, currentServer := range discovery.servers.List {
@@ -91,7 +91,7 @@ func (discovery *Discovery) SecureLocationList() []string {
}
// ServerByURL returns the discovery server by the base URL and the according type ("secure_internet", "institute_access")
-// An error is returned if and only if nil is returned for the server
+// An error is returned if and only if nil is returned for the server.
func (discovery *Discovery) ServerByURL(
baseURL string,
serverType string,
@@ -108,7 +108,7 @@ func (discovery *Discovery) ServerByURL(
}
// ServerByCountryCode returns the discovery server by the country code and the according type ("secure_internet", "institute_access")
-// An error is returned if and only if nil is returned for the server
+// An error is returned if and only if nil is returned for the server.
func (discovery *Discovery) ServerByCountryCode(
countryCode string,
serverType string,
@@ -125,7 +125,7 @@ func (discovery *Discovery) ServerByCountryCode(
}
// orgByID returns the discovery organization by the organization ID
-// An error is returned if and only if nil is returned for the organization
+// An error is returned if and only if nil is returned for the organization.
func (discovery *Discovery) orgByID(orgID string) (*types.DiscoveryOrganization, error) {
for _, organization := range discovery.organizations.List {
if organization.OrgID == orgID {
@@ -141,7 +141,7 @@ func (discovery *Discovery) orgByID(orgID string) (*types.DiscoveryOrganization,
// SecureHomeArgs returns the secure internet home server arguments:
// - The organization it belongs to
// - The secure internet server itself
-// An error is returned if and only if nil is returned for the organization
+// An error is returned if and only if nil is returned for the organization.
func (discovery *Discovery) SecureHomeArgs(
orgID string,
) (*types.DiscoveryOrganization, *types.DiscoveryServer, error) {
@@ -179,7 +179,7 @@ func (discovery *Discovery) DetermineServersUpdate() bool {
}
// Organizations returns the discovery organizations
-// If there was an error, a cached copy is returned if available
+// If there was an error, a cached copy is returned if available.
func (discovery *Discovery) Organizations() (*types.DiscoveryOrganizations, error) {
if !discovery.DetermineOrganizationsUpdate() {
return &discovery.organizations, nil
@@ -198,7 +198,7 @@ func (discovery *Discovery) Organizations() (*types.DiscoveryOrganizations, erro
}
// Servers returns the discovery servers
-// If there was an error, a cached copy is returned if available
+// If there was an error, a cached copy is returned if available.
func (discovery *Discovery) Servers() (*types.DiscoveryServers, error) {
if !discovery.DetermineServersUpdate() {
return &discovery.servers, nil
diff --git a/internal/fsm/fsm.go b/internal/fsm/fsm.go
index c3c7efa..e6f3f3a 100644
--- a/internal/fsm/fsm.go
+++ b/internal/fsm/fsm.go
@@ -12,9 +12,9 @@ import (
)
type (
- //StateID represents the Identifier of the state
+ //StateID represents the Identifier of the state.
FSMStateID int8
- //StateIDSlice represents the list of state identifiers
+ //StateIDSlice represents the list of state identifiers.
FSMStateIDSlice []FSMStateID
)
@@ -30,7 +30,7 @@ func (v FSMStateIDSlice) Swap(i, j int) {
v[i], v[j] = v[j], v[i]
}
-// Transition indicates an arrow in the state graph
+// Transition indicates an arrow in the state graph.
type FSMTransition struct {
// To represents the to-be-new state
To FSMStateID
@@ -42,13 +42,13 @@ type (
FSMStates map[FSMStateID]FSMState
)
-// State represents a single node in the graph
+// State represents a single node in the graph.
type FSMState struct {
// Transitions indicates which out arrows this node has
Transitions []FSMTransition
}
-// FSM represents the total graph
+// FSM represents the total graph.
type FSM struct {
// States is the map from state ID to states
States FSMStates
@@ -73,7 +73,7 @@ type FSM struct {
GetStateName func(FSMStateID) string
}
-// Init initializes the state machine and sets it to the given current state
+// Init initializes the state machine and sets it to the given current state.
func (fsm *FSM) Init(
current FSMStateID,
states map[FSMStateID]FSMState,
@@ -90,12 +90,12 @@ func (fsm *FSM) Init(
fsm.Generate = generate
}
-// InState returns whether or not the state machine is in the given 'check' state
+// InState returns whether or not the state machine is in the given 'check' state.
func (fsm *FSM) InState(check FSMStateID) bool {
return check == fsm.Current
}
-// HasTransition checks whether or not the state machine has a transition to the given 'check' state
+// HasTransition checks whether or not the state machine has a transition to the given 'check' state.
func (fsm *FSM) HasTransition(check FSMStateID) bool {
for _, transitionState := range fsm.States[fsm.Current].Transitions {
if transitionState.To == check {
@@ -106,13 +106,13 @@ func (fsm *FSM) HasTransition(check FSMStateID) bool {
return false
}
-// graphFilename gets the full path to the graph filename including the .graph extension
+// graphFilename gets the full path to the graph filename including the .graph extension.
func (fsm *FSM) graphFilename(extension string) string {
debugPath := path.Join(fsm.Directory, "graph")
return fmt.Sprintf("%s%s", debugPath, extension)
}
-// writeGraph writes the state machine to a .graph file
+// writeGraph writes the state machine to a .graph file.
func (fsm *FSM) writeGraph() {
graph := fsm.GenerateGraph()
graphFile := fsm.graphFilename(".graph")
@@ -132,7 +132,7 @@ func (fsm *FSM) writeGraph() {
}
// GoTransitionRequired transitions the state machine to a new state with associated state data 'data'
-// If this transition is not handled by the client, it returns an error
+// If this transition is not handled by the client, it returns an error.
func (fsm *FSM) GoTransitionRequired(newState FSMStateID, data interface{}) error {
oldState := fsm.Current
if !fsm.GoTransitionWithData(newState, data) {
@@ -142,7 +142,7 @@ func (fsm *FSM) GoTransitionRequired(newState FSMStateID, data interface{}) erro
}
// GoTransitionWithData is a helper that transitions the state machine toward the 'newState' with associated state data 'data'
-// It returns whether or not the transition is handled by the client
+// It returns whether or not the transition is handled by the client.
func (fsm *FSM) GoTransitionWithData(newState FSMStateID, data interface{}) bool {
ok := fsm.HasTransition(newState)
@@ -160,14 +160,14 @@ func (fsm *FSM) GoTransitionWithData(newState FSMStateID, data interface{}) bool
return handled
}
-// GoTransition is an alias to call GoTransitionWithData but have an empty string as data
+// GoTransition is an alias to call GoTransitionWithData but have an empty string as data.
func (fsm *FSM) GoTransition(newState FSMStateID) bool {
// No data means the callback is never required
return fsm.GoTransitionWithData(newState, "")
}
// generateMermaidGraph generates a graph suitable to be converted by the mermaid.js tool
-// it returns the graph as a string
+// it returns the graph as a string.
func (fsm *FSM) generateMermaidGraph() string {
graph := "graph TD\n"
sortedFSM := make(FSMStateIDSlice, 0, len(fsm.States))
@@ -196,7 +196,7 @@ func (fsm *FSM) generateMermaidGraph() string {
}
// GenerateGraph generates a mermaid graph if the state machine is initialized
-// If the graph cannot be generated, it returns the empty string
+// If the graph cannot be generated, it returns the empty string.
func (fsm *FSM) GenerateGraph() string {
if fsm.GetStateName != nil {
return fsm.generateMermaidGraph()
diff --git a/internal/http/http.go b/internal/http/http.go
index b21b901..7e87e3c 100644
--- a/internal/http/http.go
+++ b/internal/http/http.go
@@ -13,10 +13,10 @@ import (
"github.com/eduvpn/eduvpn-common/types"
)
-// The URLParemeters as the name suggests is a type used for the parameters in the URL
+// The URLParemeters as the name suggests is a type used for the parameters in the URL.
type URLParameters map[string]string
-// OptionalParams is a structure that defines the optional parameters that are given when making a HTTP call
+// OptionalParams is a structure that defines the optional parameters that are given when making a HTTP call.
type HTTPOptionalParams struct {
Headers http.Header
URLParameters URLParameters
@@ -24,7 +24,7 @@ type HTTPOptionalParams struct {
Timeout time.Duration
}
-// ConstructURL creates a URL with the included parameters
+// ConstructURL creates a URL with the included parameters.
func HTTPConstructURL(baseURL string, parameters URLParameters) (string, error) {
url, parseErr := url.Parse(baseURL)
if parseErr != nil {
@@ -47,28 +47,28 @@ func HTTPConstructURL(baseURL string, parameters URLParameters) (string, error)
return url.String(), nil
}
-// Get creates a Get request and returns the headers, body and an error
+// Get creates a Get request and returns the headers, body and an error.
func HTTPGet(url string) (http.Header, []byte, error) {
return HTTPMethodWithOpts(http.MethodGet, url, nil)
}
-// Post creates a Post request and returns the headers, body and an error
+// Post creates a Post request and returns the headers, body and an error.
func HTTPPost(url string, body url.Values) (http.Header, []byte, error) {
return HTTPMethodWithOpts(http.MethodGet, url, &HTTPOptionalParams{Body: body})
}
-// GetWithOpts creates a Get request with optional parameters and returns the headers, body and an error
+// GetWithOpts creates a Get request with optional parameters and returns the headers, body and an error.
func HTTPGetWithOpts(url string, opts *HTTPOptionalParams) (http.Header, []byte, error) {
return HTTPMethodWithOpts(http.MethodGet, url, opts)
}
-// PostWithOpts creates a Post request with optional parameters and returns the headers, body and an error
+// PostWithOpts creates a Post request with optional parameters and returns the headers, body and an error.
func HTTPPostWithOpts(url string, opts *HTTPOptionalParams) (http.Header, []byte, error) {
return HTTPMethodWithOpts(http.MethodPost, url, opts)
}
// optionalURL ensures that the URL contains the optional parameters
-// it returns the url (with parameters if success) and an error indicating success
+// it returns the url (with parameters if success) and an error indicating success.
func httpOptionalURL(url string, opts *HTTPOptionalParams) (string, error) {
if opts != nil {
url, urlErr := HTTPConstructURL(url, opts.URLParameters)
@@ -84,7 +84,7 @@ func httpOptionalURL(url string, opts *HTTPOptionalParams) (string, error) {
return url, nil
}
-// optionalHeaders ensures that the HTTP request uses the optional headers if defined
+// optionalHeaders ensures that the HTTP request uses the optional headers if defined.
func httpOptionalHeaders(req *http.Request, opts *HTTPOptionalParams) {
// Add headers
if opts != nil && req != nil && opts.Headers != nil {
@@ -94,7 +94,7 @@ func httpOptionalHeaders(req *http.Request, opts *HTTPOptionalParams) {
}
}
-// optionalBodyReader returns a HTTP body reader if there is a body, otherwise nil
+// optionalBodyReader returns a HTTP body reader if there is a body, otherwise nil.
func httpOptionalBodyReader(opts *HTTPOptionalParams) io.Reader {
if opts != nil && opts.Body != nil {
return strings.NewReader(opts.Body.Encode())
@@ -103,7 +103,7 @@ func httpOptionalBodyReader(opts *HTTPOptionalParams) io.Reader {
}
// MethodWithOpts creates a HTTP request using a method (e.g. GET, POST), an url and optional parameters
-// It returns the HTTP headers, the body and an error if there is one
+// It returns the HTTP headers, the body and an error if there is one.
func HTTPMethodWithOpts(
method string,
url string,
@@ -167,14 +167,14 @@ func HTTPMethodWithOpts(
return resp.Header, body, nil
}
-// StatusError indicates that we have received a HTTP status error
+// StatusError indicates that we have received a HTTP status error.
type HTTPStatusError struct {
URL string
Body string
Status int
}
-// Error returns the StatusError as an error string
+// Error returns the StatusError as an error string.
func (e *HTTPStatusError) Error() string {
return fmt.Sprintf(
"failed obtaining HTTP resource: %s as it gave an unsuccessful status code: %d. Body: %s",
@@ -193,7 +193,7 @@ type HTTPParseJSONError struct {
Err error
}
-// Error returns the ParseJSONError as an error string
+// Error returns the ParseJSONError as an error string.
func (e *HTTPParseJSONError) Error() string {
return fmt.Sprintf(
"failed parsing json %s for HTTP resource: %s with error: %v",
diff --git a/internal/log/log.go b/internal/log/log.go
index eaedc28..3aa0f0b 100644
--- a/internal/log/log.go
+++ b/internal/log/log.go
@@ -13,7 +13,7 @@ import (
)
// FileLogger defines the type of logger that this package implements
-// As the name suggests, it saves the log to a file
+// As the name suggests, it saves the log to a file.
type FileLogger struct {
// Level indicates which maximum level this logger actually forwards to the file
Level LogLevel
@@ -25,26 +25,26 @@ type FileLogger struct {
type LogLevel int8
const (
- // LevelNotSet indicates level not set, not allowed
+ // LevelNotSet indicates level not set, not allowed.
LevelNotSet LogLevel = iota
- // LevelDebug indicates that the message is not an error but is there for debugging
+ // LevelDebug indicates that the message is not an error but is there for debugging.
LevelDebug
- // LevelInfo indicates that the message is not an error but is there for additional information
+ // LevelInfo indicates that the message is not an error but is there for additional information.
LevelInfo
- // LevelWarning indicates only a warning, the app still functions
+ // LevelWarning indicates only a warning, the app still functions.
LevelWarning
- // LevelError indicates a generic error, the app still functions but some functionality might not work
+ // LevelError indicates a generic error, the app still functions but some functionality might not work.
LevelError
- // LevelFatal indicates a fatal error, the app cannot function correctly when such an error occurs
+ // LevelFatal indicates a fatal error, the app cannot function correctly when such an error occurs.
LevelFatal
)
-// String returns the string of each level
+// String returns the string of each level.
func (e LogLevel) String() string {
switch e {
case LevelNotSet:
@@ -65,7 +65,7 @@ func (e LogLevel) String() string {
}
// Init initializes the logger by forwarding a max level 'level' and a directory 'directory' where the log should be stored
-// If the logger cannot be initialized, for example an error in opening the log file, an error is returned
+// If the logger cannot be initialized, for example an error in opening the log file, an error is returned.
func (logger *FileLogger) Init(level LogLevel, directory string) error {
errorMessage := "failed creating log"
@@ -88,7 +88,7 @@ func (logger *FileLogger) Init(level LogLevel, directory string) error {
return nil
}
-// Inherit logs an error with a label using the error level of the error
+// Inherit logs an error with a label using the error level of the error.
func (logger *FileLogger) Inherit(label string, err error) {
level := types.ErrorLevel(err)
@@ -105,42 +105,42 @@ func (logger *FileLogger) Inherit(label string, err error) {
}
}
-// Debug logs a message with parameters as level LevelDebug
+// Debug logs a message with parameters as level LevelDebug.
func (logger *FileLogger) Debug(msg string, params ...interface{}) {
logger.log(LevelDebug, msg, params...)
}
-// Debug logs a message with parameters as level LevelInfo
+// Debug logs a message with parameters as level LevelInfo.
func (logger *FileLogger) Info(msg string, params ...interface{}) {
logger.log(LevelInfo, msg, params...)
}
-// Debug logs a message with parameters as level LevelWarning
+// Debug logs a message with parameters as level LevelWarning.
func (logger *FileLogger) Warning(msg string, params ...interface{}) {
logger.log(LevelWarning, msg, params...)
}
-// Debug logs a message with parameters as level LevelError
+// Debug logs a message with parameters as level LevelError.
func (logger *FileLogger) Error(msg string, params ...interface{}) {
logger.log(LevelError, msg, params...)
}
-// Debug logs a message with parameters as level LevelFatal
+// Debug logs a message with parameters as level LevelFatal.
func (logger *FileLogger) Fatal(msg string, params ...interface{}) {
logger.log(LevelFatal, msg, params...)
}
-// Close closes the logger by closing the internal file
+// Close closes the logger by closing the internal file.
func (logger *FileLogger) Close() {
logger.file.Close()
}
-// filename returns the filename of the logger by returning the full path as a string
+// filename returns the filename of the logger by returning the full path as a string.
func (logger *FileLogger) filename(directory string) string {
return path.Join(directory, "log")
}
-// log logs as level 'level' a message 'msg' with parameters 'params'
+// log logs as level 'level' a message 'msg' with parameters 'params'.
func (logger *FileLogger) log(level LogLevel, msg string, params ...interface{}) {
if level >= logger.Level && logger.Level != LevelNotSet {
formattedMsg := fmt.Sprintf(msg, params...)
diff --git a/internal/oauth/oauth.go b/internal/oauth/oauth.go
index fe78cd3..6d63235 100644
--- a/internal/oauth/oauth.go
+++ b/internal/oauth/oauth.go
@@ -29,7 +29,7 @@ import (
// state between the request and callback. The authorization server
// includes this value when redirecting the user agent back to the
// client.
-// We implement it similarly to the verifier
+// We implement it similarly to the verifier.
func genState() (string, error) {
randomBytes, err := util.MakeRandomByteSlice(32)
if err != nil {
@@ -75,7 +75,7 @@ func genVerifier() (string, error) {
return base64.RawURLEncoding.EncodeToString(randomBytes), nil
}
-// OAuth defines the main structure for this package
+// OAuth defines the main structure for this package.
type OAuth struct {
// ISS indicates the issuer indentifier of the authorization server as defined in RFC 9207
ISS string `json:"iss"`
@@ -93,7 +93,7 @@ type OAuth struct {
session OAuthExchangeSession `json:"-"`
}
-// OAuthExchangeSession is a structure that gets passed to the callback for easy access to the current state
+// OAuthExchangeSession is a structure that gets passed to the callback for easy access to the current state.
type OAuthExchangeSession struct {
// CallbackError indicates an error returned by the server
CallbackError error
@@ -120,7 +120,7 @@ type OAuthExchangeSession struct {
Listener net.Listener
}
-// OAuthToken is a structure that defines the json format for /.well-known/vpn-user-portal"
+// OAuthToken is a structure that defines the json format for /.well-known/vpn-user-portal".
type OAuthToken struct {
// Access is the access token returned by the server
Access string `json:"access_token"`
@@ -139,7 +139,7 @@ type OAuthToken struct {
}
// setupListener sets up an OAuth listener
-// If it was unsuccessful it returns an error
+// If it was unsuccessful it returns an error.
func (oauth *OAuth) setupListener() error {
errorMessage := "failed setting up listener"
oauth.session.Context = context.Background()
@@ -154,7 +154,7 @@ func (oauth *OAuth) setupListener() error {
}
// tokensWithCallback gets the OAuth tokens using a local web server
-// If it was unsuccessful it returns an error
+// If it was unsuccessful it returns an error.
func (oauth *OAuth) tokensWithCallback() error {
errorMessage := "failed getting tokens with callback"
if oauth.session.Listener == nil {
@@ -176,7 +176,7 @@ func (oauth *OAuth) tokensWithCallback() error {
// tokensWithAuthCode gets the access and refresh tokens using the authorization code
// Access tokens: https://datatracker.ietf.org/doc/html/draft-ietf-oauth-v2-1-04#section-1.4
// Refresh tokens: https://datatracker.ietf.org/doc/html/draft-ietf-oauth-v2-1-04#section-1.3.2
-// If it was unsuccessful it returns an error
+// If it was unsuccessful it returns an error.
func (oauth *OAuth) tokensWithAuthCode(authCode string) error {
errorMessage := "failed getting tokens with the authorization code"
// Make sure the verifier is set as the parameter
@@ -223,7 +223,7 @@ func (oauth *OAuth) tokensWithAuthCode(authCode string) error {
return nil
}
-// isTokensExpired returns if the OAuth tokens are expired using the expired timestamp
+// isTokensExpired returns if the OAuth tokens are expired using the expired timestamp.
func (oauth *OAuth) isTokensExpired() bool {
expiredTime := oauth.Token.ExpiredTimestamp
currentTime := time.Now()
@@ -233,7 +233,7 @@ func (oauth *OAuth) isTokensExpired() bool {
// tokensWithRefresh gets the access and refresh tokens with a previously received refresh token
// Access tokens: https://datatracker.ietf.org/doc/html/draft-ietf-oauth-v2-1-04#section-1.4
// Refresh tokens: https://datatracker.ietf.org/doc/html/draft-ietf-oauth-v2-1-04#section-1.3.2
-// If it was unsuccessful it returns an error
+// If it was unsuccessful it returns an error.
func (oauth *OAuth) tokensWithRefresh() error {
errorMessage := "failed getting tokens with the refresh token"
reqURL := oauth.TokenURL
@@ -306,14 +306,14 @@ main {
</html>
`
-// oauthResponseHTML is a structure that is used to give back the OAuth response
+// oauthResponseHTML is a structure that is used to give back the OAuth response.
type oauthResponseHTML struct {
Title string
Message string
}
// writeResponseHTML writes the OAuth response using a response writer and the title + message
-// If it was unsuccessful it returns an error
+// If it was unsuccessful it returns an error.
func writeResponseHTML(w http.ResponseWriter, title string, message string) error {
errorMessage := "failed writing response HTML"
template, templateErr := template.New("oauth-response").Parse(responseTemplate)
@@ -411,7 +411,7 @@ func (oauth *OAuth) Callback(w http.ResponseWriter, req *http.Request) {
// Init initializes OAuth with the following parameters:
// - OAuth server issuer identification
// - The URL used for authorization
-// - The URL to obtain new tokens
+// - The URL to obtain new tokens.
func (oauth *OAuth) Init(iss string, baseAuthorizationURL string, tokenURL string) {
oauth.ISS = iss
oauth.BaseAuthorizationURL = baseAuthorizationURL
@@ -419,7 +419,7 @@ func (oauth *OAuth) Init(iss string, baseAuthorizationURL string, tokenURL strin
}
// ListenerPort gets the listener for the OAuth web server
-// It returns the port as an integer and an error if there is any
+// It returns the port as an integer and an error if there is any.
func (oauth OAuth) ListenerPort() (int, error) {
errorMessage := "failed to get listener port"
@@ -429,7 +429,7 @@ func (oauth OAuth) ListenerPort() (int, error) {
return oauth.session.Listener.Addr().(*net.TCPAddr).Port, nil
}
-// AuthURL gets the authorization url to start the OAuth procedure
+// AuthURL gets the authorization url to start the OAuth procedure.
func (oauth *OAuth) AuthURL(name string, postProcessAuth func(string) string) (string, error) {
errorMessage := "failed starting OAuth exchange"
@@ -483,7 +483,7 @@ func (oauth *OAuth) AuthURL(name string, postProcessAuth func(string) string) (s
}
// Exchange starts the OAuth exchange by getting the tokens with the redirect callback
-// If it was unsuccessful it returns an error
+// If it was unsuccessful it returns an error.
func (oauth *OAuth) Exchange() error {
tokenErr := oauth.tokensWithCallback()
@@ -494,7 +494,7 @@ func (oauth *OAuth) Exchange() error {
}
// Cancel cancels the existing OAuth
-// TODO: Use context for this
+// TODO: Use context for this.
func (oauth *OAuth) Cancel() {
oauth.session.CallbackError = types.NewWrappedErrorLevel(
types.ErrInfo,
@@ -507,7 +507,7 @@ func (oauth *OAuth) Cancel() {
}
// EnsureTokens makes sure the OAuth tokens are still valid
-// if this cannot be guaranteed, it returns an error
+// if this cannot be guaranteed, it returns an error.
func (oauth *OAuth) EnsureTokens() error {
errorMessage := "failed ensuring OAuth tokens"
// Access Token or Refresh Tokens empty, we can not ensure the tokens
diff --git a/internal/server/api.go b/internal/server/api.go
index 559b787..eb55bd8 100644
--- a/internal/server/api.go
+++ b/internal/server/api.go
@@ -223,7 +223,7 @@ func APIConnectOpenVPN(server Server, profileID string, preferTCP bool) (string,
return string(connectBody), pTime, nil
}
-// This needs no further return value as it's best effort
+// This needs no further return value as it's best effort.
func APIDisconnect(server Server) {
_, _, _ = apiAuthorized(server, http.MethodPost, "/disconnect", nil)
}
diff --git a/internal/server/common.go b/internal/server/common.go
index 16208eb..351b3af 100644
--- a/internal/server/common.go
+++ b/internal/server/common.go
@@ -10,7 +10,7 @@ import (
"github.com/eduvpn/eduvpn-common/types"
)
-// The base type for servers
+// The base type for servers.
type ServerBase struct {
URL string `json:"base_url"`
DisplayName map[string]string `json:"display_name"`
@@ -82,7 +82,7 @@ type ServerEndpointList struct {
Token string `json:"token_endpoint"`
}
-// Struct that defines the json format for /.well-known/vpn-user-portal"
+// Struct that defines the json format for /.well-known/vpn-user-portal".
type ServerEndpoints struct {
API struct {
V2 ServerEndpointList `json:"http://eduvpn.org/api#2"`
diff --git a/internal/server/instituteaccess.go b/internal/server/instituteaccess.go
index ca37dcd..c0594a7 100644
--- a/internal/server/instituteaccess.go
+++ b/internal/server/instituteaccess.go
@@ -8,7 +8,7 @@ import (
"github.com/eduvpn/eduvpn-common/types"
)
-// An instute access server
+// An instute access server.
type InstituteAccessServer struct {
// An instute access server has its own OAuth
Auth oauth.OAuth `json:"oauth"`
diff --git a/internal/server/secureinternet.go b/internal/server/secureinternet.go
index 0dc9ef1..c6a353b 100644
--- a/internal/server/secureinternet.go
+++ b/internal/server/secureinternet.go
@@ -10,7 +10,7 @@ import (
)
// A secure internet server which has its own OAuth tokens
-// It specifies the current location url it is connected to
+// It specifies the current location url it is connected to.
type SecureInternetHomeServer struct {
Auth oauth.OAuth `json:"oauth"`
DisplayName map[string]string `json:"display_name"`
@@ -122,7 +122,7 @@ func (server *SecureInternetHomeServer) addLocation(
return base, nil
}
-// Initializes the home server and adds its own location
+// Initializes the home server and adds its own location.
func (server *SecureInternetHomeServer) init(
homeOrg *types.DiscoveryOrganization,
homeLocation *types.DiscoveryServer,
diff --git a/internal/util/util.go b/internal/util/util.go
index 8b39b9f..3ce1992 100644
--- a/internal/util/util.go
+++ b/internal/util/util.go
@@ -17,7 +17,7 @@ import (
// - Sets the scheme to https if none is given
// - It 'cleans' up the path using path.Clean
// - It makes sure that the URL ends with a /
-// It returns an error if the URL cannot be parsed
+// It returns an error if the URL cannot be parsed.
func EnsureValidURL(s string) (string, error) {
parsedURL, parseErr := url.Parse(s)
if parseErr != nil {
@@ -56,7 +56,7 @@ func MakeRandomByteSlice(size int) ([]byte, error) {
return byteSlice, nil
}
-// EnsureDirectory creates a directory with permission 700
+// EnsureDirectory creates a directory with permission 700.
func EnsureDirectory(directory string) error {
// Create with 700 permissions, read, write, execute only for the owner
mkdirErr := os.MkdirAll(directory, 0o700)
@@ -71,7 +71,7 @@ func EnsureDirectory(directory string) error {
// WAYFEncode an input URL using 'skip Where Are You From' encoding
// See https://github.com/eduvpn/documentation/blob/dc4d53c47dd7a69e95d6650eec408e16eaa814a2/SERVER_DISCOVERY_SKIP_WAYF.md
-// URL encode for skipping where are you from (WAYF). Note that this right now is basically an alias to QueryEscape
+// URL encode for skipping where are you from (WAYF). Note that this right now is basically an alias to QueryEscape.
func WAYFEncode(input string) string {
// QueryReplace already replaces a space with a +
// see https://go.dev/play/p/pOfrn-Wsq5
diff --git a/internal/verify/verify.go b/internal/verify/verify.go
index 98a9c67..83765a0 100644
--- a/internal/verify/verify.go
+++ b/internal/verify/verify.go
@@ -54,7 +54,7 @@ func Verify(
// The signature is checked to have a timestamp with a value of at least minSignTime, which is a UNIX timestamp without milliseconds.
//
// The return value will either be (true, nil) on success or (false, detailedVerifyError) on failure.
-// Note that every error path is wrapped in a custom type here because minisign does not return custom error types, they use errors.New
+// Note that every error path is wrapped in a custom type here because minisign does not return custom error types, they use errors.New.
func verifyWithKeys(
signatureFileContent string,
signedJSON []byte,
diff --git a/internal/wireguard/wireguard.go b/internal/wireguard/wireguard.go
index d9bd974..7da2623 100644
--- a/internal/wireguard/wireguard.go
+++ b/internal/wireguard/wireguard.go
@@ -10,7 +10,7 @@ import (
)
// GenerateKey generates a WireGuard private key using wgctrl
-// It returns an error if key generation failed
+// It returns an error if key generation failed.
func GenerateKey() (wgtypes.Key, error) {
key, keyErr := wgtypes.GeneratePrivateKey()
@@ -24,7 +24,7 @@ func GenerateKey() (wgtypes.Key, error) {
}
// ConfigAddKey takes the WireGuard configuration and adds the PrivateKey to the right section
-// FIXME: Instead of doing a regex replace, decide if we should use a parser
+// FIXME: Instead of doing a regex replace, decide if we should use a parser.
func ConfigAddKey(config string, key wgtypes.Key) string {
interfaceSection := "[Interface]"
InterfaceSectionEscaped := regexp.QuoteMeta(interfaceSection)
diff --git a/types/error.go b/types/error.go
index a7f70b0..da5d971 100644
--- a/types/error.go
+++ b/types/error.go
@@ -8,16 +8,16 @@ import (
type ErrLevel int8
const (
- // All other errors, default
+ // All other errors, default.
ErrOther ErrLevel = iota
- // The erorr is just here as additional info
+ // The erorr is just here as additional info.
ErrInfo
- // The error is just here as a warning
+ // The error is just here as a warning.
ErrWarning
- // The error is fatal, the app cannot function
+ // The error is fatal, the app cannot function.
ErrFatal
)
@@ -27,12 +27,12 @@ type WrappedErrorMessage struct {
Err error
}
-// NewWrappedError returns a WrappedErrorMessage and uses the error level from the parent
+// NewWrappedError returns a WrappedErrorMessage and uses the error level from the parent.
func NewWrappedError(message string, err error) *WrappedErrorMessage {
return &WrappedErrorMessage{Level: ErrorLevel(err), Message: message, Err: err}
}
-// NewWrappedError returns a WrappedErrorMessage and uses the given error level from the parent
+// NewWrappedError returns a WrappedErrorMessage and uses the given error level from the parent.
func NewWrappedErrorLevel(level ErrLevel, message string, err error) *WrappedErrorMessage {
return &WrappedErrorMessage{Level: level, Message: message, Err: err}
}
diff --git a/types/server.go b/types/server.go
index 24db8f2..c15cb4e 100644
--- a/types/server.go
+++ b/types/server.go
@@ -33,7 +33,7 @@ type DiscoveryServers struct {
type DiscoMapOrString map[string]string
// The display name can either be a map or a string in the server list
-// Unmarshal it by first trying a string and then the map
+// Unmarshal it by first trying a string and then the map.
func (DN *DiscoMapOrString) UnmarshalJSON(data []byte) error {
var displayNameString string