History

Remove `Named` interface (#26913)

`Named` is implemented by every `Method` and future implementations should implement the method too.

KN4CK3R committed 3 years ago

Commit 0eebeee1 parent a99b96c12 files · +12 −21Browse files

Unified · Split

12 files
  1. routers/api/packages/chef/auth.go +2 −0
  2. routers/api/packages/conan/auth.go +2 −0
  3. routers/api/packages/container/auth.go +2 −0
  4. routers/api/packages/nuget/auth.go +2 −0
  5. services/auth/basic.go +0 −1
  6. services/auth/group.go +4 −12
  7. services/auth/httpsign.go +0 −1
  8. services/auth/interface.go +0 −3
  9. services/auth/oauth2.go +0 −1
  10. services/auth/reverseproxy.go +0 −1
  11. services/auth/session.go +0 −1
  12. services/auth/sspi_windows.go +0 −1
routers/api/packages/chef/auth.go+2−0
@@ -36,6 +36,8 @@ var ( · 35 unmodified lines
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+2−0
@@ -12,6 +12,8 @@ import ( · 11 unmodified lines
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+2−0
@@ -12,6 +12,8 @@ import ( · 11 unmodified lines
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+2−0
@@ -13,6 +13,8 @@ import ( · 12 unmodified lines
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+0−1
@@ -21,7 +21,6 @@ import ( · 20 unmodified lines
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+4−12
@@ -5,7 +5,6 @@ package auth · 4 unmodified lines
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) { · 25 unmodified lines
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 · 9 unmodified lines
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+0−1
@@ -23,7 +23,6 @@ import ( · 22 unmodified lines
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+0−3
@@ -27,10 +27,7 @@ type Method interface { · 26 unmodified lines
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+0−1
@@ -22,7 +22,6 @@ import ( · 21 unmodified lines
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+0−1
@@ -20,7 +20,6 @@ import ( · 19 unmodified lines
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+0−1
@@ -14,7 +14,6 @@ import ( · 13 unmodified lines
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+0−1
@@ -37,7 +37,6 @@ var ( · 36 unmodified lines
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

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t