Documentation
¶
Overview ¶
SPDX-License-Identifier: AGPL-3.0-or-later
SPDX-License-Identifier: AGPL-3.0-or-later
SPDX-License-Identifier: AGPL-3.0-or-later
SPDX-License-Identifier: AGPL-3.0-or-later
SPDX-License-Identifier: AGPL-3.0-or-later
SPDX-License-Identifier: AGPL-3.0-or-later
Index ¶
- Constants
- Variables
- func EmbedDocumentMiddleware(docService docService, publisher webhookPublisher) func(http.Handler) http.Handler
- func EmbedFolder(fsEmbed embed.FS, targetPath string, baseURL string, version string, ...) http.HandlerFunc
- type AuditEvent
- type AuditLogger
- type AuthProvider
- type AuthResult
- type Authorizer
- type ConfigProvider
- type CryptoSigner
- type LogOnlyAuditLogger
- type MagicLinkProvider
- type MagicLinkResult
- type NoLimitQuotaEnforcer
- type QuotaAction
- type QuotaEnforcer
- type QuotaUsage
- type Server
- func (s *Server) ConfigService() *services.ConfigService
- func (s *Server) GetAddr() string
- func (s *Server) GetAuditLogger() AuditLogger
- func (s *Server) GetAuthProvider() AuthProvider
- func (s *Server) GetAuthorizer() Authorizer
- func (s *Server) GetDB() *sql.DB
- func (s *Server) GetEmailSender() email.Sender
- func (s *Server) GetMagicLinkProvider() MagicLinkProvider
- func (s *Server) GetQuotaEnforcer() QuotaEnforcer
- func (s *Server) RegisterRoutes(fn func(r *chi.Mux))
- func (s *Server) Router() *chi.Mux
- func (s *Server) Shutdown(ctx context.Context) error
- func (s *Server) Start() error
- type ServerBuilder
- func (b *ServerBuilder) Build(ctx context.Context) (*Server, error)
- func (b *ServerBuilder) WithAuditLogger(logger AuditLogger) *ServerBuilder
- func (b *ServerBuilder) WithAuthProvider(provider AuthProvider) *ServerBuilder
- func (b *ServerBuilder) WithAuthorizer(authorizer Authorizer) *ServerBuilder
- func (b *ServerBuilder) WithBaseURLProvider(p services.BaseURLProvider) *ServerBuilder
- func (b *ServerBuilder) WithCryptoSigner(s CryptoSigner) *ServerBuilder
- func (b *ServerBuilder) WithDB(db *sql.DB) *ServerBuilder
- func (b *ServerBuilder) WithQuotaEnforcer(enforcer QuotaEnforcer) *ServerBuilder
- func (b *ServerBuilder) WithStorageProvider(p storage.Provider) *ServerBuilder
- func (b *ServerBuilder) WithStorageQuotaChecker(checker StorageQuotaChecker) *ServerBuilder
- func (b *ServerBuilder) WithTenantProvider(tp providers.TenantProvider) *ServerBuilder
- type SignatureRepository
- type StorageQuotaChecker
- type UsageMetric
- type User
Constants ¶
const ( AuditActionLogin = "auth.login" AuditActionLogout = "auth.logout" AuditActionDocumentCreate = "document.create" AuditActionDocumentUpdate = "document.update" AuditActionDocumentDelete = "document.delete" AuditActionSignatureCreate = "signature.create" AuditActionReminderSend = "reminder.send" AuditActionWebhookCreate = "webhook.create" AuditActionWebhookUpdate = "webhook.update" AuditActionWebhookDelete = "webhook.delete" AuditActionSignerAdd = "signer.add" AuditActionSignerRemove = "signer.remove" AuditActionAdminAccess = "admin.access" )
AuditAction constants for common audit events.
Variables ¶
var ( ErrNotAuthenticated = errors.New("user not authenticated") ErrNotAuthorized = errors.New("user not authorized") ErrQuotaExceeded = errors.New("quota exceeded") ErrProviderDisabled = errors.New("provider is disabled") )
Common errors for capability providers.
Functions ¶
func EmbedDocumentMiddleware ¶
func EmbedDocumentMiddleware( docService docService, publisher webhookPublisher, ) func(http.Handler) http.Handler
EmbedDocumentMiddleware creates documents on /embed access with strict rate limiting This ensures documents exist before the SPA renders, without requiring authentication The docServiceFn should be a function that calls FindOrCreateDocument
func EmbedFolder ¶
func EmbedFolder(fsEmbed embed.FS, targetPath string, baseURL string, version string, signatureRepo SignatureRepository) http.HandlerFunc
EmbedFolder returns an http.HandlerFunc that serves an embedded filesystem with SPA fallback support (serves index.html for non-existent routes). Only BASE_URL and VERSION are injected - other config is loaded via /api/v1/config.
Types ¶
type AuditEvent ¶
type AuditEvent struct {
Timestamp time.Time
TenantID string
UserEmail string
UserSub string
Action string
Resource string
ResourceID string
Details map[string]any
IPAddress string
UserAgent string
}
AuditEvent represents an auditable action in the system.
type AuditLogger ¶
type AuditLogger interface {
// Log records an audit event.
Log(ctx context.Context, event AuditEvent) error
}
AuditLogger defines the interface for audit logging. CE: LogOnlyAuditLogger (logs to standard logger). SaaS: DatabaseAuditLogger (stores in database with search/export).
type AuthProvider ¶
type AuthProvider = providers.AuthProvider
Re-export types from pkg/providers for convenience.
type AuthResult ¶
AuthResult represents the result of an authentication operation.
type Authorizer ¶
type Authorizer = providers.Authorizer
type ConfigProvider ¶
type ConfigProvider interface {
GetConfig() *models.MutableConfig
}
ConfigProvider provides dynamic configuration values.
type CryptoSigner ¶ added in v1.3.9
type CryptoSigner interface {
CreateSignature(ctx context.Context, docID string, user *User, timestamp time.Time, nonce string, docChecksum string) (payloadHash string, signature string, err error)
}
CryptoSigner provides cryptographic signature operations for read confirmations. Implement this interface to override the default Ed25519Signer (e.g., per-tenant keys).
type LogOnlyAuditLogger ¶
type LogOnlyAuditLogger struct{}
LogOnlyAuditLogger logs audit events to the standard logger. This is the default for Community Edition.
func NewLogOnlyAuditLogger ¶
func NewLogOnlyAuditLogger() *LogOnlyAuditLogger
func (*LogOnlyAuditLogger) Log ¶
func (l *LogOnlyAuditLogger) Log(_ context.Context, event AuditEvent) error
type MagicLinkProvider ¶
type MagicLinkProvider = providers.MagicLinkProvider
type MagicLinkResult ¶
type MagicLinkResult = providers.MagicLinkResult
type NoLimitQuotaEnforcer ¶
type NoLimitQuotaEnforcer struct{}
NoLimitQuotaEnforcer is a quota enforcer that imposes no limits. This is the default for Community Edition.
func NewNoLimitQuotaEnforcer ¶
func NewNoLimitQuotaEnforcer() *NoLimitQuotaEnforcer
func (*NoLimitQuotaEnforcer) Check ¶
func (e *NoLimitQuotaEnforcer) Check(_ context.Context, _ string, _ QuotaAction) error
func (*NoLimitQuotaEnforcer) GetUsage ¶
func (e *NoLimitQuotaEnforcer) GetUsage(_ context.Context, tenantID string) (*QuotaUsage, error)
func (*NoLimitQuotaEnforcer) Record ¶
func (e *NoLimitQuotaEnforcer) Record(_ context.Context, _ string, _ QuotaAction) error
type QuotaAction ¶
type QuotaAction string
QuotaAction represents an action that can be quota-limited.
const ( QuotaActionCreateDocument QuotaAction = "document.create" QuotaActionDeleteDocument QuotaAction = "document.delete" QuotaActionCreateSignature QuotaAction = "signature.create" QuotaActionSendReminder QuotaAction = "reminder.send" QuotaActionCreateWebhook QuotaAction = "webhook.create" QuotaActionAddExpectedSigner QuotaAction = "signer.add" QuotaActionWebhookDelivery QuotaAction = "webhook.delivery" )
type QuotaEnforcer ¶
type QuotaEnforcer interface {
// Check verifies if the action is allowed under current quotas.
Check(ctx context.Context, tenantID string, action QuotaAction) error
// Record records that an action was performed.
Record(ctx context.Context, tenantID string, action QuotaAction) error
// GetUsage returns the current usage metrics for a tenant.
GetUsage(ctx context.Context, tenantID string) (*QuotaUsage, error)
}
QuotaEnforcer defines the interface for quota management. CE: NoLimitQuotaEnforcer (no limits). SaaS: PlanBasedQuotaEnforcer (limits based on subscription plan).
type QuotaUsage ¶
type QuotaUsage struct {
TenantID string
Period string // e.g., "2024-01" for monthly quotas
Documents UsageMetric
Signatures UsageMetric
Reminders UsageMetric
Webhooks UsageMetric
}
QuotaUsage represents current usage metrics for a tenant.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func (*Server) ConfigService ¶
func (s *Server) ConfigService() *services.ConfigService
ConfigService returns the internal ConfigService for multi-tenant overrides. In SaaS mode, callers can use Reload(ctx) to refresh config from the DB for the current tenant before reading it.
func (*Server) GetAuditLogger ¶
func (s *Server) GetAuditLogger() AuditLogger
func (*Server) GetAuthProvider ¶
func (s *Server) GetAuthProvider() AuthProvider
func (*Server) GetAuthorizer ¶
func (s *Server) GetAuthorizer() Authorizer
func (*Server) GetEmailSender ¶
func (*Server) GetMagicLinkProvider ¶
func (s *Server) GetMagicLinkProvider() MagicLinkProvider
func (*Server) GetQuotaEnforcer ¶
func (s *Server) GetQuotaEnforcer() QuotaEnforcer
func (*Server) RegisterRoutes ¶
type ServerBuilder ¶
type ServerBuilder struct {
// contains filtered or unexported fields
}
ServerBuilder allows dependency injection for extensibility. DB and TenantProvider are REQUIRED. AuthProvider and Authorizer have sensible CE defaults (AuthProvider, SimpleAuthorizer). QuotaEnforcer and AuditLogger have sensible CE defaults (NoLimit, LogOnly). All technical services (I18n, Email, MagicLink, Reminder, Config) are created internally.
func NewServerBuilder ¶
func (*ServerBuilder) Build ¶
func (b *ServerBuilder) Build(ctx context.Context) (*Server, error)
Build constructs the server with all dependencies.
func (*ServerBuilder) WithAuditLogger ¶
func (b *ServerBuilder) WithAuditLogger(logger AuditLogger) *ServerBuilder
WithAuditLogger injects an audit logger (optional, defaults to LogOnly).
func (*ServerBuilder) WithAuthProvider ¶
func (b *ServerBuilder) WithAuthProvider(provider AuthProvider) *ServerBuilder
WithAuthProvider injects an authentication provider (REQUIRED).
func (*ServerBuilder) WithAuthorizer ¶
func (b *ServerBuilder) WithAuthorizer(authorizer Authorizer) *ServerBuilder
WithAuthorizer injects an authorizer (REQUIRED).
func (*ServerBuilder) WithBaseURLProvider ¶
func (b *ServerBuilder) WithBaseURLProvider(p services.BaseURLProvider) *ServerBuilder
func (*ServerBuilder) WithCryptoSigner ¶ added in v1.3.9
func (b *ServerBuilder) WithCryptoSigner(s CryptoSigner) *ServerBuilder
WithCryptoSigner injects a custom cryptographic signer (optional). When set, the builder skips creating the default Ed25519Signer from env.
func (*ServerBuilder) WithDB ¶
func (b *ServerBuilder) WithDB(db *sql.DB) *ServerBuilder
WithDB injects a database connection (REQUIRED).
func (*ServerBuilder) WithQuotaEnforcer ¶
func (b *ServerBuilder) WithQuotaEnforcer(enforcer QuotaEnforcer) *ServerBuilder
WithQuotaEnforcer injects a quota enforcer (optional, defaults to NoLimit).
func (*ServerBuilder) WithStorageProvider ¶
func (b *ServerBuilder) WithStorageProvider(p storage.Provider) *ServerBuilder
WithStorageProvider injects an external storage provider (optional). When set, the builder will not create its own storage provider from config.
func (*ServerBuilder) WithStorageQuotaChecker ¶
func (b *ServerBuilder) WithStorageQuotaChecker(checker StorageQuotaChecker) *ServerBuilder
WithStorageQuotaChecker injects a storage quota checker (optional).
func (*ServerBuilder) WithTenantProvider ¶
func (b *ServerBuilder) WithTenantProvider(tp providers.TenantProvider) *ServerBuilder
WithTenantProvider injects a tenant provider (REQUIRED).
type SignatureRepository ¶
type SignatureRepository interface {
GetByDoc(ctx context.Context, docID string) ([]*models.Signature, error)
}
SignatureRepository defines minimal signature operations for meta tags
type StorageQuotaChecker ¶
type StorageQuotaChecker interface {
// CheckStorageQuota returns an error if the upload would exceed the storage quota.
CheckStorageQuota(ctx context.Context, tenantID string, fileSize int64) error
}
StorageQuotaChecker verifies storage quota before file upload. CE: nil (no storage quota). SaaS: PlanBasedStorageQuotaChecker (limits based on subscription plan).
type UsageMetric ¶
UsageMetric represents usage for a single resource type.
func (UsageMetric) IsExceeded ¶
func (m UsageMetric) IsExceeded() bool
IsExceeded returns true if usage has exceeded the limit.
func (UsageMetric) IsUnlimited ¶
func (m UsageMetric) IsUnlimited() bool
IsUnlimited returns true if the metric has no limit.
func (UsageMetric) Remaining ¶
func (m UsageMetric) Remaining() int64
Remaining returns the remaining quota, or -1 if unlimited.