Raw
 1package storage
 2
 3import (
 4	"context"
 5	"fmt"
 6	"time"
 7)
 8
 9func (s *Store) RevokeOwnForwardSessionAudited(ctx context.Context, userID, sessionID string, audit AppendAuditInput) error {
10	return s.RevokeOwnForwardSessionAuditedAt(ctx, userID, sessionID, audit, s.now())
11}
12
13func (s *Store) RevokeOwnForwardSessionAuditedAt(ctx context.Context, userID, sessionID string, audit AppendAuditInput, now time.Time) error {
14	const operation = "revoke own forward session"
15	if err := s.checkOpen(operation); err != nil {
16		return err
17	}
18	tx, err := s.sql.BeginTx(ctx, nil)
19	if err != nil {
20		return classify("begin "+operation, err)
21	}
22	defer tx.Rollback()
23	changed, err := execCount(ctx, tx, operation, `UPDATE forward_sessions SET revoked = 1 WHERE id = ? AND user_id = ? AND revoked = 0`, sessionID, userID)
24	if err != nil {
25		return err
26	}
27	if changed == 0 {
28		return fmt.Errorf("%s: %w", operation, ErrNotFound)
29	}
30	if _, err := appendAudit(ctx, tx, operation+" audit", audit, canonicalTime(now)); err != nil {
31		return err
32	}
33	return classify("commit "+operation, tx.Commit())
34}