package sts import ( "context" "fmt" "sync" "time" ) // MemorySessionStore implements SessionStore using in-memory storage type MemorySessionStore struct { sessions map[string]*SessionInfo mutex sync.RWMutex } // NewMemorySessionStore creates a new memory-based session store func NewMemorySessionStore() *MemorySessionStore { return &MemorySessionStore{ sessions: make(map[string]*SessionInfo), } } // StoreSession stores session information in memory func (m *MemorySessionStore) StoreSession(ctx context.Context, sessionId string, session *SessionInfo) error { if sessionId == "" { return fmt.Errorf("session ID cannot be empty") } if session == nil { return fmt.Errorf("session cannot be nil") } m.mutex.Lock() defer m.mutex.Unlock() m.sessions[sessionId] = session return nil } // GetSession retrieves session information from memory func (m *MemorySessionStore) GetSession(ctx context.Context, sessionId string) (*SessionInfo, error) { if sessionId == "" { return nil, fmt.Errorf("session ID cannot be empty") } m.mutex.RLock() defer m.mutex.RUnlock() session, exists := m.sessions[sessionId] if !exists { return nil, fmt.Errorf("session not found") } // Check if session has expired if time.Now().After(session.ExpiresAt) { return nil, fmt.Errorf("session has expired") } return session, nil } // RevokeSession revokes a session from memory func (m *MemorySessionStore) RevokeSession(ctx context.Context, sessionId string) error { if sessionId == "" { return fmt.Errorf("session ID cannot be empty") } m.mutex.Lock() defer m.mutex.Unlock() delete(m.sessions, sessionId) return nil } // CleanupExpiredSessions removes expired sessions from memory func (m *MemorySessionStore) CleanupExpiredSessions(ctx context.Context) error { m.mutex.Lock() defer m.mutex.Unlock() now := time.Now() for sessionId, session := range m.sessions { if now.After(session.ExpiresAt) { delete(m.sessions, sessionId) } } return nil } // FilerSessionStore implements SessionStore using SeaweedFS filer type FilerSessionStore struct { // TODO: Add filer client configuration basePath string } // NewFilerSessionStore creates a new filer-based session store func NewFilerSessionStore(config map[string]interface{}) (*FilerSessionStore, error) { // TODO: Implement filer session store initialization // 1. Parse configuration for filer connection // 2. Set up filer client // 3. Configure base path for session storage return nil, fmt.Errorf("filer session store not implemented yet") } // StoreSession stores session information in filer func (f *FilerSessionStore) StoreSession(ctx context.Context, sessionId string, session *SessionInfo) error { // TODO: Implement filer session storage // 1. Serialize session information to JSON/protobuf // 2. Store in filer at configured path + sessionId // 3. Handle errors and retries return fmt.Errorf("filer session storage not implemented yet") } // GetSession retrieves session information from filer func (f *FilerSessionStore) GetSession(ctx context.Context, sessionId string) (*SessionInfo, error) { // TODO: Implement filer session retrieval // 1. Read session data from filer // 2. Deserialize JSON/protobuf to SessionInfo // 3. Check expiration // 4. Handle not found cases return nil, fmt.Errorf("filer session retrieval not implemented yet") } // RevokeSession revokes a session from filer func (f *FilerSessionStore) RevokeSession(ctx context.Context, sessionId string) error { // TODO: Implement filer session revocation // 1. Delete session file from filer // 2. Handle errors return fmt.Errorf("filer session revocation not implemented yet") } // CleanupExpiredSessions removes expired sessions from filer func (f *FilerSessionStore) CleanupExpiredSessions(ctx context.Context) error { // TODO: Implement filer session cleanup // 1. List all session files in base path // 2. Read and check expiration times // 3. Delete expired sessions return fmt.Errorf("filer session cleanup not implemented yet") }