mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-20 09:16:40 +00:00
[client,management] Rewrite the SSH feature (#4015)
This commit is contained in:
@@ -4,7 +4,8 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/netbirdio/netbird/shared/auth"
|
||||
)
|
||||
|
||||
type key int
|
||||
@@ -13,45 +14,22 @@ const (
|
||||
UserAuthContextKey key = iota
|
||||
)
|
||||
|
||||
type UserAuth struct {
|
||||
// The account id the user is accessing
|
||||
AccountId string
|
||||
// The account domain
|
||||
Domain string
|
||||
// The account domain category, TBC values
|
||||
DomainCategory string
|
||||
// Indicates whether this user was invited, TBC logic
|
||||
Invited bool
|
||||
// Indicates whether this is a child account
|
||||
IsChild bool
|
||||
|
||||
// The user id
|
||||
UserId string
|
||||
// Last login time for this user
|
||||
LastLogin time.Time
|
||||
// The Groups the user belongs to on this account
|
||||
Groups []string
|
||||
|
||||
// Indicates whether this user has authenticated with a Personal Access Token
|
||||
IsPAT bool
|
||||
}
|
||||
|
||||
func GetUserAuthFromRequest(r *http.Request) (UserAuth, error) {
|
||||
func GetUserAuthFromRequest(r *http.Request) (auth.UserAuth, error) {
|
||||
return GetUserAuthFromContext(r.Context())
|
||||
}
|
||||
|
||||
func SetUserAuthInRequest(r *http.Request, userAuth UserAuth) *http.Request {
|
||||
func SetUserAuthInRequest(r *http.Request, userAuth auth.UserAuth) *http.Request {
|
||||
return r.WithContext(SetUserAuthInContext(r.Context(), userAuth))
|
||||
}
|
||||
|
||||
func GetUserAuthFromContext(ctx context.Context) (UserAuth, error) {
|
||||
if userAuth, ok := ctx.Value(UserAuthContextKey).(UserAuth); ok {
|
||||
func GetUserAuthFromContext(ctx context.Context) (auth.UserAuth, error) {
|
||||
if userAuth, ok := ctx.Value(UserAuthContextKey).(auth.UserAuth); ok {
|
||||
return userAuth, nil
|
||||
}
|
||||
return UserAuth{}, fmt.Errorf("user auth not in context")
|
||||
return auth.UserAuth{}, fmt.Errorf("user auth not in context")
|
||||
}
|
||||
|
||||
func SetUserAuthInContext(ctx context.Context, userAuth UserAuth) context.Context {
|
||||
func SetUserAuthInContext(ctx context.Context, userAuth auth.UserAuth) context.Context {
|
||||
//nolint
|
||||
ctx = context.WithValue(ctx, UserIDKey, userAuth.UserId)
|
||||
//nolint
|
||||
|
||||
Reference in New Issue
Block a user