Skip to content

Commit

Permalink
fix nil pointer deref, eliminate PolicyApplicationPointData.ObjectId()
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismarget-j committed Jan 12, 2024
1 parent 53726c5 commit 01c2fc1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
16 changes: 10 additions & 6 deletions apstra/two_stage_l3_clos_policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ type PolicyData struct {
}

func (o PolicyData) request() *policyRequest {
var srcApplicationPoint, dstApplicationPoint ObjectId
if o.SrcApplicationPoint != nil {
srcApplicationPoint = o.SrcApplicationPoint.Id
}
if o.DstApplicationPoint != nil {
dstApplicationPoint = o.DstApplicationPoint.Id
}

rules := make([]rawPolicyRule, len(o.Rules))
for i, rule := range o.Rules {
rules[i] = *rule.Data.raw()
Expand All @@ -53,8 +61,8 @@ func (o PolicyData) request() *policyRequest {
Enabled: o.Enabled,
Label: o.Label,
Description: o.Description,
SrcApplicationPoint: o.SrcApplicationPoint.ObjectId(),
DstApplicationPoint: o.DstApplicationPoint.ObjectId(),
SrcApplicationPoint: srcApplicationPoint,
DstApplicationPoint: dstApplicationPoint,
Rules: rules,
Tags: o.Tags,
}
Expand Down Expand Up @@ -122,10 +130,6 @@ type PolicyApplicationPointData struct {
Type string `json:"type"` // group, internal, external, security_zone, virtual_network
}

func (o PolicyApplicationPointData) ObjectId() ObjectId {
return o.Id
}

func (o *TwoStageL3ClosClient) getAllPolicies(ctx context.Context) ([]rawPolicy, error) {
response := &struct {
Policies []rawPolicy `json:"policies"`
Expand Down
8 changes: 4 additions & 4 deletions apstra/two_stage_l3_clos_policies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,12 @@ func comparePolicyData(a *PolicyData, aName string, b *PolicyData, bName string,
t.Fatalf("Policy Descriptions don't match: %s has %q, %s has %q", aName, a.Description, bName, b.Description)
}

if a.SrcApplicationPoint.ObjectId() != b.SrcApplicationPoint.ObjectId() {
t.Fatalf("Policy SrcApplicationPoints don't match: %s has %q, %s has %q", aName, a.SrcApplicationPoint.ObjectId(), bName, b.SrcApplicationPoint.ObjectId())
if a.SrcApplicationPoint.Id != b.SrcApplicationPoint.Id {
t.Fatalf("Policy SrcApplicationPoints don't match: %s has %q, %s has %q", aName, a.SrcApplicationPoint.Id, bName, b.SrcApplicationPoint.Id)
}

if a.DstApplicationPoint.ObjectId() != b.DstApplicationPoint.ObjectId() {
t.Fatalf("Policy DstApplicationPoints don't match: %s has %q, %s has %q", aName, a.DstApplicationPoint.ObjectId(), bName, b.DstApplicationPoint.ObjectId())
if a.DstApplicationPoint.Id != b.DstApplicationPoint.Id {
t.Fatalf("Policy DstApplicationPoints don't match: %s has %q, %s has %q", aName, a.DstApplicationPoint.Id, bName, b.DstApplicationPoint.Id)
}

compareSlicesAsSets(t, a.Tags, b.Tags, fmt.Sprintf("%s tags: %v, %s tags %v", aName, a.Tags, bName, b.Tags))
Expand Down

0 comments on commit 01c2fc1

Please sign in to comment.