fix linter issues

This commit is contained in:
pascal
2026-02-12 01:02:13 +01:00
parent 1c7059ee67
commit e20b969188
9 changed files with 27 additions and 54 deletions

View File

@@ -21,6 +21,8 @@ import (
const DefaultManagementURL = "https://api.netbird.io:443"
// envProxyToken is the environment variable name for the proxy access token.
//
//nolint:gosec
const envProxyToken = "NB_PROXY_TOKEN"
var (
@@ -160,7 +162,8 @@ func runServer(cmd *cobra.Command, args []string) error {
defer stop()
if err := srv.ListenAndServe(ctx, addr); err != nil {
log.Fatal(err)
log.Error(err)
return err
}
return nil
}

View File

@@ -1,40 +0,0 @@
package auth
import (
"context"
"github.com/netbirdio/netbird/proxy/auth"
)
type requestContextKey string
const (
authMethodKey requestContextKey = "authMethod"
authUserKey requestContextKey = "authUser"
)
func withAuthMethod(ctx context.Context, method auth.Method) context.Context {
return context.WithValue(ctx, authMethodKey, method)
}
func MethodFromContext(ctx context.Context) auth.Method {
v := ctx.Value(authMethodKey)
method, ok := v.(auth.Method)
if !ok {
return ""
}
return method
}
func withAuthUser(ctx context.Context, userId string) context.Context {
return context.WithValue(ctx, authUserKey, userId)
}
func UserFromContext(ctx context.Context) string {
v := ctx.Value(authUserKey)
userId, ok := v.(string)
if !ok {
return ""
}
return userId
}

View File

@@ -21,7 +21,7 @@ import (
)
const (
saTokenPath = "/var/run/secrets/kubernetes.io/serviceaccount/token"
saTokenPath = "/var/run/secrets/kubernetes.io/serviceaccount/token" //nolint:gosec
saNamespacePath = "/var/run/secrets/kubernetes.io/serviceaccount/namespace"
saCACertPath = "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"

View File

@@ -86,7 +86,7 @@ func (p *ReverseProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ErrorHandler: proxyErrorHandler,
}
if result.rewriteRedirects {
rp.ModifyResponse = p.rewriteLocationFunc(result.url, result.matchedPath, r)
rp.ModifyResponse = p.rewriteLocationFunc(result.url, result.matchedPath, r) //nolint:bodyclose
}
rp.ServeHTTP(w, r.WithContext(ctx))
}

View File

@@ -572,6 +572,7 @@ func TestRewriteLocationFunc(t *testing.T) {
"http://backend.internal:8080/login")
require.NoError(t, err)
defer resp.Body.Close()
assert.Equal(t, "https://public.example.com/login", resp.Header.Get("Location"))
})
@@ -580,6 +581,7 @@ func TestRewriteLocationFunc(t *testing.T) {
"https://other.example.com/path")
require.NoError(t, err)
defer resp.Body.Close()
assert.Equal(t, "https://other.example.com/path", resp.Header.Get("Location"))
})
@@ -588,12 +590,14 @@ func TestRewriteLocationFunc(t *testing.T) {
"/dashboard")
require.NoError(t, err)
defer resp.Body.Close()
assert.Equal(t, "/dashboard", resp.Header.Get("Location"))
})
t.Run("re-adds stripped path prefix", func(t *testing.T) {
resp, err := run(newProxy("https"), "/api", newReq("https://public.example.com/api/users"),
"http://backend.internal:8080/users")
defer resp.Body.Close()
require.NoError(t, err)
assert.Equal(t, "https://public.example.com/api/users", resp.Header.Get("Location"))

View File

@@ -109,7 +109,7 @@ func ServeHTTP(w http.ResponseWriter, r *http.Request, data any, statusCode ...i
if err := tmpl.Execute(&buf, struct {
Data template.JS
}{
Data: template.JS(dataJSON),
Data: template.JS(dataJSON), //nolint:gosec
}); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return