Skip to content

Commit

Permalink
Added GetInfo() to the Claims interface to aid consumers with a way o…
Browse files Browse the repository at this point in the history
…f extracting the Info
  • Loading branch information
aricart committed Jan 27, 2020
1 parent ddd1bb0 commit faaa062
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 9 deletions.
6 changes: 5 additions & 1 deletion account_claims.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
6 changes: 5 additions & 1 deletion activation_claims.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -165,3 +165,7 @@ func cleanSubject(subject string) string {
}
return cleaned
}

func (a *ActivationClaims) GetInfo() *Info {
return &a.Activation.Info
}
5 changes: 3 additions & 2 deletions claims.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"`
}
Expand Down
6 changes: 5 additions & 1 deletion cluster_claims.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
6 changes: 5 additions & 1 deletion genericlaims.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down Expand Up @@ -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
}
6 changes: 5 additions & 1 deletion operator_claims.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
6 changes: 5 additions & 1 deletion server_claims.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
6 changes: 5 additions & 1 deletion user_claims.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

0 comments on commit faaa062

Please sign in to comment.