summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-11-28 12:50:23 +0100
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-11-28 12:50:23 +0100
commit7bab6c76599fdfd34ea9bb064d871ed2be01d4c8 (patch)
tree8200ead8926c0c5f11f750698760a0bcd93c230c /internal
parent7339e77c6eda5b96874dfc099d5c58da8ed53629 (diff)
Lint: Run godot fix
Full command: golangci-lint run --disable-all -E godot --fix
Diffstat (limited to 'internal')
-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
13 files changed, 89 insertions, 89 deletions
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)