Skip to content

Commit

Permalink
ensure rule.TcpStateQualifier is used only with 4.1.2 and later
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismarget-j committed Jan 16, 2024
1 parent aca5310 commit 49f8df4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
7 changes: 7 additions & 0 deletions apstra/compatibility.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ const (

integerPoolForbiddenVersions = "4.1.0, 4.1.1"

policyRuleTcpStateQualifierForbidenVersions = "4.1.0, 4.1.1"
policyRuleTcpStateQualifierForbidenError = "tcp_state_qualifier permitted only with Apstra 4.1.2 and later"

securityZoneJunosEvpnIrbModeRequiredVersions = "4.2.0"
securityZoneJunosEvpnIrbModeRequiredError = "junos_evpn_irb_mode is required by Apstra 4.2 and later"

Expand Down Expand Up @@ -54,6 +57,10 @@ func integerPoolForbidden() StringSliceWithIncludes {
return parseVersionList(integerPoolForbiddenVersions)
}

func policyRuleTcpStateQualifierForbidden() StringSliceWithIncludes {
return parseVersionList(policyRuleTcpStateQualifierForbidenVersions)
}

func securityZoneJunosEvpnIrbModeRequired() StringSliceWithIncludes {
return parseVersionList(securityZoneJunosEvpnIrbModeRequiredVersions)
}
Expand Down
37 changes: 37 additions & 0 deletions apstra/two_stage_l3_clos_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,21 @@ func (o *TwoStageL3ClosClient) GetPolicyByLabel(ctx context.Context, label strin

// CreatePolicy creates a policy within the DC blueprint, returns its ID
func (o *TwoStageL3ClosClient) CreatePolicy(ctx context.Context, data *PolicyData) (ObjectId, error) {
var tcpStateQualifier bool
for _, rule := range data.Rules {
if rule.Data.TcpStateQualifier != nil {
tcpStateQualifier = true
break
}
}

if tcpStateQualifier && policyRuleTcpStateQualifierForbidden().Includes(o.client.apiVersion) {
return "", ClientErr{
errType: ErrCompatibility,
err: errors.New(policyRuleTcpStateQualifierForbidenError),
}
}

return o.createPolicy(ctx, data.request())
}

Expand All @@ -314,6 +329,21 @@ func (o *TwoStageL3ClosClient) DeletePolicy(ctx context.Context, id ObjectId) er

// UpdatePolicy calls PUT to replace the configuration of policy 'id' within the DC blueprint
func (o *TwoStageL3ClosClient) UpdatePolicy(ctx context.Context, id ObjectId, data *PolicyData) error {
var tcpStateQualifier bool
for _, rule := range data.Rules {
if rule.Data.TcpStateQualifier != nil {
tcpStateQualifier = true
break
}
}

if tcpStateQualifier && policyRuleTcpStateQualifierForbidden().Includes(o.client.apiVersion) {
return ClientErr{
errType: ErrCompatibility,
err: errors.New(policyRuleTcpStateQualifierForbidenError),
}
}

return o.updatePolicy(ctx, id, data.request())
}

Expand All @@ -322,6 +352,13 @@ func (o *TwoStageL3ClosClient) UpdatePolicy(ctx context.Context, id ObjectId, da
// on the list, etc... Use -1 for last on the list. The returned ObjectId
// represents the new rule
func (o *TwoStageL3ClosClient) AddPolicyRule(ctx context.Context, rule *PolicyRuleData, position int, policyId ObjectId) (ObjectId, error) {
if rule.TcpStateQualifier != nil && policyRuleTcpStateQualifierForbidden().Includes(o.client.apiVersion) {
return "", ClientErr{
errType: ErrCompatibility,
err: errors.New(policyRuleTcpStateQualifierForbidenError),
}
}

return o.addPolicyRule(ctx, rule.raw(), position, policyId)
}

Expand Down

0 comments on commit 49f8df4

Please sign in to comment.