Skip to content

Commit f8ec43d

Browse files
authored
Extract constant names out for the ReverseProxy and Basic authentication methods (#17735)
In order to reduce load on the GC extract out the constant names of the Basic and ReverseProxy methods. As mentioned in #15119 (comment) Signed-off-by: Andrew Thornton <[email protected]>
1 parent 931d0cf commit f8ec43d

File tree

5 files changed

+11
-5
lines changed

5 files changed

+11
-5
lines changed

modules/context/api.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func APIAuth(authMethod auth.Method) func(*APIContext) {
245245
// Get user from session if logged in.
246246
ctx.User = authMethod.Verify(ctx.Req, ctx.Resp, ctx, ctx.Session)
247247
if ctx.User != nil {
248-
ctx.IsBasicAuth = ctx.Data["AuthedMethod"].(string) == new(auth.Basic).Name()
248+
ctx.IsBasicAuth = ctx.Data["AuthedMethod"].(string) == auth.BasicMethodName
249249
ctx.IsSigned = true
250250
ctx.Data["IsSigned"] = ctx.IsSigned
251251
ctx.Data["SignedUser"] = ctx.User

modules/context/context.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ func Auth(authMethod auth.Method) func(*Context) {
614614
return func(ctx *Context) {
615615
ctx.User = authMethod.Verify(ctx.Req, ctx.Resp, ctx, ctx.Session)
616616
if ctx.User != nil {
617-
ctx.IsBasicAuth = ctx.Data["AuthedMethod"].(string) == new(auth.Basic).Name()
617+
ctx.IsBasicAuth = ctx.Data["AuthedMethod"].(string) == auth.BasicMethodName
618618
ctx.IsSigned = true
619619
ctx.Data["IsSigned"] = ctx.IsSigned
620620
ctx.Data["SignedUser"] = ctx.User

routers/api/v1/api.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ func reqExploreSignIn() func(ctx *context.APIContext) {
217217

218218
func reqBasicOrRevProxyAuth() func(ctx *context.APIContext) {
219219
return func(ctx *context.APIContext) {
220-
if ctx.IsSigned && setting.Service.EnableReverseProxyAuth && ctx.Data["AuthedMethod"].(string) == new(auth.ReverseProxy).Name() {
220+
if ctx.IsSigned && setting.Service.EnableReverseProxyAuth && ctx.Data["AuthedMethod"].(string) == auth.ReverseProxyMethodName {
221221
return
222222
}
223223
if !ctx.Context.IsBasicAuth {

services/auth/basic.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ var (
2323
_ Named = &Basic{}
2424
)
2525

26+
// BasicMethodName is the constant name of the basic authentication method
27+
const BasicMethodName = "basic"
28+
2629
// Basic implements the Auth interface and authenticates requests (API requests
2730
// only) by looking for Basic authentication data or "x-oauth-basic" token in the "Authorization"
2831
// header.
@@ -31,7 +34,7 @@ type Basic struct {
3134

3235
// Name represents the name of auth method
3336
func (b *Basic) Name() string {
34-
return "basic"
37+
return BasicMethodName
3538
}
3639

3740
// Verify extracts and validates Basic data (username and password/token) from the

services/auth/reverseproxy.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ var (
2424
_ Named = &ReverseProxy{}
2525
)
2626

27+
// ReverseProxyMethodName is the constant name of the ReverseProxy authentication method
28+
const ReverseProxyMethodName = "reverse_proxy"
29+
2730
// ReverseProxy implements the Auth interface, but actually relies on
2831
// a reverse proxy for authentication of users.
2932
// 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 {
4346

4447
// Name represents the name of auth method
4548
func (r *ReverseProxy) Name() string {
46-
return "reverse_proxy"
49+
return ReverseProxyMethodName
4750
}
4851

4952
// Verify extracts the username from the "setting.ReverseProxyAuthUser" header

0 commit comments

Comments
 (0)