Skip to content

Remove Named interface #26913

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions routers/api/packages/chef/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions routers/api/packages/conan/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"code.gitea.io/gitea/services/packages"
)

var _ auth.Method = &Auth{}

type Auth struct{}

func (a *Auth) Name() string {
Expand Down
2 changes: 2 additions & 0 deletions routers/api/packages/container/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"code.gitea.io/gitea/services/packages"
)

var _ auth.Method = &Auth{}

type Auth struct{}

func (a *Auth) Name() string {
Expand Down
2 changes: 2 additions & 0 deletions routers/api/packages/nuget/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"code.gitea.io/gitea/services/auth"
)

var _ auth.Method = &Auth{}

type Auth struct{}

func (a *Auth) Name() string {
Expand Down
1 change: 0 additions & 1 deletion services/auth/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 4 additions & 12 deletions services/auth/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package auth

import (
"net/http"
"reflect"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

"strings"

user_model "code.gitea.io/gitea/models/user"
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down
1 change: 0 additions & 1 deletion services/auth/httpsign.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions services/auth/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
1 change: 0 additions & 1 deletion services/auth/oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
// Ensure the struct implements the interface.
var (
_ Method = &OAuth2{}
_ Named = &OAuth2{}
)

// CheckOAuthAccessToken returns uid of user from oauth token
Expand Down
1 change: 0 additions & 1 deletion services/auth/reverseproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion services/auth/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion services/auth/sspi_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ var (

// Ensure the struct implements the interface.
_ Method = &SSPI{}
_ Named = &SSPI{}
)

// SSPI implements the SingleSignOn interface and authenticates requests
Expand Down