From 97c38270d812c20471e5c8cb4dd7257821085035 Mon Sep 17 00:00:00 2001 From: Alberto Ricart Date: Tue, 7 Nov 2023 17:23:48 -0600 Subject: [PATCH] [FIX] added set expiry to operators and accounts FIX #6 --- accounts.go | 9 +++++++++ operator.go | 14 +++++++++++--- types.go | 12 ++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/accounts.go b/accounts.go index 97352d7..4193cbd 100644 --- a/accounts.go +++ b/accounts.go @@ -48,6 +48,15 @@ func (a *AccountData) update() error { return a.issue(key) } +func (a *AccountData) SetExpiry(exp int64) error { + a.Claim.Expires = exp + return a.update() +} + +func (a *AccountData) Expiry() int64 { + return a.Claim.Expires +} + func (a *AccountData) Users() Users { return &UsersImpl{accountData: a} } diff --git a/operator.go b/operator.go index d8f55b2..5e29814 100644 --- a/operator.go +++ b/operator.go @@ -1,12 +1,11 @@ package authb import ( + "encoding/json" + "errors" "github.com/nats-io/jwt/v2" "github.com/nats-io/nkeys" "github.com/nats-io/nsc/v2/cmd" - - "encoding/json" - "errors" ) func (o *OperatorData) String() string { @@ -44,6 +43,15 @@ func (o *OperatorData) SetOperatorServiceURL(url ...string) error { return o.update() } +func (o *OperatorData) SetExpiry(exp int64) error { + o.Claim.Expires = exp + return o.update() +} + +func (o *OperatorData) Expiry() int64 { + return o.Claim.Expires +} + func (o *OperatorData) OperatorServiceURLs() []string { return o.Claim.OperatorServiceURLs } diff --git a/types.go b/types.go index af67819..e162513 100644 --- a/types.go +++ b/types.go @@ -125,6 +125,12 @@ type Operator interface { SetSystemAccount(account Account) error // MemResolver generates a mem resolver server configuration MemResolver() ([]byte, error) + // SetExpiry sets the expiry for the operator in Unix Time Seconds. + // 0 never expires. + SetExpiry(exp int64) error + // Expiry returns the expiry for the operator in Unix Time Seconds. + // 0 never expires + Expiry() int64 } // Accounts is an interface for managing accounts @@ -157,6 +163,12 @@ type Account interface { Exports() Exports // Limits returns an interface for managing account limits Limits() AccountLimits + // SetExpiry sets the expiry for the account in Unix Time Seconds. + // 0 never expires. + SetExpiry(exp int64) error + // Expiry returns the expiry for the account in Unix Time Seconds. + // 0 never expires + Expiry() int64 } // Users is an interface for managing users