mirror of
https://github.com/J3vb/OwnCord.git
synced 2026-09-03 03:50:00 +03:00
golangci-lint had been failing invisibly behind the earlier CI gate failures. Default-build lint is now clean: - Delete the unused pre-topic-limiter rate-limit constants, the unused bluemonday sanitizer, and the dead broadcast variants superseded by their Low/High counterparts (broadcastExclude, broadcastToDMParticipants(+Exclude), sendSequencedToUsers, PubSub.debugDump). Test references were comments only; updated to name the live variants. - Separate 'Phase X Step Y' file headers from the package clause with a blank line so staticcheck ST1000 no longer reads them as malformed package comments (proper package docs exist in hub.go/manifest.go). - Add .gitattributes normalizing line endings to LF on checkout — the Windows CI runner materialized CRLF, which made every prettier-formatted file fail the format gate. Known remainder (pre-existing, out of P0 scope): golangci-lint with -tags wazero reports 3 gosec + 2 staticcheck and -tags otel 1+1; CI lints the default build. Tracked for the P1 plugin pass. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
56 lines
1.8 KiB
Go
56 lines
1.8 KiB
Go
// Phase C Step 9 — `storage` host capability.
|
|
//
|
|
// Plugins get a per-plugin namespaced KV store backed by the PluginStore
|
|
// rows in the events/plugin schema. Capacity caps and value-size caps are
|
|
// enforced here so a misbehaving plugin can't fill the database.
|
|
|
|
package plugin
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
)
|
|
|
|
const (
|
|
maxPluginValueBytes = 64 * 1024 // 64 KB per value
|
|
maxPluginScanLimit = 1000 // hard cap on PluginKVScan results
|
|
)
|
|
|
|
// StoragePut writes a single key/value pair on behalf of inst.
|
|
func (r *Registry) StoragePut(ctx context.Context, inst *Instance, key string, value []byte) error {
|
|
if !inst.Manifest.HasCapability(CapStorage) {
|
|
return ErrCapabilityNotGranted
|
|
}
|
|
if len(value) > maxPluginValueBytes {
|
|
return fmt.Errorf("plugin storage: value exceeds %d bytes", maxPluginValueBytes)
|
|
}
|
|
return r.cfg.Store.PluginKVSet(ctx, inst.ID, key, value)
|
|
}
|
|
|
|
// StorageGet returns the value for key, or (nil, error) when missing.
|
|
func (r *Registry) StorageGet(ctx context.Context, inst *Instance, key string) ([]byte, error) {
|
|
if !inst.Manifest.HasCapability(CapStorage) {
|
|
return nil, ErrCapabilityNotGranted
|
|
}
|
|
return r.cfg.Store.PluginKVGet(ctx, inst.ID, key)
|
|
}
|
|
|
|
// StorageDelete removes a key.
|
|
func (r *Registry) StorageDelete(ctx context.Context, inst *Instance, key string) error {
|
|
if !inst.Manifest.HasCapability(CapStorage) {
|
|
return ErrCapabilityNotGranted
|
|
}
|
|
return r.cfg.Store.PluginKVDelete(ctx, inst.ID, key)
|
|
}
|
|
|
|
// StorageScan returns all keys with the given prefix, capped at maxPluginScanLimit.
|
|
func (r *Registry) StorageScan(ctx context.Context, inst *Instance, prefix string, limit int) (map[string][]byte, error) {
|
|
if !inst.Manifest.HasCapability(CapStorage) {
|
|
return nil, ErrCapabilityNotGranted
|
|
}
|
|
if limit <= 0 || limit > maxPluginScanLimit {
|
|
limit = maxPluginScanLimit
|
|
}
|
|
return r.cfg.Store.PluginKVScan(ctx, inst.ID, prefix, limit)
|
|
}
|