apikey

package
v1.32.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2025 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SnapshotVersion   = 0
	FileName          = "users.json"
	UserNameMaxLength = 128
	UserNameRegexCore = `[A-Za-z][-_0-9A-Za-z@.]{0,128}`
)

Variables

This section is empty.

Functions

func ReadFile added in v1.30.0

func ReadFile(filename string) ([]byte, error)

Types

type ApiKey added in v1.30.0

type ApiKey struct {
	Dynamic *DBUser
	// contains filtered or unexported fields
}

func New

func New(cfg config.Config, logger logrus.FieldLogger) (*ApiKey, error)

func (*ApiKey) ValidateAndExtract added in v1.30.0

func (a *ApiKey) ValidateAndExtract(token string, scopes []string) (*models.Principal, error)

type DBUser added in v1.30.0

type DBUser struct {
	// contains filtered or unexported fields
}

func NewDBUser added in v1.30.0

func NewDBUser(path string, enabled bool, logger logrus.FieldLogger) (*DBUser, error)

func (*DBUser) ActivateUser added in v1.30.0

func (c *DBUser) ActivateUser(userId string) error

func (*DBUser) CheckUserIdentifierExists added in v1.30.0

func (c *DBUser) CheckUserIdentifierExists(userIdentifier string) (bool, error)

func (*DBUser) Close added in v1.30.1

func (c *DBUser) Close() error

func (*DBUser) CreateUser added in v1.30.0

func (c *DBUser) CreateUser(userId, secureHash, userIdentifier, apiKeyFirstLetters string, createdAt time.Time) error

func (*DBUser) CreateUserWithKey added in v1.30.10

func (c *DBUser) CreateUserWithKey(userId, apiKeyFirstLetters string, weakHash [sha256.Size]byte, createdAt time.Time) error

func (*DBUser) DeactivateUser added in v1.30.0

func (c *DBUser) DeactivateUser(userId string, revokeKey bool) error

func (*DBUser) DeleteUser added in v1.30.0

func (c *DBUser) DeleteUser(userId string) error

func (*DBUser) GetUsers added in v1.30.0

func (c *DBUser) GetUsers(userIds ...string) (map[string]*User, error)

func (*DBUser) IsBlockedKey added in v1.30.10

func (c *DBUser) IsBlockedKey(token string) bool

func (*DBUser) Restore added in v1.30.0

func (c *DBUser) Restore(snapshot []byte) error

func (*DBUser) RotateKey added in v1.30.0

func (c *DBUser) RotateKey(userId, apiKeyFirstLetters, secureHash, oldIdentifier, newIdentifier string) error

func (*DBUser) Snapshot added in v1.30.0

func (c *DBUser) Snapshot() ([]byte, error)

func (*DBUser) UpdateLastUsedTimestamp added in v1.30.1

func (c *DBUser) UpdateLastUsedTimestamp(users map[string]time.Time)

func (*DBUser) ValidateAndExtract added in v1.30.0

func (c *DBUser) ValidateAndExtract(key, userIdentifier string) (*models.Principal, error)

func (*DBUser) ValidateImportedKey added in v1.30.10

func (c *DBUser) ValidateImportedKey(token string) (*models.Principal, error)

type DBUserSnapshot added in v1.30.0

type DBUserSnapshot struct {
	Data    dbUserdata
	Version int
}

type DBUsers added in v1.30.0

type DBUsers interface {
	CreateUser(userId, secureHash, userIdentifier, apiKeyFirstLetters string, createdAt time.Time) error
	CreateUserWithKey(userId, apiKeyFirstLetters string, weakHash [sha256.Size]byte, createdAt time.Time) error
	DeleteUser(userId string) error
	ActivateUser(userId string) error
	DeactivateUser(userId string, revokeKey bool) error
	GetUsers(userIds ...string) (map[string]*User, error)
	RotateKey(userId, apiKeyFirstLetters, secureHash, oldIdentifier, newIdentifier string) error
	CheckUserIdentifierExists(userIdentifier string) (bool, error)
}

type RemoteApiKey added in v1.30.1

type RemoteApiKey struct {
	// contains filtered or unexported fields
}

func NewRemoteApiKey added in v1.30.1

func NewRemoteApiKey(apikey *ApiKey) *RemoteApiKey

func (*RemoteApiKey) GetUserStatus added in v1.30.1

func (r *RemoteApiKey) GetUserStatus(ctx context.Context, users UserStatusRequest) (*UserStatusResponse, error)

type StaticApiKey added in v1.30.0

type StaticApiKey struct {
	// contains filtered or unexported fields
}

func NewStatic added in v1.30.0

func NewStatic(cfg config.Config) (*StaticApiKey, error)

func (*StaticApiKey) ValidateAndExtract added in v1.30.0

func (c *StaticApiKey) ValidateAndExtract(token string, scopes []string) (*models.Principal, error)

type User added in v1.30.0

type User struct {
	sync.RWMutex
	Id                 string
	Active             bool
	InternalIdentifier string
	ApiKeyFirstLetters string
	CreatedAt          time.Time
	LastUsedAt         time.Time
	ImportedWithKey    bool
}

type UserStatusRequest added in v1.30.1

type UserStatusRequest struct {
	Users        map[string]time.Time
	ReturnStatus bool
}

type UserStatusResponse added in v1.30.1

type UserStatusResponse struct {
	Users map[string]time.Time
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL