From 0eebeeec9045c759d005ab0ba87f3275da7c627d Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Tue, 5 Sep 2023 17:58:30 +0200 Subject: [PATCH] Remove `Named` interface (#26913) `Named` is implemented by every `Method` and future implementations should implement the method too. --- routers/api/packages/chef/auth.go | 2 ++ routers/api/packages/conan/auth.go | 2 ++ routers/api/packages/container/auth.go | 2 ++ routers/api/packages/nuget/auth.go | 2 ++ services/auth/basic.go | 1 - services/auth/group.go | 16 ++++------------ services/auth/httpsign.go | 1 - services/auth/interface.go | 3 --- services/auth/oauth2.go | 1 - services/auth/reverseproxy.go | 1 - services/auth/session.go | 1 - services/auth/sspi_windows.go | 1 - 12 files changed, 12 insertions(+), 21 deletions(-) diff --git a/routers/api/packages/chef/auth.go b/routers/api/packages/chef/auth.go index 1ea453f1f..d89564089 100644 --- a/routers/api/packages/chef/auth.go +++ b/routers/api/packages/chef/auth.go @@ -36,6 +36,8 @@ var ( algorithmPattern = regexp.MustCompile(`algorithm=(\w+)`) versionPattern = regexp.MustCompile(`version=(\d+\.\d+)`) authorizationPattern = regexp.MustCompile(`\AX-Ops-Authorization-(\d+)`) + + _ auth.Method = &Auth{} ) // Documentation: diff --git a/routers/api/packages/conan/auth.go b/routers/api/packages/conan/auth.go index ca02d61e7..521fa1237 100644 --- a/routers/api/packages/conan/auth.go +++ b/routers/api/packages/conan/auth.go @@ -12,6 +12,8 @@ import ( "code.gitea.io/gitea/services/packages" ) +var _ auth.Method = &Auth{} + type Auth struct{} func (a *Auth) Name() string { diff --git a/routers/api/packages/container/auth.go b/routers/api/packages/container/auth.go index 6fb32c389..1c7afa95f 100644 --- a/routers/api/packages/container/auth.go +++ b/routers/api/packages/container/auth.go @@ -12,6 +12,8 @@ import ( "code.gitea.io/gitea/services/packages" ) +var _ auth.Method = &Auth{} + type Auth struct{} func (a *Auth) Name() string { diff --git a/routers/api/packages/nuget/auth.go b/routers/api/packages/nuget/auth.go index 54b33d89c..60b81b8d4 100644 --- a/routers/api/packages/nuget/auth.go +++ b/routers/api/packages/nuget/auth.go @@ -13,6 +13,8 @@ import ( "code.gitea.io/gitea/services/auth" ) +var _ auth.Method = &Auth{} + type Auth struct{} func (a *Auth) Name() string { diff --git a/services/auth/basic.go b/services/auth/basic.go index 36480568f..ea8df3d0e 100644 --- a/services/auth/basic.go +++ b/services/auth/basic.go @@ -21,7 +21,6 @@ import ( // Ensure the struct implements the interface. var ( _ Method = &Basic{} - _ Named = &Basic{} ) // BasicMethodName is the constant name of the basic authentication method diff --git a/services/auth/group.go b/services/auth/group.go index 7193dfcf4..aecf43cb2 100644 --- a/services/auth/group.go +++ b/services/auth/group.go @@ -5,7 +5,6 @@ package auth import ( "net/http" - "reflect" "strings" user_model "code.gitea.io/gitea/models/user" @@ -37,21 +36,16 @@ func (b *Group) Add(method Method) { func (b *Group) Name() string { names := make([]string, 0, len(b.methods)) for _, m := range b.methods { - if n, ok := m.(Named); ok { - names = append(names, n.Name()) - } else { - names = append(names, reflect.TypeOf(m).Elem().Name()) - } + names = append(names, m.Name()) } return strings.Join(names, ",") } -// Verify extracts and validates func (b *Group) Verify(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) (*user_model.User, error) { // Try to sign in with each of the enabled plugins var retErr error - for _, ssoMethod := range b.methods { - user, err := ssoMethod.Verify(req, w, store, sess) + for _, m := range b.methods { + user, err := m.Verify(req, w, store, sess) if err != nil { if retErr == nil { retErr = err @@ -67,9 +61,7 @@ func (b *Group) Verify(req *http.Request, w http.ResponseWriter, store DataStore // Return the user and ignore any error returned by previous methods. if user != nil { if store.GetData()["AuthedMethod"] == nil { - if named, ok := ssoMethod.(Named); ok { - store.GetData()["AuthedMethod"] = named.Name() - } + store.GetData()["AuthedMethod"] = m.Name() } return user, nil } diff --git a/services/auth/httpsign.go b/services/auth/httpsign.go index 4d5231538..d6a64c6fc 100644 --- a/services/auth/httpsign.go +++ b/services/auth/httpsign.go @@ -23,7 +23,6 @@ import ( // Ensure the struct implements the interface. var ( _ Method = &HTTPSign{} - _ Named = &HTTPSign{} ) // HTTPSign implements the Auth interface and authenticates requests (API requests diff --git a/services/auth/interface.go b/services/auth/interface.go index 508291fa4..dc91747a4 100644 --- a/services/auth/interface.go +++ b/services/auth/interface.go @@ -27,10 +27,7 @@ type Method interface { // Second argument returns err if verification fails, otherwise // First return argument returns nil if no matched verification condition Verify(http *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) (*user_model.User, error) -} -// Named represents a named thing -type Named interface { Name() string } diff --git a/services/auth/oauth2.go b/services/auth/oauth2.go index 0dd7a12d2..e621b5ffa 100644 --- a/services/auth/oauth2.go +++ b/services/auth/oauth2.go @@ -22,7 +22,6 @@ import ( // Ensure the struct implements the interface. var ( _ Method = &OAuth2{} - _ Named = &OAuth2{} ) // CheckOAuthAccessToken returns uid of user from oauth token diff --git a/services/auth/reverseproxy.go b/services/auth/reverseproxy.go index 3574e660b..62e60ccdc 100644 --- a/services/auth/reverseproxy.go +++ b/services/auth/reverseproxy.go @@ -20,7 +20,6 @@ import ( // Ensure the struct implements the interface. var ( _ Method = &ReverseProxy{} - _ Named = &ReverseProxy{} ) // ReverseProxyMethodName is the constant name of the ReverseProxy authentication method diff --git a/services/auth/session.go b/services/auth/session.go index c75113573..52cfb8ac2 100644 --- a/services/auth/session.go +++ b/services/auth/session.go @@ -14,7 +14,6 @@ import ( // Ensure the struct implements the interface. var ( _ Method = &Session{} - _ Named = &Session{} ) // Session checks if there is a user uid stored in the session and returns the user diff --git a/services/auth/sspi_windows.go b/services/auth/sspi_windows.go index eabfd5fa4..a4880c733 100644 --- a/services/auth/sspi_windows.go +++ b/services/auth/sspi_windows.go @@ -37,7 +37,6 @@ var ( // Ensure the struct implements the interface. _ Method = &SSPI{} - _ Named = &SSPI{} ) // SSPI implements the SingleSignOn interface and authenticates requests