Skip to content

Commit

Permalink
[FEATURE] Adding support for js max bytes required (#164)
Browse files Browse the repository at this point in the history
* [FEATURE] Adding support for js max bytes required

Signed-off-by: Matthias Hanel <mh@synadia.com>
  • Loading branch information
matthiashanel committed Jan 13, 2022
1 parent b87bc9c commit 58e8789
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
13 changes: 7 additions & 6 deletions v2/account_claims.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,16 @@ func (n *NatsLimits) IsUnlimited() bool {
}

type JetStreamLimits struct {
MemoryStorage int64 `json:"mem_storage,omitempty"` // Max number of bytes stored in memory across all streams. (0 means disabled)
DiskStorage int64 `json:"disk_storage,omitempty"` // Max number of bytes stored on disk across all streams. (0 means disabled)
Streams int64 `json:"streams,omitempty"` // Max number of streams
Consumer int64 `json:"consumer,omitempty"` // Max number of consumer
MemoryStorage int64 `json:"mem_storage,omitempty"` // Max number of bytes stored in memory across all streams. (0 means disabled)
DiskStorage int64 `json:"disk_storage,omitempty"` // Max number of bytes stored on disk across all streams. (0 means disabled)
Streams int64 `json:"streams,omitempty"` // Max number of streams
Consumer int64 `json:"consumer,omitempty"` // Max number of consumers
MaxBytesRequired bool `json:"max_bytes_required,omitempty"` // Max bytes required by all Streams
}

// IsUnlimited returns true if all limits are unlimited
func (j *JetStreamLimits) IsUnlimited() bool {
return *j == JetStreamLimits{NoLimit, NoLimit, NoLimit, NoLimit}
return *j == JetStreamLimits{NoLimit, NoLimit, NoLimit, NoLimit, false}
}

// OperatorLimits are used to limit access by an account
Expand Down Expand Up @@ -188,7 +189,7 @@ func NewAccountClaims(subject string) *AccountClaims {
c.Limits = OperatorLimits{
NatsLimits{NoLimit, NoLimit, NoLimit},
AccountLimits{NoLimit, NoLimit, true, NoLimit, NoLimit},
JetStreamLimits{0, 0, 0, 0}}
JetStreamLimits{0, 0, 0, 0, false}}
c.Subject = subject
c.Mappings = Mapping{}
return c
Expand Down
4 changes: 3 additions & 1 deletion v2/account_claims_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,15 @@ func TestJetstreamLimits(t *testing.T) {
if acc1.Limits.JetStreamLimits.DiskStorage != 0 ||
acc1.Limits.JetStreamLimits.MemoryStorage != 0 ||
acc1.Limits.JetStreamLimits.Consumer != 0 ||
acc1.Limits.JetStreamLimits.Streams != 0 {
acc1.Limits.JetStreamLimits.Streams != 0 ||
acc1.Limits.JetStreamLimits.MaxBytesRequired != false {
t.Fatalf("Expected unlimited operator limits")
}
acc1.Limits.Consumer = 1
acc1.Limits.Streams = 2
acc1.Limits.MemoryStorage = 3
acc1.Limits.DiskStorage = 4
acc1.Limits.MaxBytesRequired = true
vr := CreateValidationResults()
acc1.Validate(vr)
if !vr.IsEmpty() {
Expand Down
2 changes: 1 addition & 1 deletion v2/decoder_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (oa v1AccountClaims) migrateV1() (*AccountClaims, error) {
a.Account.Exports = oa.v1NatsAccount.Exports
a.Account.Limits.AccountLimits = oa.v1NatsAccount.Limits.AccountLimits
a.Account.Limits.NatsLimits = oa.v1NatsAccount.Limits.NatsLimits
a.Account.Limits.JetStreamLimits = JetStreamLimits{0, 0, 0, 0}
a.Account.Limits.JetStreamLimits = JetStreamLimits{0, 0, 0, 0, false}
a.Account.SigningKeys = make(SigningKeys)
for _, v := range oa.SigningKeys {
a.Account.SigningKeys.Add(v)
Expand Down

0 comments on commit 58e8789

Please sign in to comment.