Documentation
¶
Overview ¶
Package sessions provides session management use cases for Redfish SessionService
Package sessions provides business logic for Redfish SessionService
Index ¶
- Constants
- Variables
- type Repository
- type UseCase
- func (uc *UseCase) CreateSession(username, password, clientIP, userAgent string) (*entity.Session, string, error)
- func (uc *UseCase) DeleteSession(sessionID string) error
- func (uc *UseCase) GetSession(sessionID string) (*entity.Session, error)
- func (uc *UseCase) GetSessionCount() (int, error)
- func (uc *UseCase) ListSessions() ([]*entity.Session, error)
- func (uc *UseCase) ValidateToken(tokenString string) (*entity.Session, error)
Constants ¶
const (
// DefaultSessionTimeout is the default session timeout in seconds (30 minutes).
DefaultSessionTimeout = 1800
)
Variables ¶
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") )
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 ¶
DeleteSession terminates a session (logout).
func (*UseCase) GetSession ¶
GetSession retrieves a session by ID.
func (*UseCase) GetSessionCount ¶
GetSessionCount returns the number of active sessions.
func (*UseCase) ListSessions ¶
ListSessions returns all active sessions.