Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sentinel - removing setting etag before updating it #16428

Merged
merged 1 commit into from
Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ func resourceSentinelAlertRuleFusionCreateUpdate(d *pluginsdk.ResourceData, meta
},
}

// Service avoid concurrent update of this resource via checking the "etag" to guarantee it is the same value as last Read.
if !d.IsNewResource() {
resp, err := client.Get(ctx, workspaceID.ResourceGroup, workspaceID.WorkspaceName, name)
if err != nil {
Expand All @@ -112,7 +111,6 @@ func resourceSentinelAlertRuleFusionCreateUpdate(d *pluginsdk.ResourceData, meta
if err := assertAlertRuleKind(resp.Value, securityinsight.AlertRuleKindFusion); err != nil {
return fmt.Errorf("asserting alert rule of %q: %+v", id, err)
}
params.Etag = resp.Value.(securityinsight.FusionAlertRule).Etag
}

if _, err := client.CreateOrUpdate(ctx, workspaceID.ResourceGroup, workspaceID.WorkspaceName, name, params); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ func resourceSentinelAlertRuleMLBehaviorAnalyticsCreateUpdate(d *pluginsdk.Resou
},
}

// Service avoid concurrent update of this resource via checking the "etag" to guarantee it is the same value as last Read.
if !d.IsNewResource() {
resp, err := client.Get(ctx, workspaceID.ResourceGroup, workspaceID.WorkspaceName, name)
if err != nil {
Expand All @@ -112,7 +111,6 @@ func resourceSentinelAlertRuleMLBehaviorAnalyticsCreateUpdate(d *pluginsdk.Resou
if err := assertAlertRuleKind(resp.Value, securityinsight.AlertRuleKindMLBehaviorAnalytics); err != nil {
return fmt.Errorf("asserting alert rule of %q: %+v", id, err)
}
params.Etag = resp.Value.(securityinsight.MLBehaviorAnalyticsAlertRule).Etag
}

if _, err := client.CreateOrUpdate(ctx, workspaceID.ResourceGroup, workspaceID.WorkspaceName, name, params); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ func resourceSentinelAlertRuleMsSecurityIncidentCreateUpdate(d *pluginsdk.Resour
param.DisplayNamesExcludeFilter = utils.ExpandStringSlice(v.(*pluginsdk.Set).List())
}

// Service avoid concurrent update of this resource via checking the "etag" to guarantee it is the same value as last Read.
if !d.IsNewResource() {
resp, err := client.Get(ctx, workspaceID.ResourceGroup, workspaceID.WorkspaceName, name)
if err != nil {
Expand All @@ -188,7 +187,6 @@ func resourceSentinelAlertRuleMsSecurityIncidentCreateUpdate(d *pluginsdk.Resour
if err := assertAlertRuleKind(resp.Value, securityinsight.AlertRuleKindMicrosoftSecurityIncidentCreation); err != nil {
return fmt.Errorf("asserting alert rule of %q: %+v", id, err)
}
param.Etag = resp.Value.(securityinsight.MicrosoftSecurityIncidentCreationAlertRule).Etag
}

if _, err := client.CreateOrUpdate(ctx, workspaceID.ResourceGroup, workspaceID.WorkspaceName, name, param); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,6 @@ func resourceSentinelAlertRuleScheduledCreateUpdate(d *pluginsdk.ResourceData, m
param.ScheduledAlertRuleProperties.EntityMappings = expandAlertRuleScheduledEntityMapping(v.([]interface{}))
}

// Service avoid concurrent update of this resource via checking the "etag" to guarantee it is the same value as last Read.
if !d.IsNewResource() {
resp, err := client.Get(ctx, workspaceID.ResourceGroup, workspaceID.WorkspaceName, name)
if err != nil {
Expand All @@ -455,7 +454,6 @@ func resourceSentinelAlertRuleScheduledCreateUpdate(d *pluginsdk.ResourceData, m
if err := assertAlertRuleKind(resp.Value, securityinsight.AlertRuleKindScheduled); err != nil {
return fmt.Errorf("asserting alert rule of %q: %+v", id, err)
}
param.Etag = resp.Value.(securityinsight.ScheduledAlertRule).Etag
}

if _, err := client.CreateOrUpdate(ctx, workspaceID.ResourceGroup, workspaceID.WorkspaceName, name, param); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,15 @@ func resourceSentinelDataConnectorAwsCloudTrailCreateUpdate(d *pluginsdk.Resourc
Kind: securityinsight.KindBasicDataConnectorKindAmazonWebServicesCloudTrail,
}

// Service avoid concurrent updates of this resource via checking the "etag" to guarantee it is the same value as last Read.
// TODO: following code can be removed once the issue below is fixed:
// https://github.com/Azure/azure-rest-api-specs/issues/13203
if !d.IsNewResource() {
resp, err := client.Get(ctx, id.ResourceGroup, id.WorkspaceName, name)
if err != nil {
return fmt.Errorf("retrieving %s: %+v", id, err)
}

dc, ok := resp.Value.(securityinsight.AwsCloudTrailDataConnector)
if !ok {
if _, ok := resp.Value.(securityinsight.AwsCloudTrailDataConnector); !ok {
return fmt.Errorf("%s was not an AWS Cloud Trail Data Connector", id)
}
param.Etag = dc.Etag
}

if _, err = client.CreateOrUpdate(ctx, id.ResourceGroup, id.WorkspaceName, id.Name, param); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,20 +138,15 @@ func resourceSentinelDataConnectorMicrosoftCloudAppSecurityCreateUpdate(d *plugi
Kind: securityinsight.KindBasicDataConnectorKindMicrosoftCloudAppSecurity,
}

// Service avoid concurrent updates of this resource via checking the "etag" to guarantee it is the same value as last Read.
// TODO: following code can be removed once the issue below is fixed:
// https://github.com/Azure/azure-rest-api-specs/issues/13203
if !d.IsNewResource() {
resp, err := client.Get(ctx, id.ResourceGroup, id.WorkspaceName, name)
if err != nil {
return fmt.Errorf("retrieving %s: %+v", id, err)
}

dc, ok := resp.Value.(securityinsight.MCASDataConnector)
if !ok {
if _, ok := resp.Value.(securityinsight.MCASDataConnector); !ok {
return fmt.Errorf("%s was not a Microsoft Cloud App Security Data Connector", id)
}
param.Etag = dc.Etag
}

if _, err = client.CreateOrUpdate(ctx, id.ResourceGroup, id.WorkspaceName, id.Name, param); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,21 +154,15 @@ func resourceSentinelDataConnectorOffice365CreateUpdate(d *pluginsdk.ResourceDat
Kind: securityinsight.KindBasicDataConnectorKindOffice365,
}

// Service avoid concurrent updates of this resource via checking the "etag" to guarantee it is the same value as last Read.
// TODO: following code can be removed once the issue below is fixed:
// https://github.com/Azure/azure-rest-api-specs/issues/13203
if !d.IsNewResource() {
resp, err := client.Get(ctx, id.ResourceGroup, id.WorkspaceName, name)
if err != nil {
return fmt.Errorf("retrieving Sentinel Data Connector Office 365 %q: %+v", id, err)
}

dc, ok := resp.Value.(securityinsight.OfficeDataConnector)
if !ok {
if _, ok := resp.Value.(securityinsight.OfficeDataConnector); !ok {
return fmt.Errorf("%s was not an Office 365 Data Connector", id)
}

param.Etag = dc.Etag
}

if _, err = client.CreateOrUpdate(ctx, id.ResourceGroup, id.WorkspaceName, id.Name, param); err != nil {
Expand Down