Skip to content

Commit

Permalink
Added container for message trace options
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Kozlovic <[email protected]>
  • Loading branch information
kozlovic committed Feb 15, 2024
1 parent 40f01dc commit 5312ad7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
17 changes: 11 additions & 6 deletions v2/account_claims.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,16 @@ type Account struct {
DefaultPermissions Permissions `json:"default_permissions,omitempty"`
Mappings Mapping `json:"mappings,omitempty"`
Authorization ExternalAuthorization `json:"authorization,omitempty"`
TraceDest Subject `json:"trace_dest,omitempty"`
Trace *MsgTrace `json:"trace,omitempty"`
Info
GenericFields
}

// MsgTrace holds distributed message tracing configuration
type MsgTrace struct {
Destination Subject `json:"dest,omitempty"`
}

// Validate checks if the account is valid, based on the wrapper
func (a *Account) Validate(acct *AccountClaims, vr *ValidationResults) {
a.Imports.Validate(acct.Subject, vr)
Expand All @@ -243,14 +248,14 @@ func (a *Account) Validate(acct *AccountClaims, vr *ValidationResults) {
a.DefaultPermissions.Validate(vr)
a.Mappings.Validate(vr)
a.Authorization.Validate(vr)
if a.TraceDest != "" {
if a.Trace != nil {
tvr := CreateValidationResults()
a.TraceDest.Validate(tvr)
a.Trace.Destination.Validate(tvr)
if !tvr.IsEmpty() {
vr.AddError(fmt.Sprintf("the account TraceDest %s", tvr.Issues[0].Description))
vr.AddError(fmt.Sprintf("the account Trace.Destination %s", tvr.Issues[0].Description))
}
if a.TraceDest.HasWildCards() {
vr.AddError("the account TraceDest subject %q is not a valid publish subject", a.TraceDest)
if a.Trace.Destination.HasWildCards() {
vr.AddError("the account Trace.Destination subject %q is not a valid publish subject", a.Trace.Destination)
}
}

Expand Down
7 changes: 5 additions & 2 deletions v2/account_claims_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -882,20 +882,23 @@ func TestAccountClaimsTraceDest(t *testing.T) {
apk := publicKey(akp, t)

account := NewAccountClaims(apk)
for _, test := range []struct {
for i, test := range []struct {
name string
invalidSubj Subject
expectErr bool
}{
{"trace not specified", "", false},
{"trace created but with empty destination", "", true},
{"trace dest has spaces", "invalid dest", true},
{"trace dest start with a dot", ".invalid.dest", true},
{"trace dest ends with a dot", "invalid.dest.", true},
{"trace dest has consecutive dots", "invalid..dest", true},
{"trace dest invalid publish dest", "invalid.publish.*.dest", true},
} {
t.Run(test.name, func(t *testing.T) {
account.TraceDest = test.invalidSubj
if i > 0 {
account.Trace = &MsgTrace{Destination: test.invalidSubj}
}
vr := CreateValidationResults()
account.Validate(vr)

Expand Down

0 comments on commit 5312ad7

Please sign in to comment.