]> source.dussan.org Git - gitea.git/commitdiff
Extract constant names out for the ReverseProxy and Basic authentication methods...
authorzeripath <art27@cantab.net>
Sat, 20 Nov 2021 15:33:18 +0000 (15:33 +0000)
committerGitHub <noreply@github.com>
Sat, 20 Nov 2021 15:33:18 +0000 (23:33 +0800)
In order to reduce load on the GC extract out the constant names of the Basic and ReverseProxy methods.

As mentioned in https://github.com/go-gitea/gitea/pull/15119#discussion_r730352176

Signed-off-by: Andrew Thornton <art27@cantab.net>
modules/context/api.go
modules/context/context.go
routers/api/v1/api.go
services/auth/basic.go
services/auth/reverseproxy.go

index c978835af87494c0f02dad5bee0bc58879d7c23f..07ceeeea15cfa1593934f156885ad45a92b86690 100644 (file)
@@ -245,7 +245,7 @@ func APIAuth(authMethod auth.Method) func(*APIContext) {
                // Get user from session if logged in.
                ctx.User = authMethod.Verify(ctx.Req, ctx.Resp, ctx, ctx.Session)
                if ctx.User != nil {
-                       ctx.IsBasicAuth = ctx.Data["AuthedMethod"].(string) == new(auth.Basic).Name()
+                       ctx.IsBasicAuth = ctx.Data["AuthedMethod"].(string) == auth.BasicMethodName
                        ctx.IsSigned = true
                        ctx.Data["IsSigned"] = ctx.IsSigned
                        ctx.Data["SignedUser"] = ctx.User
index 8adf1f306bd6d035f45673ffab6c582d10beff9f..1ea53c7d3b8d256e2b28b9c18475b2b2dc239d27 100644 (file)
@@ -614,7 +614,7 @@ func Auth(authMethod auth.Method) func(*Context) {
        return func(ctx *Context) {
                ctx.User = authMethod.Verify(ctx.Req, ctx.Resp, ctx, ctx.Session)
                if ctx.User != nil {
-                       ctx.IsBasicAuth = ctx.Data["AuthedMethod"].(string) == new(auth.Basic).Name()
+                       ctx.IsBasicAuth = ctx.Data["AuthedMethod"].(string) == auth.BasicMethodName
                        ctx.IsSigned = true
                        ctx.Data["IsSigned"] = ctx.IsSigned
                        ctx.Data["SignedUser"] = ctx.User
index 67f88cf0008ef385b590e9f35ee90e824051045a..099559caad2ef1bb22349456f309bd6e151306cf 100644 (file)
@@ -217,7 +217,7 @@ func reqExploreSignIn() func(ctx *context.APIContext) {
 
 func reqBasicOrRevProxyAuth() func(ctx *context.APIContext) {
        return func(ctx *context.APIContext) {
-               if ctx.IsSigned && setting.Service.EnableReverseProxyAuth && ctx.Data["AuthedMethod"].(string) == new(auth.ReverseProxy).Name() {
+               if ctx.IsSigned && setting.Service.EnableReverseProxyAuth && ctx.Data["AuthedMethod"].(string) == auth.ReverseProxyMethodName {
                        return
                }
                if !ctx.Context.IsBasicAuth {
index d7f889cbdc8e26ab3ee7e3d9611713225ecf45c6..9cfbd0f644cbc63d86964d3e3d0c71ae46d17df8 100644 (file)
@@ -23,6 +23,9 @@ var (
        _ Named  = &Basic{}
 )
 
+// BasicMethodName is the constant name of the basic authentication method
+const BasicMethodName = "basic"
+
 // Basic implements the Auth interface and authenticates requests (API requests
 // only) by looking for Basic authentication data or "x-oauth-basic" token in the "Authorization"
 // header.
@@ -31,7 +34,7 @@ type Basic struct {
 
 // Name represents the name of auth method
 func (b *Basic) Name() string {
-       return "basic"
+       return BasicMethodName
 }
 
 // Verify extracts and validates Basic data (username and password/token) from the
index 550fcabc1da2effa822af5090a064fb7c987b374..7cd24c302d21363054d5f3a5c5d6338a00c11a6c 100644 (file)
@@ -24,6 +24,9 @@ var (
        _ Named  = &ReverseProxy{}
 )
 
+// ReverseProxyMethodName is the constant name of the ReverseProxy authentication method
+const ReverseProxyMethodName = "reverse_proxy"
+
 // ReverseProxy implements the Auth interface, but actually relies on
 // a reverse proxy for authentication of users.
 // On successful authentication the proxy is expected to populate the username in the
@@ -43,7 +46,7 @@ func (r *ReverseProxy) getUserName(req *http.Request) string {
 
 // Name represents the name of auth method
 func (r *ReverseProxy) Name() string {
-       return "reverse_proxy"
+       return ReverseProxyMethodName
 }
 
 // Verify extracts the username from the "setting.ReverseProxyAuthUser" header