-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
New resource: azurerm_sentinel_data_connector_threat_intelligence_taxii
#19209
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2c33981
WIP: sentinel dc ti taxii
magodo 813f71f
hacking...
magodo f7188f2
New resource: `azurerm_sentinel_data_connector_threat_intelligence_taxii
magodo e39e852
remove a file..
magodo 9526847
Add a TODO 4.0 to check whether the service has fixed the incorrect b…
magodo 8e9be36
Merge remote-tracking branch 'upstream/main' into sentinel_dc_titaxii
magodo 142d82f
Pass build
magodo 6afe958
Make sure the hacks can still work even if the service fixed the API
magodo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
162 changes: 162 additions & 0 deletions
162
internal/services/sentinel/azuresdkhacks/dataconnectors.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
package azuresdkhacks | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
"github.com/Azure/go-autorest/autorest" | ||
"github.com/Azure/go-autorest/autorest/azure" | ||
"github.com/Azure/go-autorest/autorest/validation" | ||
securityinsight "github.com/tombuildsstuff/kermit/sdk/securityinsights/2022-10-01-preview/securityinsights" | ||
) | ||
|
||
type DataConnectorsClient struct { | ||
securityinsight.BaseClient | ||
} | ||
|
||
func (client DataConnectorsClient) Get(ctx context.Context, resourceGroupName string, workspaceName string, dataConnectorID string) (result DataConnectorModel, err error) { | ||
if err := validation.Validate([]validation.Validation{ | ||
{TargetValue: client.SubscriptionID, | ||
Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, | ||
{TargetValue: resourceGroupName, | ||
Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, | ||
{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}, | ||
{TargetValue: workspaceName, | ||
Constraints: []validation.Constraint{{Target: "workspaceName", Name: validation.MaxLength, Rule: 90, Chain: nil}, | ||
{Target: "workspaceName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { | ||
return result, validation.NewError("securityinsight.DataConnectorsClient", "Get", err.Error()) | ||
} | ||
|
||
req, err := client.GetPreparer(ctx, resourceGroupName, workspaceName, dataConnectorID) | ||
if err != nil { | ||
err = autorest.NewErrorWithError(err, "securityinsight.DataConnectorsClient", "Get", nil, "Failure preparing request") | ||
return | ||
} | ||
|
||
resp, err := client.GetSender(req) | ||
if err != nil { | ||
result.Response = autorest.Response{Response: resp} | ||
err = autorest.NewErrorWithError(err, "securityinsight.DataConnectorsClient", "Get", resp, "Failure sending request") | ||
return | ||
} | ||
|
||
result, err = client.GetResponder(resp) | ||
if err != nil { | ||
err = autorest.NewErrorWithError(err, "securityinsight.DataConnectorsClient", "Get", resp, "Failure responding to request") | ||
return | ||
} | ||
|
||
return | ||
} | ||
|
||
func (client DataConnectorsClient) GetPreparer(ctx context.Context, resourceGroupName string, workspaceName string, dataConnectorID string) (*http.Request, error) { | ||
pathParameters := map[string]interface{}{ | ||
"dataConnectorId": autorest.Encode("path", dataConnectorID), | ||
"resourceGroupName": autorest.Encode("path", resourceGroupName), | ||
"subscriptionId": autorest.Encode("path", client.SubscriptionID), | ||
"workspaceName": autorest.Encode("path", workspaceName), | ||
} | ||
|
||
const APIVersion = "2022-10-01-preview" | ||
queryParameters := map[string]interface{}{ | ||
"api-version": APIVersion, | ||
} | ||
|
||
preparer := autorest.CreatePreparer( | ||
autorest.AsGet(), | ||
autorest.WithBaseURL(client.BaseURI), | ||
autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.OperationalInsights/workspaces/{workspaceName}/providers/Microsoft.SecurityInsights/dataConnectors/{dataConnectorId}", pathParameters), | ||
autorest.WithQueryParameters(queryParameters)) | ||
return preparer.Prepare((&http.Request{}).WithContext(ctx)) | ||
} | ||
|
||
func (client DataConnectorsClient) GetSender(req *http.Request) (*http.Response, error) { | ||
return client.Send(req, azure.DoRetryWithRegistration(client.Client)) | ||
} | ||
|
||
func (client DataConnectorsClient) GetResponder(resp *http.Response) (result DataConnectorModel, err error) { | ||
err = autorest.Respond( | ||
resp, | ||
azure.WithErrorUnlessStatusCode(http.StatusOK), | ||
autorest.ByUnmarshallingJSON(&result), | ||
autorest.ByClosing()) | ||
result.Response = autorest.Response{Response: resp} | ||
return | ||
} | ||
|
||
func (client DataConnectorsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, workspaceName string, dataConnectorID string, dataConnector securityinsight.BasicDataConnector) (result DataConnectorModel, err error) { | ||
if err := validation.Validate([]validation.Validation{ | ||
{TargetValue: client.SubscriptionID, | ||
Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, | ||
{TargetValue: resourceGroupName, | ||
Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, | ||
{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}, | ||
{TargetValue: workspaceName, | ||
Constraints: []validation.Constraint{{Target: "workspaceName", Name: validation.MaxLength, Rule: 90, Chain: nil}, | ||
{Target: "workspaceName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { | ||
return result, validation.NewError("securityinsight.DataConnectorsClient", "CreateOrUpdate", err.Error()) | ||
} | ||
|
||
req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, workspaceName, dataConnectorID, dataConnector) | ||
if err != nil { | ||
err = autorest.NewErrorWithError(err, "securityinsight.DataConnectorsClient", "CreateOrUpdate", nil, "Failure preparing request") | ||
return | ||
} | ||
|
||
resp, err := client.CreateOrUpdateSender(req) | ||
if err != nil { | ||
result.Response = autorest.Response{Response: resp} | ||
err = autorest.NewErrorWithError(err, "securityinsight.DataConnectorsClient", "CreateOrUpdate", resp, "Failure sending request") | ||
return | ||
} | ||
|
||
result, err = client.CreateOrUpdateResponder(resp) | ||
if err != nil { | ||
err = autorest.NewErrorWithError(err, "securityinsight.DataConnectorsClient", "CreateOrUpdate", resp, "Failure responding to request") | ||
return | ||
} | ||
|
||
return | ||
} | ||
|
||
// CreateOrUpdatePreparer prepares the CreateOrUpdate request. | ||
func (client DataConnectorsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, workspaceName string, dataConnectorID string, dataConnector securityinsight.BasicDataConnector) (*http.Request, error) { | ||
pathParameters := map[string]interface{}{ | ||
"dataConnectorId": autorest.Encode("path", dataConnectorID), | ||
"resourceGroupName": autorest.Encode("path", resourceGroupName), | ||
"subscriptionId": autorest.Encode("path", client.SubscriptionID), | ||
"workspaceName": autorest.Encode("path", workspaceName), | ||
} | ||
|
||
const APIVersion = "2022-10-01-preview" | ||
queryParameters := map[string]interface{}{ | ||
"api-version": APIVersion, | ||
} | ||
|
||
preparer := autorest.CreatePreparer( | ||
autorest.AsContentType("application/json; charset=utf-8"), | ||
autorest.AsPut(), | ||
autorest.WithBaseURL(client.BaseURI), | ||
autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.OperationalInsights/workspaces/{workspaceName}/providers/Microsoft.SecurityInsights/dataConnectors/{dataConnectorId}", pathParameters), | ||
autorest.WithJSON(dataConnector), | ||
autorest.WithQueryParameters(queryParameters)) | ||
return preparer.Prepare((&http.Request{}).WithContext(ctx)) | ||
} | ||
|
||
// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the | ||
// http.Response Body if it receives an error. | ||
func (client DataConnectorsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { | ||
return client.Send(req, azure.DoRetryWithRegistration(client.Client)) | ||
} | ||
|
||
// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always | ||
// closes the http.Response Body. | ||
func (client DataConnectorsClient) CreateOrUpdateResponder(resp *http.Response) (result DataConnectorModel, err error) { | ||
err = autorest.Respond( | ||
resp, | ||
azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), | ||
autorest.ByUnmarshallingJSON(&result), | ||
autorest.ByClosing()) | ||
result.Response = autorest.Response{Response: resp} | ||
return | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you describe this hack and why it is required inline in the code and link to the rest API issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is described at: https://github.com/hashicorp/terraform-provider-azurerm/pull/19209/files#diff-678a173979b1ea700c88ac1db19d4545fe5088817771414efcaaacafbad2dd5aR13
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@magodo mind sending a Swagger PR to fix that too, in addition to the issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tombuildsstuff That is a service behavior issue rather than a Swagger issue, which the service team has acknowledged and will fix it at backend.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any updates on if the service team has fixed this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@magodo - could you update the linked rest api spec issue with that? will this hack here work when that backend change goes into play?
also could we put a `//todo 4.0 check if this can be removed" comment next to the link to the rest issue?
thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@katbyte The issue link is added here:
terraform-provider-azurerm/internal/services/sentinel/azuresdkhacks/models.go
Line 13 in e39e852
Once the backend change goes into play, this hack will cause error, at that time we shall revert it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any way that you could write the hack so it can handle both? otherwise when the fix goes out the resource will break users requiring them to update again
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@katbyte I've made the change and now it should go on working even if the service team fixed it:
terraform-provider-azurerm on sentinel_dc_titaxii via 🐹 v1.19 took 6s 💢 TF_ACC=1 go test -v -timeout=20h ./internal/services/sentinel -run=TestAccDataConnectorThreatIntelligenceTAXII_basic === RUN TestAccDataConnectorThreatIntelligenceTAXII_basic === PAUSE TestAccDataConnectorThreatIntelligenceTAXII_basic === CONT TestAccDataConnectorThreatIntelligenceTAXII_basic --- PASS: TestAccDataConnectorThreatIntelligenceTAXII_basic (262.73s) PASS ok github.com/hashicorp/terraform-provider-azurerm/internal/services/sentinel 262.743s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perfect! thanks 😄