From faaa0626b9d8a8aa1aa72058f925bbe7db3777d8 Mon Sep 17 00:00:00 2001 From: aricart Date: Mon, 27 Jan 2020 13:28:35 -0400 Subject: [PATCH] Added GetInfo() to the Claims interface to aid consumers with a way of extracting the Info --- account_claims.go | 6 +++++- activation_claims.go | 6 +++++- claims.go | 5 +++-- cluster_claims.go | 6 +++++- genericlaims.go | 6 +++++- operator_claims.go | 6 +++++- server_claims.go | 6 +++++- user_claims.go | 6 +++++- 8 files changed, 38 insertions(+), 9 deletions(-) diff --git a/account_claims.go b/account_claims.go index dd75188..f6bf5c7 100644 --- a/account_claims.go +++ b/account_claims.go @@ -61,7 +61,7 @@ type Account struct { Limits OperatorLimits `json:"limits,omitempty"` SigningKeys StringList `json:"signing_keys,omitempty"` Revocations RevocationList `json:"revocations,omitempty"` - NatsStandard + Info } // Validate checks if the account is valid, based on the wrapper @@ -221,3 +221,7 @@ func (a *AccountClaims) IsRevokedAt(pubKey string, timestamp time.Time) bool { func (a *AccountClaims) IsRevoked(pubKey string) bool { return a.Revocations.IsRevoked(pubKey, time.Now()) } + +func (a *AccountClaims) GetInfo() *Info { + return &a.Account.Info +} diff --git a/activation_claims.go b/activation_claims.go index a171942..cf0e515 100644 --- a/activation_claims.go +++ b/activation_claims.go @@ -30,7 +30,7 @@ type Activation struct { ImportSubject Subject `json:"subject,omitempty"` ImportType ExportType `json:"type,omitempty"` Limits - NatsStandard + Info } // IsService returns true if an Activation is for a service @@ -165,3 +165,7 @@ func cleanSubject(subject string) string { } return cleaned } + +func (a *ActivationClaims) GetInfo() *Info { + return &a.Activation.Info +} diff --git a/claims.go b/claims.go index 7238f5c..3b602c7 100644 --- a/claims.go +++ b/claims.go @@ -52,6 +52,7 @@ type Claims interface { Encode(kp nkeys.KeyPair) (string, error) ExpectedPrefixes() []nkeys.PrefixByte Payload() interface{} + GetInfo() *Info String() string Validate(vr *ValidationResults) Verify(payload string, sig []byte) bool @@ -69,8 +70,8 @@ type ClaimsData struct { Subject string `json:"sub,omitempty"` } -// NatsStandard contains fields shared by all NATS JWTs -type NatsStandard struct { +// Info contains fields shared by all NATS JWTs +type Info struct { Tags TagList `json:"tags,omitempty"` Type ClaimType `json:"type,omitempty"` } diff --git a/cluster_claims.go b/cluster_claims.go index 0706185..7ff20b5 100644 --- a/cluster_claims.go +++ b/cluster_claims.go @@ -27,7 +27,7 @@ type Cluster struct { Accounts []string `json:"accts,omitempty"` AccountURL string `json:"accturl,omitempty"` OperatorURL string `json:"opurl,omitempty"` - NatsStandard + Info } // Validate checks the cluster and permissions for a cluster JWT @@ -93,3 +93,7 @@ func (c *ClusterClaims) ExpectedPrefixes() []nkeys.PrefixByte { func (c *ClusterClaims) Claims() *ClaimsData { return &c.ClaimsData } + +func (c *ClusterClaims) GetInfo() *Info { + return &c.Cluster.Info +} diff --git a/genericlaims.go b/genericlaims.go index 0d1295f..fb8847d 100644 --- a/genericlaims.go +++ b/genericlaims.go @@ -20,7 +20,7 @@ import "github.com/nats-io/nkeys" // GenericClaims can be used to read a JWT as a map for any non-generic fields type GenericClaims struct { ClaimsData - NatsStandard + Info Data map[string]interface{} `json:"nats,omitempty"` } @@ -81,3 +81,7 @@ func (gc *GenericClaims) String() string { func (gc *GenericClaims) ExpectedPrefixes() []nkeys.PrefixByte { return nil } + +func (gc *GenericClaims) GetInfo() *Info { + return &gc.Info +} diff --git a/operator_claims.go b/operator_claims.go index e54f26f..b992718 100644 --- a/operator_claims.go +++ b/operator_claims.go @@ -26,7 +26,7 @@ import ( // Operator specific claims type Operator struct { - NatsStandard + Info // Slice of real identies (like websites) that can be used to identify the operator. Identities []Identity `json:"identity,omitempty"` // Slice of other operator NKeys that can be used to sign on behalf of the main @@ -203,3 +203,7 @@ func (oc *OperatorClaims) ExpectedPrefixes() []nkeys.PrefixByte { func (oc *OperatorClaims) Claims() *ClaimsData { return &oc.ClaimsData } + +func (oc *OperatorClaims) GetInfo() *Info { + return &oc.Info +} diff --git a/server_claims.go b/server_claims.go index 9e1eb24..38546c2 100644 --- a/server_claims.go +++ b/server_claims.go @@ -25,7 +25,7 @@ import ( type Server struct { Permissions Cluster string `json:"cluster,omitempty"` - NatsStandard + Info } // Validate checks the cluster and permissions for a server JWT @@ -93,3 +93,7 @@ func (s *ServerClaims) ExpectedPrefixes() []nkeys.PrefixByte { func (s *ServerClaims) Claims() *ClaimsData { return &s.ClaimsData } + +func (s *ServerClaims) GetInfo() *Info { + return &s.Server.Info +} diff --git a/user_claims.go b/user_claims.go index a889667..98a37e0 100644 --- a/user_claims.go +++ b/user_claims.go @@ -26,7 +26,7 @@ type User struct { Permissions Limits BearerToken bool `json:"bearer_token,omitempty"` - NatsStandard + Info } // Validate checks the permissions and limits in a User jwt @@ -105,3 +105,7 @@ func (u *UserClaims) String() string { func (u *UserClaims) IsBearerToken() bool { return u.BearerToken } + +func (u *UserClaims) GetInfo() *Info { + return &u.User.Info +}