Skip to content

Commit 0eebeee

Browse files
authored
Remove Named interface (#26913)
`Named` is implemented by every `Method` and future implementations should implement the method too.
1 parent a99b96c commit 0eebeee

File tree

12 files changed

+12
-21
lines changed

12 files changed

+12
-21
lines changed

routers/api/packages/chef/auth.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ var (
3636
algorithmPattern = regexp.MustCompile(`algorithm=(\w+)`)
3737
versionPattern = regexp.MustCompile(`version=(\d+\.\d+)`)
3838
authorizationPattern = regexp.MustCompile(`\AX-Ops-Authorization-(\d+)`)
39+
40+
_ auth.Method = &Auth{}
3941
)
4042

4143
// Documentation:

routers/api/packages/conan/auth.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
"code.gitea.io/gitea/services/packages"
1313
)
1414

15+
var _ auth.Method = &Auth{}
16+
1517
type Auth struct{}
1618

1719
func (a *Auth) Name() string {

routers/api/packages/container/auth.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
"code.gitea.io/gitea/services/packages"
1313
)
1414

15+
var _ auth.Method = &Auth{}
16+
1517
type Auth struct{}
1618

1719
func (a *Auth) Name() string {

routers/api/packages/nuget/auth.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313
"code.gitea.io/gitea/services/auth"
1414
)
1515

16+
var _ auth.Method = &Auth{}
17+
1618
type Auth struct{}
1719

1820
func (a *Auth) Name() string {

services/auth/basic.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
// Ensure the struct implements the interface.
2222
var (
2323
_ Method = &Basic{}
24-
_ Named = &Basic{}
2524
)
2625

2726
// BasicMethodName is the constant name of the basic authentication method

services/auth/group.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package auth
55

66
import (
77
"net/http"
8-
"reflect"
98
"strings"
109

1110
user_model "code.gitea.io/gitea/models/user"
@@ -37,21 +36,16 @@ func (b *Group) Add(method Method) {
3736
func (b *Group) Name() string {
3837
names := make([]string, 0, len(b.methods))
3938
for _, m := range b.methods {
40-
if n, ok := m.(Named); ok {
41-
names = append(names, n.Name())
42-
} else {
43-
names = append(names, reflect.TypeOf(m).Elem().Name())
44-
}
39+
names = append(names, m.Name())
4540
}
4641
return strings.Join(names, ",")
4742
}
4843

49-
// Verify extracts and validates
5044
func (b *Group) Verify(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) (*user_model.User, error) {
5145
// Try to sign in with each of the enabled plugins
5246
var retErr error
53-
for _, ssoMethod := range b.methods {
54-
user, err := ssoMethod.Verify(req, w, store, sess)
47+
for _, m := range b.methods {
48+
user, err := m.Verify(req, w, store, sess)
5549
if err != nil {
5650
if retErr == nil {
5751
retErr = err
@@ -67,9 +61,7 @@ func (b *Group) Verify(req *http.Request, w http.ResponseWriter, store DataStore
6761
// Return the user and ignore any error returned by previous methods.
6862
if user != nil {
6963
if store.GetData()["AuthedMethod"] == nil {
70-
if named, ok := ssoMethod.(Named); ok {
71-
store.GetData()["AuthedMethod"] = named.Name()
72-
}
64+
store.GetData()["AuthedMethod"] = m.Name()
7365
}
7466
return user, nil
7567
}

services/auth/httpsign.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
// Ensure the struct implements the interface.
2424
var (
2525
_ Method = &HTTPSign{}
26-
_ Named = &HTTPSign{}
2726
)
2827

2928
// HTTPSign implements the Auth interface and authenticates requests (API requests

services/auth/interface.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ type Method interface {
2727
// Second argument returns err if verification fails, otherwise
2828
// First return argument returns nil if no matched verification condition
2929
Verify(http *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) (*user_model.User, error)
30-
}
3130

32-
// Named represents a named thing
33-
type Named interface {
3431
Name() string
3532
}
3633

services/auth/oauth2.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
// Ensure the struct implements the interface.
2323
var (
2424
_ Method = &OAuth2{}
25-
_ Named = &OAuth2{}
2625
)
2726

2827
// CheckOAuthAccessToken returns uid of user from oauth token

services/auth/reverseproxy.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
// Ensure the struct implements the interface.
2121
var (
2222
_ Method = &ReverseProxy{}
23-
_ Named = &ReverseProxy{}
2423
)
2524

2625
// ReverseProxyMethodName is the constant name of the ReverseProxy authentication method

services/auth/session.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
// Ensure the struct implements the interface.
1515
var (
1616
_ Method = &Session{}
17-
_ Named = &Session{}
1817
)
1918

2019
// Session checks if there is a user uid stored in the session and returns the user

services/auth/sspi_windows.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ var (
3737

3838
// Ensure the struct implements the interface.
3939
_ Method = &SSPI{}
40-
_ Named = &SSPI{}
4140
)
4241

4342
// SSPI implements the SingleSignOn interface and authenticates requests

0 commit comments

Comments
 (0)