forked from hashicorp/terraform-provider-azurerm
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New resource: `azurerm_sentinel_data_connector_threat_intelligence_ta…
…xii` (hashicorp#19209)
- Loading branch information
Showing
7 changed files
with
1,233 additions
and
1 deletion.
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.