1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-17 09:57:01 +00:00

update dependencies

This commit is contained in:
Gerasimos (Makis) Maropoulos
2025-08-15 23:29:20 +03:00
parent de4f462198
commit a8a3afea22
186 changed files with 694 additions and 689 deletions

View File

@@ -42,7 +42,7 @@ const (
//
// Default implementations are:
// AllowUsers and AllowUsersFile functions.
type AuthFunc func(ctx *context.Context, username, password string) (interface{}, bool)
type AuthFunc func(ctx *context.Context, username, password string) (any, bool)
// ErrorHandler should handle the given request credentials failure.
// See Options.ErrorHandler and DefaultErrorHandler for details.
@@ -242,7 +242,7 @@ func New(opts Options) context.Handler {
// A user list can defined with one of the following values:
//
// map[string]string form of: {username:password, ...}
// map[string]interface{} form of: {"username": {"password": "...", "other_field": ...}, ...}
// map[string]any form of: {"username": {"password": "...", "other_field": ...}, ...}
// []T which T completes the User interface, where T is a struct value
// []T which T contains at least Username and Password fields.
//
@@ -252,7 +252,7 @@ func New(opts Options) context.Handler {
// "admin": "admin",
// "john": "p@ss",
// })
func Default(users interface{}, userOpts ...UserAuthOption) context.Handler {
func Default(users any, userOpts ...UserAuthOption) context.Handler {
opts := Options{
Realm: DefaultRealm,
Allow: AllowUsers(users, userOpts...),

View File

@@ -78,18 +78,18 @@ func toUserAuthOptions(opts []UserAuthOption) (options UserAuthOptions) {
// The "users" input parameter can be one of the following forms:
//
// map[string]string e.g. {username: password, username: password...}.
// []map[string]interface{} e.g. []{"username": "...", "password": "...", "other_field": ...}, ...}.
// []map[string]any e.g. []{"username": "...", "password": "...", "other_field": ...}, ...}.
// []T which T completes the User interface.
// []T which T contains at least Username and Password fields.
//
// Usage:
// New(Options{Allow: AllowUsers(..., [BCRYPT])})
func AllowUsers(users interface{}, opts ...UserAuthOption) AuthFunc {
func AllowUsers(users any, opts ...UserAuthOption) AuthFunc {
// create a local user structure to be used in the map copy,
// takes longer to initialize but faster to serve.
type user struct {
password string
ref interface{}
ref any
}
cp := make(map[string]*user)
@@ -114,7 +114,7 @@ func AllowUsers(users interface{}, opts ...UserAuthOption) AuthFunc {
switch m := elem.(type) {
case map[string]string:
return userMap(m, opts...)
case map[string]interface{}:
case map[string]any:
username, password, ok := mapUsernameAndPassword(m)
if !ok {
break
@@ -133,7 +133,7 @@ func AllowUsers(users interface{}, opts ...UserAuthOption) AuthFunc {
options := toUserAuthOptions(opts)
return func(_ *context.Context, username, password string) (interface{}, bool) {
return func(_ *context.Context, username, password string) (any, bool) {
if u, ok := cp[username]; ok { // fast map access,
if options.ComparePassword(u.password, password) {
return u.ref, true
@@ -147,7 +147,7 @@ func AllowUsers(users interface{}, opts ...UserAuthOption) AuthFunc {
func userMap(usernamePassword map[string]string, opts ...UserAuthOption) AuthFunc {
options := toUserAuthOptions(opts)
return func(_ *context.Context, username, password string) (interface{}, bool) {
return func(_ *context.Context, username, password string) (any, bool) {
pass, ok := usernamePassword[username]
return nil, ok && options.ComparePassword(pass, password)
}
@@ -173,7 +173,7 @@ func AllowUsersFile(jsonOrYamlFilename string, opts ...UserAuthOption) AuthFunc
usernamePassword map[string]string
// no need to support too much forms, this would be for:
// "$username": { "password": "$pass", "other_field": ...}
userList []map[string]interface{}
userList []map[string]any
)
if err := decodeFile(jsonOrYamlFilename, &usernamePassword, &userList); err != nil {
@@ -199,7 +199,7 @@ func AllowUsersFile(jsonOrYamlFilename string, opts ...UserAuthOption) AuthFunc
panic("malformed document file: " + jsonOrYamlFilename)
}
func decodeFile(src string, dest ...interface{}) error {
func decodeFile(src string, dest ...any) error {
data, err := ReadFile(src)
if err != nil {
return err
@@ -208,7 +208,7 @@ func decodeFile(src string, dest ...interface{}) error {
// We use unmarshal instead of file decoder
// as we may need to read it more than once (dests, see below).
var (
unmarshal func(data []byte, v interface{}) error
unmarshal func(data []byte, v any) error
ext string
)
@@ -245,7 +245,7 @@ func decodeFile(src string, dest ...interface{}) error {
return nil // if at least one is succeed we are ok.
}
func extractUsernameAndPassword(s interface{}) (username, password string, ok bool) {
func extractUsernameAndPassword(s any) (username, password string, ok bool) {
if s == nil {
return
}
@@ -256,7 +256,7 @@ func extractUsernameAndPassword(s interface{}) (username, password string, ok bo
password = u.GetPassword()
ok = username != "" && password != ""
return
case map[string]interface{}:
case map[string]any:
return mapUsernameAndPassword(u)
default:
b, err := json.Marshal(u)
@@ -264,7 +264,7 @@ func extractUsernameAndPassword(s interface{}) (username, password string, ok bo
return
}
var m map[string]interface{}
var m map[string]any
if err = json.Unmarshal(b, &m); err != nil {
return
}
@@ -273,7 +273,7 @@ func extractUsernameAndPassword(s interface{}) (username, password string, ok bo
}
}
func mapUsernameAndPassword(m map[string]interface{}) (username, password string, ok bool) {
func mapUsernameAndPassword(m map[string]any) (username, password string, ok bool) {
// type of username: password.
if len(m) == 1 {
for username, v := range m {

View File

@@ -13,13 +13,13 @@ import (
)
type IUserRepository interface {
GetByUsernameAndPassword(dest interface{}, username, password string) error
GetByUsernameAndPassword(dest any, username, password string) error
}
// Test a custom implementation of AuthFunc with a user repository.
// This is a usage example of custom AuthFunc implementation.
func UserRepository(repo IUserRepository, newUserPtr func() interface{}) AuthFunc {
return func(_ *context.Context, username, password string) (interface{}, bool) {
func UserRepository(repo IUserRepository, newUserPtr func() any) AuthFunc {
return func(_ *context.Context, username, password string) (any, bool) {
dest := newUserPtr()
err := repo.GetByUsernameAndPassword(dest, username, password)
if err == nil {
@@ -50,7 +50,7 @@ type testRepo struct {
}
// Implements IUserRepository interface.
func (r *testRepo) GetByUsernameAndPassword(dest interface{}, username, password string) error {
func (r *testRepo) GetByUsernameAndPassword(dest any, username, password string) error {
for _, e := range r.entries {
if e.username == username && e.password == password {
*dest.(*testUser) = e
@@ -68,7 +68,7 @@ func TestAllowUserRepository(t *testing.T) {
},
}
allow := UserRepository(repo, func() interface{} {
allow := UserRepository(repo, func() any {
return new(testUser)
})
@@ -260,7 +260,7 @@ func TestAllowUsersFile(t *testing.T) {
u, ok := v.(context.Map)
if !ok {
t.Fatalf("[%d] a user loaded from external source or file should be alway type of map[string]interface{} but got: %#+v (%T)", i, v, v)
t.Fatalf("[%d] a user loaded from external source or file should be alway type of map[string]any but got: %#+v (%T)", i, v, v)
}
if expected, got := len(tt.user), len(u); expected != got {