clone

a self-hosted multitenant nostr relay with sites, file storage, git hosting, and inbox and outbox delivery

add file storage allowances to tenant policy

Dami committed 0aca966
commit
0aca966a569138bd3e705a7f9931fa95a1a348f3
parent
3b648ecfc76b2d06f78f37d22375dbcf5834813f
author
Dami <dami.etoile@gmail.com>
4 files changed, +63 -2
Minternal/configport/configport.go2+-
Ainternal/configport/file_limits_test.go24++++++++++++++++++++++++
Ainternal/policy/file_limits_test.go27+++++++++++++++++++++++++++
Minternal/policy/policy.go12+++++++++++-
M internal/configport/configport.go +1 -1
A internal/configport/file_limits_test.go +24 -0
A internal/policy/file_limits_test.go +27 -0
M internal/policy/policy.go +11 -1
@@ -62,6 +62,12 @@ type Inbox struct {
6262 Targeted bool `json:"targeted"`6363 }6464 65+// FileLimits controls a tenant's file storage allowances. Zero is unlimited.66+type FileLimits struct {67+ MaxFileBytes int64 `json:"maxFileBytes"`68+ UserStorageBytes int64 `json:"userStorageBytes"`69+}70+6571 type CustomHost struct {6672 Host string `json:"host"`6773 ID string `json:"id"`
@@ -109,6 +115,7 @@ type Policy struct {
109115 Features Features `json:"features"`110116 PushCallbacks []string `json:"pushCallbacks"`111117 PrivatePeers []string `json:"privatePeers,omitempty"`118+ FileLimits FileLimits `json:"fileLimits"`112119 LetteredNips bool `json:"letteredNips"`113120 Delivery Delivery `json:"delivery"`114121 Inbox Inbox `json:"inbox"`
@@ -126,6 +133,9 @@ func Defaults(owner string) Policy {
126133 }127134 128135 func Validate(p Policy) error {136+ if p.FileLimits.MaxFileBytes < 0 || p.FileLimits.UserStorageBytes < 0 {137+ return errors.New("fileLimits: byte allowances cannot be negative")138+ }129139 if p.Writes != "open" && p.Writes != "allowlist" && p.Writes != "wot" && p.Writes != "owner" {130140 return fmt.Errorf("writes: invalid rule %q", p.Writes)131141 }
@@ -203,7 +213,7 @@ func Patch(cur Policy, raw map[string]json.RawMessage) (Policy, error) {
203213 if _, ok := merged[key]; !ok {204214 continue205215 }206- if key == "features" || key == "notify" || key == "memberInvites" || key == "delivery" || key == "inbox" {216+ if key == "features" || key == "notify" || key == "memberInvites" || key == "delivery" || key == "inbox" || key == "fileLimits" {207217 var patchMap, currentMap map[string]json.RawMessage208218 if json.Unmarshal(value, &patchMap) == nil && json.Unmarshal(merged[key], &currentMap) == nil {209219 if key == "features" {