From 612adf787aa2729ba5e2d8a8e714203284d6bc14 Mon Sep 17 00:00:00 2001 From: hopleus Date: Thu, 31 Oct 2024 15:50:58 +0300 Subject: [PATCH] Fixed errors in files according to golangci-lint rules --- hscontrol/oidc.go | 9 ++---- hscontrol/templates/general.go | 2 +- hscontrol/templates/oidc_callback.go | 45 ++++++++++++++-------------- 3 files changed, 26 insertions(+), 30 deletions(-) diff --git a/hscontrol/oidc.go b/hscontrol/oidc.go index af03a16f..487fdd26 100644 --- a/hscontrol/oidc.go +++ b/hscontrol/oidc.go @@ -7,7 +7,6 @@ import ( "encoding/hex" "errors" "fmt" - "github.com/juanfont/headscale/hscontrol/templates" "net/http" "slices" "strings" @@ -17,6 +16,7 @@ import ( "github.com/gorilla/mux" "github.com/juanfont/headscale/hscontrol/db" "github.com/juanfont/headscale/hscontrol/notifier" + "github.com/juanfont/headscale/hscontrol/templates" "github.com/juanfont/headscale/hscontrol/types" "github.com/juanfont/headscale/hscontrol/util" "github.com/rs/zerolog/log" @@ -116,7 +116,7 @@ func (a *AuthProviderOIDC) determineNodeExpiry(idTokenExpiration time.Time) time return time.Now().Add(a.cfg.Expiry) } -// RegisterOIDC redirects to the OIDC provider for authentication +// RegisterHandler redirects to the OIDC provider for authentication // Puts NodeKey in cache so the callback can retrieve it using the oidc state param // Listens in /register/:mKey. func (a *AuthProviderOIDC) RegisterHandler( @@ -171,11 +171,6 @@ func (a *AuthProviderOIDC) RegisterHandler( http.Redirect(writer, req, authURL, http.StatusFound) } -type oidcCallbackTemplateConfig struct { - User string - Verb string -} - // OIDCCallbackHandler handles the callback from the OIDC endpoint // Retrieves the nkey from the state cache and adds the node to the users email user // TODO: A confirmation page for new nodes should be added to avoid phishing vulnerabilities diff --git a/hscontrol/templates/general.go b/hscontrol/templates/general.go index 566ace46..9a3b74bb 100644 --- a/hscontrol/templates/general.go +++ b/hscontrol/templates/general.go @@ -33,7 +33,7 @@ func logo(class string) *elem.Element { styles.Var("fill-rule"): "evenodd", styles.Var("clip-rule"): "evenodd", styles.Var("stroke-linejoin"): "round", - styles.Var("stroke-miterlimit"): styles.Int(2), + styles.Var("stroke-miterlimit"): styles.Int(2), //nolint }.ToInline(), "viewBox": "0 0 1280 640", }, diff --git a/hscontrol/templates/oidc_callback.go b/hscontrol/templates/oidc_callback.go index 3b378d99..a9f50744 100644 --- a/hscontrol/templates/oidc_callback.go +++ b/hscontrol/templates/oidc_callback.go @@ -2,6 +2,7 @@ package templates import ( "fmt" + "github.com/chasefleming/elem-go" "github.com/chasefleming/elem-go/attrs" "github.com/chasefleming/elem-go/styles" @@ -11,7 +12,7 @@ import ( func OidcCallback(node *types.Node, user *types.User, verb string) string { styleMgr := styles.NewStyleManager() styleBody := styleMgr.AddStyle(styles.Props{ - styles.FontSize: styles.Pixels(14), + styles.FontSize: styles.Pixels(14), //nolint styles.FontFamily: "system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", \"Roboto\", \"Oxygen\", \"Ubuntu\", \"Cantarell\", \"Fira Sans\", \"Droid Sans\", \"Helvetica Neue\", sans-serif", }) styleHr := styleMgr.AddStyle(styles.Props{ @@ -22,12 +23,12 @@ func OidcCallback(node *types.Node, user *types.User, verb string) string { styles.Display: "flex", styles.JustifyContent: "center", styles.AlignItems: "center", - styles.Height: styles.ViewportHeight(70), + styles.Height: styles.ViewportHeight(70), //nolint }) classLogo := styleMgr.AddStyle(styles.Props{ styles.Display: "block", - styles.MarginLeft: styles.Pixels(-20), - styles.MarginBottom: styles.Pixels(16), + styles.MarginLeft: styles.Pixels(-20), //nolint + styles.MarginBottom: styles.Pixels(16), //nolint }) colorMessageSuccess := styles.Props{ @@ -40,12 +41,12 @@ func OidcCallback(node *types.Node, user *types.User, verb string) string { } styleMessage := styles.Props{ styles.Display: "flex", - styles.MinWidth: styles.ViewportWidth(40), - styles.MarginBottom: styles.Pixels(12), + styles.MinWidth: styles.ViewportWidth(40), //nolint + styles.MarginBottom: styles.Pixels(12), //nolint styles.Padding: "12px 16px 16px 12px", styles.Position: "relative", - styles.BorderRadius: styles.Pixels(2), - styles.FontSize: styles.Pixels(14), + styles.BorderRadius: styles.Pixels(2), //nolint + styles.FontSize: styles.Pixels(14), //nolint } var classMessage string @@ -56,7 +57,7 @@ func OidcCallback(node *types.Node, user *types.User, verb string) string { } classMessageContent := styleMgr.AddStyle(styles.Props{ - styles.MarginLeft: styles.Pixels(4), + styles.MarginLeft: styles.Pixels(4), //nolint }) classIconSuccess := styleMgr.AddStyle(styles.Props{ "fill": "#2eb039", @@ -69,9 +70,9 @@ func OidcCallback(node *types.Node, user *types.User, verb string) string { styles.Color: "#d58525", } styleMessageTitle := styles.Props{ - styles.FontSize: styles.Pixels(16), - styles.FontWeight: styles.Int(700), - styles.LineHeight: styles.Float(1.25), + styles.FontSize: styles.Pixels(16), //nolint + styles.FontWeight: styles.Int(700), //nolint + styles.LineHeight: styles.Float(1.25), //nolint } var classMessageTitle string @@ -88,11 +89,11 @@ func OidcCallback(node *types.Node, user *types.User, verb string) string { styles.Color: "#824c0b", } styleMessageBody := styles.Props{ - styles.FontSize: styles.Pixels(12), - styles.Margin: styles.Int(0), - styles.Padding: styles.Int(0), - styles.Border: styles.Int(0), - styles.MarginTop: styles.Pixels(4), + styles.FontSize: styles.Pixels(12), //nolint + styles.Margin: styles.Int(0), //nolint + styles.Padding: styles.Int(0), //nolint + styles.Border: styles.Int(0), //nolint + styles.MarginTop: styles.Pixels(4), //nolint } var classMessageBody string @@ -108,7 +109,7 @@ func OidcCallback(node *types.Node, user *types.User, verb string) string { styles.Margin: "8px 0", styles.Color: "#1563ff", styles.TextDecoration: "none", - styles.FontWeight: styles.Int(600), + styles.FontWeight: styles.Int(600), //nolint }, PseudoClasses: map[string]styles.Props{ styles.PseudoHover: {styles.Color: "black"}, @@ -118,14 +119,14 @@ func OidcCallback(node *types.Node, user *types.User, verb string) string { styles.AlignItems: "center", styles.Display: "inline-flex", styles.JustifyContent: "center", - styles.Width: styles.Pixels(21), - styles.Height: styles.Pixels(21), + styles.Width: styles.Pixels(21), //nolint + styles.Height: styles.Pixels(21), //nolint styles.VerticalAlign: "middle", }) styleH1 := styleMgr.AddStyle(styles.Props{ styles.FontSize: "17.5px", - styles.FontWeight: styles.Pixels(700), - styles.MarginBottom: styles.Pixels(0), + styles.FontWeight: styles.Pixels(700), //nolint + styles.MarginBottom: styles.Pixels(0), //nolint }) styleH1P := styleMgr.AddStyle(styles.Props{ styles.Margin: "8px 0 16px 0",