package buscompose import "slices" // **The lease write's grants** (novox/hq ADR 0582 clause 3, issue 774). Composed with Records.LeaseCut, the list takes // from the controller its write of the lease's key and every update, purge and delete of the lease's bucket, and gives // the grants part the key `holder`, which it creates naming itself and deletes at a hand-back (clause 5). Whatever the // records, the bus module's tools account may read and update the lease's bucket, for the tool that removes and // restores its expiry; no other bucket's. // leaseStream is the lease bucket's stream. var leaseStream = "KV_" + LeaseBucket // LeaseHolderWrite is the grants part's write of the lease's one key, from the cut. func LeaseHolderWrite() string { return "$KV." + LeaseBucket + "." + leaseKey } // LeaseCutDenied are the controller's subjects of the lease's bucket that its `$JS.API.>` reaches and the cut refuses: // the bucket's update (its expiry), purge and delete, and a message's delete (the key's last value). func LeaseCutDenied() []string { return []string{"$JS.API.STREAM.UPDATE." + leaseStream, "$JS.API.STREAM.PURGE." + leaseStream, "$JS.API.STREAM.DELETE." + leaseStream, "$JS.API.STREAM.MSG.DELETE." + leaseStream} } // LeaseExpiryGrants are the bus module's tools account's read and update of the lease's bucket, for its expiry. func LeaseExpiryGrants() []string { return []string{"$JS.API.STREAM.INFO." + leaseStream, "$JS.API.STREAM.UPDATE." + leaseStream} } // writesTheLease is the controller holding the lease, or, from the cut, the grants part writing its key holder alone. func writesTheLease(p Principal, pattern string) bool { if p.Kind == KindController { return true } return p.Kind == KindModule && p.Module == GrantsModule && p.LeaseCut && pattern == LeaseHolderWrite() } // setsLeaseExpiry is the bus module's tools account updating the lease's bucket: the writers table's one exemption from // stream definitions being the controller's beside ASSIGNMENTS' removal (ADR 0582 clause 3). func setsLeaseExpiry(p Principal, pattern string) bool { return p.Kind == KindProcess && len(p.Removes) > 0 && slices.Contains(LeaseExpiryGrants(), pattern) }