Skip to content

Commit

Permalink
Upgrade go client. (#2430)
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-edmonds-dd authored Jun 10, 2024
1 parent 61f3746 commit 8552cf3
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 4 deletions.
59 changes: 58 additions & 1 deletion datadog/resource_datadog_security_monitoring_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,21 @@ func buildCreatePayload(d utils.Resource) (*datadogV2.SecurityMonitoringRuleCrea
return &createPayload, err
}

func buildValidatePayload(d utils.Resource) (*datadogV2.SecurityMonitoringRuleValidatePayload, error) {

if err := checkQueryConsistency(d); err != nil {
return &datadogV2.SecurityMonitoringRuleValidatePayload{}, err
}
if isSignalCorrelationSchema(d) {
payload, err := buildSignalPayload(d)
createPayload := datadogV2.SecurityMonitoringSignalRulePayloadAsSecurityMonitoringRuleValidatePayload(payload)
return &createPayload, err
}
payload, err := buildStandardPayload(d)
createPayload := datadogV2.SecurityMonitoringStandardRulePayloadAsSecurityMonitoringRuleValidatePayload(payload)
return &createPayload, err
}

func buildCreateCommonPayload(d utils.Resource, payload securityMonitoringRuleCreateInterface) {
payload.SetIsEnabled(d.Get("enabled").(bool))
payload.SetMessage(d.Get("message").(string))
Expand Down Expand Up @@ -627,6 +642,27 @@ func buildCreateStandardPayload(d utils.Resource) (*datadogV2.SecurityMonitoring
return &payload, nil
}

func buildStandardPayload(d utils.Resource) (*datadogV2.SecurityMonitoringStandardRulePayload, error) {
payload := datadogV2.SecurityMonitoringStandardRulePayload{}
buildCreateCommonPayload(d, &payload)

if isThirdPartyRule(d) {
payload.SetThirdPartyCases(buildPayloadThirdPartyCases(d))
} else {
payload.SetCases(buildCreatePayloadCases(d))
payload.SetQueries(buildCreateStandardPayloadQueries(d))
}

if v, ok := d.GetOk("type"); ok {
if ruleType, err := datadogV2.NewSecurityMonitoringRuleTypeCreateFromValue(v.(string)); err == nil {
payload.SetType(*ruleType)
} else {
return &payload, err
}
}
return &payload, nil
}

func buildCreateSignalPayload(d utils.Resource) (*datadogV2.SecurityMonitoringSignalRuleCreatePayload, error) {
payload := datadogV2.SecurityMonitoringSignalRuleCreatePayload{}
buildCreateCommonPayload(d, &payload)
Expand All @@ -648,6 +684,27 @@ func buildCreateSignalPayload(d utils.Resource) (*datadogV2.SecurityMonitoringSi
return &payload, nil
}

func buildSignalPayload(d utils.Resource) (*datadogV2.SecurityMonitoringSignalRulePayload, error) {
payload := datadogV2.SecurityMonitoringSignalRulePayload{}
buildCreateCommonPayload(d, &payload)
payload.SetCases(buildCreatePayloadCases(d))
if queries, err := buildCreateSignalPayloadQueries(d); err == nil {
payload.SetQueries(queries)
} else {
return &payload, err
}

if v, ok := d.GetOk("type"); ok {
if ruleType, err := datadogV2.NewSecurityMonitoringSignalRuleTypeFromValue(v.(string)); err == nil {
payload.SetType(*ruleType)
} else {
return &payload, err
}
}

return &payload, nil
}

func buildCreatePayloadCases(d utils.Resource) []datadogV2.SecurityMonitoringRuleCaseCreate {
tfCases := d.Get("case").([]interface{})
payloadCases := make([]datadogV2.SecurityMonitoringRuleCaseCreate, len(tfCases))
Expand Down Expand Up @@ -1458,7 +1515,7 @@ func resourceDatadogSecurityMonitoringRuleCustomizeDiff(ctx context.Context, dif
apiInstances := providerConf.DatadogApiInstances
auth := providerConf.Auth

if payload, err := buildCreatePayload(diff); err == nil {
if payload, err := buildValidatePayload(diff); err == nil {
if httpResponse, err := apiInstances.GetSecurityMonitoringApiV2().ValidateSecurityMonitoringRule(auth, *payload); err != nil || httpResponse == nil {
return utils.TranslateClientError(err, httpResponse, "error validating security monitoring rule")
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module github.com/terraform-providers/terraform-provider-datadog

require (
github.com/DataDog/datadog-api-client-go/v2 v2.26.0
github.com/DataDog/datadog-api-client-go/v2 v2.26.1-0.20240607153051-dcbfc17c9179
github.com/DataDog/dd-sdk-go-testing v0.0.0-20211116174033-1cd082e322ad
github.com/google/uuid v1.5.0
github.com/hashicorp/go-cleanhttp v0.5.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/DataDog/datadog-api-client-go/v2 v2.26.0 h1:bZr0hu+hx8L91+yU5EGw8wK3FlCVEIashpx+cylWsf0=
github.com/DataDog/datadog-api-client-go/v2 v2.26.0/go.mod h1:QKOu6vscsh87fMY1lHfLEmNSunyXImj8BUaUWJXOehc=
github.com/DataDog/datadog-api-client-go/v2 v2.26.1-0.20240607153051-dcbfc17c9179 h1:1JhH7F3V89jun91SgR0LwpR+ExyML4lOgG5zb4ggo/I=
github.com/DataDog/datadog-api-client-go/v2 v2.26.1-0.20240607153051-dcbfc17c9179/go.mod h1:QKOu6vscsh87fMY1lHfLEmNSunyXImj8BUaUWJXOehc=
github.com/DataDog/datadog-go v4.4.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/DataDog/datadog-go v4.8.3+incompatible h1:fNGaYSuObuQb5nzeTQqowRAd9bpDIRRV4/gUtIBjh8Q=
github.com/DataDog/datadog-go v4.8.3+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
Expand Down

0 comments on commit 8552cf3

Please sign in to comment.