Files
opencloud/services/auth-guest/pkg/service/storage/storage.go
T
André Duffeck 564e1c0ec7 Rate limit guest link renewals with a valid session separately
Each session renewal issues a PIN with fresh attempts, so without a limit a stolen session could keep guessing. The quota is separate from the one for renewals without a session, so neither can use up the other's.
2026-10-16 13:05:38 +02:00

50 lines
1.9 KiB
Go

// Copyright 2026 OpenCloud GmbH <mail@opencloud.eu>
// SPDX-License-Identifier: Apache-2.0
package storage
import (
"errors"
"time"
"github.com/opencloud-eu/opencloud/services/auth-guest/pkg/service/guard"
)
var ErrNotFound = errors.New("record not found")
var ErrInvalidHash = errors.New("invalid share id hash")
var ErrConflict = errors.New("record was modified concurrently")
// Record holds the data persisted for a guest share token.
type Record struct {
ShareID string `json:"shareid"`
ShareIDHash string `json:"shareidhash"`
SecretHash string `json:"secrethash"`
PinHash string `json:"pinhash"`
Expiry time.Time `json:"expiry,omitzero"`
PinExpiry time.Time `json:"pinexpiry,omitzero"`
Redeemed bool `json:"redeemed"`
Revision uint64 `json:"revision"`
NonceState guard.NonceState `json:"nonce,omitzero"`
BackoffLimiterState guard.BackoffLimiterState `json:"backoff_limiter,omitzero"`
QuotaLimiterState guard.QuotaLimiterState `json:"quota_limiter,omitzero"`
SessionQuotaLimiterState guard.QuotaLimiterState `json:"session_quota_limiter,omitzero"`
}
// NewRecord returns a record for the given token.
func NewRecord(shareID, shareIDHash, secretHash string, expiry time.Time) Record {
return Record{
ShareID: shareID,
ShareIDHash: shareIDHash,
SecretHash: secretHash,
Expiry: expiry,
}
}
type Manager interface {
Add(rec Record) error
Get(shareIDHash string) (*Record, error)
Remove(shareIDHash string) error
Update(shareIDHash string, fn func(*Record) error) error
UpdateFrom(seen Record, fn func(*Record) error) (*Record, error)
}