sessions

package
v1.19.2-redfish.preview.1 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package sessions provides session management use cases for Redfish SessionService

Package sessions provides business logic for Redfish SessionService

Index

Constants

View Source
const (
	// DefaultSessionTimeout is the default session timeout in seconds (30 minutes).
	DefaultSessionTimeout = 1800
)

Variables

View Source
var (
	// ErrSessionNotFound is returned when a session cannot be found.
	ErrSessionNotFound = errors.New("session not found")

	// ErrSessionExpired is returned when a session has expired.
	ErrSessionExpired = errors.New("session expired")

	// ErrInvalidToken is returned when a token is invalid.
	ErrInvalidToken = errors.New("invalid token")

	// ErrSessionAlreadyExists is returned when trying to create a session for a user who already has an active session.
	ErrSessionAlreadyExists = errors.New("an active session already exists for this user")
)
View Source
var ErrInvalidCredentials = ErrInvalidToken // ErrInvalidCredentials is returned when credentials are invalid.

Functions

This section is empty.

Types

type Repository

type Repository interface {
	// Create stores a new session
	Create(session *entity.Session) error

	// Update modifies an existing session
	Update(session *entity.Session) error

	// Get retrieves a session by ID
	Get(id string) (*entity.Session, error)

	// GetByToken retrieves a session by token
	GetByToken(token string) (*entity.Session, error)

	// Delete removes a session
	Delete(id string) error

	// List returns all active sessions
	List() ([]*entity.Session, error)

	// DeleteExpired removes all expired sessions
	DeleteExpired() (int, error)
}

Repository defines the interface for session storage.

type UseCase

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

UseCase defines the session management business logic.

func NewUseCase

func NewUseCase(repo Repository, cfg *config.Config) *UseCase

NewUseCase creates a new session use case.

func (*UseCase) CreateSession

func (uc *UseCase) CreateSession(username, password, clientIP, userAgent string) (*entity.Session, string, error)

CreateSession creates a new session with JWT token. This integrates with DMT Console's existing JWT authentication. If a session already exists for this user, it returns an error to prevent multiple concurrent sessions.

func (*UseCase) DeleteSession

func (uc *UseCase) DeleteSession(sessionID string) error

DeleteSession terminates a session (logout).

func (*UseCase) GetSession

func (uc *UseCase) GetSession(sessionID string) (*entity.Session, error)

GetSession retrieves a session by ID.

func (*UseCase) GetSessionCount

func (uc *UseCase) GetSessionCount() (int, error)

GetSessionCount returns the number of active sessions.

func (*UseCase) ListSessions

func (uc *UseCase) ListSessions() ([]*entity.Session, error)

ListSessions returns all active sessions.

func (*UseCase) ValidateToken

func (uc *UseCase) ValidateToken(tokenString string) (*entity.Session, error)

ValidateToken validates a session token (JWT). This can work in two modes: 1. Stateless: Just validate JWT signature and expiration. 2. Stateful: Also check if session exists and is active.

Jump to

Keyboard shortcuts

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