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
36 algorithmPattern = regexp.MustCompile(`algorithm=(\w+)`)36 algorithmPattern = regexp.MustCompile(`algorithm=(\w+)`)
37 versionPattern = regexp.MustCompile(`version=(\d+\.\d+)`)37 versionPattern = regexp.MustCompile(`version=(\d+\.\d+)`)
38 authorizationPattern = regexp.MustCompile(`\AX-Ops-Authorization-(\d+)`)38 authorizationPattern = regexp.MustCompile(`\AX-Ops-Authorization-(\d+)`)
39
40 _ auth.Method = &Auth{}
39)41)
40 42
41// Documentation:43// Documentation:
routers/api/packages/conan/auth.go+2−0
@@ -12,6 +12,8 @@ import ( · 11 unmodified lines
12 "code.gitea.io/gitea/services/packages"12 "code.gitea.io/gitea/services/packages"
13)13)
14 14
15var _ auth.Method = &Auth{}
16
15type Auth struct{}17type Auth struct{}
16 18
17func (a *Auth) Name() string {19func (a *Auth) Name() string {
routers/api/packages/container/auth.go+2−0
@@ -12,6 +12,8 @@ import ( · 11 unmodified lines
12 "code.gitea.io/gitea/services/packages"12 "code.gitea.io/gitea/services/packages"
13)13)
14 14
15var _ auth.Method = &Auth{}
16
15type Auth struct{}17type Auth struct{}
16 18
17func (a *Auth) Name() string {19func (a *Auth) Name() string {
routers/api/packages/nuget/auth.go+2−0
@@ -13,6 +13,8 @@ import ( · 12 unmodified lines
13 "code.gitea.io/gitea/services/auth"13 "code.gitea.io/gitea/services/auth"
14)14)
15 15
16var _ auth.Method = &Auth{}
17
16type Auth struct{}18type Auth struct{}
17 19
18func (a *Auth) Name() string {20func (a *Auth) Name() string {
services/auth/basic.go+0−1
@@ -21,7 +21,6 @@ import ( · 20 unmodified lines
21// Ensure the struct implements the interface.21// Ensure the struct implements the interface.
22var (22var (
23 _ Method = &Basic{}23 _ Method = &Basic{}
24 _ Named = &Basic{}
25)24)
26 25
27// BasicMethodName is the constant name of the basic authentication method26// 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
5 5
6import (6import (
7 "net/http"7 "net/http"
8 "reflect"
9 "strings"8 "strings"
10 9
11 user_model "code.gitea.io/gitea/models/user"10 user_model "code.gitea.io/gitea/models/user"
@@ -37,21 +36,16 @@ func (b *Group) Add(method Method) { · 25 unmodified lines
37func (b *Group) Name() string {36func (b *Group) Name() string {
38 names := make([]string, 0, len(b.methods))37 names := make([]string, 0, len(b.methods))
39 for _, m := range b.methods {38 for _, m := range b.methods {
40 if n, ok := m.(Named); ok {39 names = append(names, m.Name())
41 names = append(names, n.Name())
42 } else {
43 names = append(names, reflect.TypeOf(m).Elem().Name())
44 }
45 }40 }
46 return strings.Join(names, ",")41 return strings.Join(names, ",")
47}42}
48 43
49// Verify extracts and validates
50func (b *Group) Verify(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) (*user_model.User, error) {44func (b *Group) Verify(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) (*user_model.User, error) {
51 // Try to sign in with each of the enabled plugins45 // Try to sign in with each of the enabled plugins
52 var retErr error46 var retErr error
53 for _, ssoMethod := range b.methods {47 for _, m := range b.methods {
54 user, err := ssoMethod.Verify(req, w, store, sess)48 user, err := m.Verify(req, w, store, sess)
55 if err != nil {49 if err != nil {
56 if retErr == nil {50 if retErr == nil {
57 retErr = err51 retErr = err
@@ -67,9 +61,7 @@ func (b *Group) Verify(req *http.Request, w http.ResponseWriter, store DataStore · 9 unmodified lines
67 // Return the user and ignore any error returned by previous methods.61 // Return the user and ignore any error returned by previous methods.
68 if user != nil {62 if user != nil {
69 if store.GetData()["AuthedMethod"] == nil {63 if store.GetData()["AuthedMethod"] == nil {
70 if named, ok := ssoMethod.(Named); ok {64 store.GetData()["AuthedMethod"] = m.Name()
71 store.GetData()["AuthedMethod"] = named.Name()
72 }
73 }65 }
74 return user, nil66 return user, nil
75 }67 }
services/auth/httpsign.go+0−1
@@ -23,7 +23,6 @@ import ( · 22 unmodified lines
23// Ensure the struct implements the interface.23// Ensure the struct implements the interface.
24var (24var (
25 _ Method = &HTTPSign{}25 _ Method = &HTTPSign{}
26 _ Named = &HTTPSign{}
27)26)
28 27
29// HTTPSign implements the Auth interface and authenticates requests (API requests28// 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
27 // Second argument returns err if verification fails, otherwise27 // Second argument returns err if verification fails, otherwise
28 // First return argument returns nil if no matched verification condition28 // First return argument returns nil if no matched verification condition
29 Verify(http *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) (*user_model.User, error)29 Verify(http *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) (*user_model.User, error)
30}
31 30
32// Named represents a named thing
33type Named interface {
34 Name() string31 Name() string
35}32}
36 33
services/auth/oauth2.go+0−1
@@ -22,7 +22,6 @@ import ( · 21 unmodified lines
22// Ensure the struct implements the interface.22// Ensure the struct implements the interface.
23var (23var (
24 _ Method = &OAuth2{}24 _ Method = &OAuth2{}
25 _ Named = &OAuth2{}
26)25)
27 26
28// CheckOAuthAccessToken returns uid of user from oauth token27// CheckOAuthAccessToken returns uid of user from oauth token
services/auth/reverseproxy.go+0−1
@@ -20,7 +20,6 @@ import ( · 19 unmodified lines
20// Ensure the struct implements the interface.20// Ensure the struct implements the interface.
21var (21var (
22 _ Method = &ReverseProxy{}22 _ Method = &ReverseProxy{}
23 _ Named = &ReverseProxy{}
24)23)
25 24
26// ReverseProxyMethodName is the constant name of the ReverseProxy authentication method25// ReverseProxyMethodName is the constant name of the ReverseProxy authentication method
services/auth/session.go+0−1
@@ -14,7 +14,6 @@ import ( · 13 unmodified lines
14// Ensure the struct implements the interface.14// Ensure the struct implements the interface.
15var (15var (
16 _ Method = &Session{}16 _ Method = &Session{}
17 _ Named = &Session{}
18)17)
19 18
20// Session checks if there is a user uid stored in the session and returns the user19// 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
37 37
38 // Ensure the struct implements the interface.38 // Ensure the struct implements the interface.
39 _ Method = &SSPI{}39 _ Method = &SSPI{}
40 _ Named = &SSPI{}
41)40)
42 41
43// SSPI implements the SingleSignOn interface and authenticates requests42// 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