diff --git a/resource-manager/securityinsights/2021-09-01-preview/actions/client.go b/resource-manager/securityinsights/2021-09-01-preview/actions/client.go index 9a66b55eb82..a2b7d01bfe1 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/actions/client.go +++ b/resource-manager/securityinsights/2021-09-01-preview/actions/client.go @@ -1,18 +1,26 @@ package actions -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type ActionsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewActionsClientWithBaseURI(endpoint string) ActionsClient { - return ActionsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewActionsClientWithBaseURI(sdkApi sdkEnv.Api) (*ActionsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "actions", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ActionsClient: %+v", err) } + + return &ActionsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2021-09-01-preview/actions/method_createorupdate.go b/resource-manager/securityinsights/2021-09-01-preview/actions/method_createorupdate.go new file mode 100644 index 00000000000..1672bf99a0f --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/actions/method_createorupdate.go @@ -0,0 +1,56 @@ +package actions + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ActionResponse +} + +// CreateOrUpdate ... +func (c ActionsClient) CreateOrUpdate(ctx context.Context, id ActionId, input ActionRequest) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/actions/method_createorupdate_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/actions/method_createorupdate_autorest.go deleted file mode 100644 index f5145e1a555..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/actions/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package actions - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *ActionResponse -} - -// CreateOrUpdate ... -func (c ActionsClient) CreateOrUpdate(ctx context.Context, id ActionId, input ActionRequest) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c ActionsClient) preparerForCreateOrUpdate(ctx context.Context, id ActionId, input ActionRequest) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c ActionsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/actions/method_delete.go b/resource-manager/securityinsights/2021-09-01-preview/actions/method_delete.go new file mode 100644 index 00000000000..0f8a28307c2 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/actions/method_delete.go @@ -0,0 +1,47 @@ +package actions + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c ActionsClient) Delete(ctx context.Context, id ActionId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/actions/method_delete_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/actions/method_delete_autorest.go deleted file mode 100644 index d142f9f3054..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/actions/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package actions - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c ActionsClient) Delete(ctx context.Context, id ActionId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c ActionsClient) preparerForDelete(ctx context.Context, id ActionId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c ActionsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/actions/method_get.go b/resource-manager/securityinsights/2021-09-01-preview/actions/method_get.go new file mode 100644 index 00000000000..76d3593e1f1 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/actions/method_get.go @@ -0,0 +1,51 @@ +package actions + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ActionResponse +} + +// Get ... +func (c ActionsClient) Get(ctx context.Context, id ActionId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/actions/method_get_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/actions/method_get_autorest.go deleted file mode 100644 index aa1388a0c31..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/actions/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package actions - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *ActionResponse -} - -// Get ... -func (c ActionsClient) Get(ctx context.Context, id ActionId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c ActionsClient) preparerForGet(ctx context.Context, id ActionId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c ActionsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/actions/method_listbyalertrule.go b/resource-manager/securityinsights/2021-09-01-preview/actions/method_listbyalertrule.go new file mode 100644 index 00000000000..09d32b9d82d --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/actions/method_listbyalertrule.go @@ -0,0 +1,91 @@ +package actions + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByAlertRuleOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ActionResponse +} + +type ListByAlertRuleCompleteResult struct { + LatestHttpResponse *http.Response + Items []ActionResponse +} + +// ListByAlertRule ... +func (c ActionsClient) ListByAlertRule(ctx context.Context, id AlertRuleId) (result ListByAlertRuleOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/actions", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ActionResponse `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByAlertRuleComplete retrieves all the results into a single object +func (c ActionsClient) ListByAlertRuleComplete(ctx context.Context, id AlertRuleId) (ListByAlertRuleCompleteResult, error) { + return c.ListByAlertRuleCompleteMatchingPredicate(ctx, id, ActionResponseOperationPredicate{}) +} + +// ListByAlertRuleCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ActionsClient) ListByAlertRuleCompleteMatchingPredicate(ctx context.Context, id AlertRuleId, predicate ActionResponseOperationPredicate) (result ListByAlertRuleCompleteResult, err error) { + items := make([]ActionResponse, 0) + + resp, err := c.ListByAlertRule(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByAlertRuleCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/actions/method_listbyalertrule_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/actions/method_listbyalertrule_autorest.go deleted file mode 100644 index a58a9738f1f..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/actions/method_listbyalertrule_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package actions - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListByAlertRuleOperationResponse struct { - HttpResponse *http.Response - Model *[]ActionResponse - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListByAlertRuleOperationResponse, error) -} - -type ListByAlertRuleCompleteResult struct { - Items []ActionResponse -} - -func (r ListByAlertRuleOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListByAlertRuleOperationResponse) LoadMore(ctx context.Context) (resp ListByAlertRuleOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// ListByAlertRule ... -func (c ActionsClient) ListByAlertRule(ctx context.Context, id AlertRuleId) (resp ListByAlertRuleOperationResponse, err error) { - req, err := c.preparerForListByAlertRule(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "ListByAlertRule", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "ListByAlertRule", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForListByAlertRule(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "ListByAlertRule", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForListByAlertRule prepares the ListByAlertRule request. -func (c ActionsClient) preparerForListByAlertRule(ctx context.Context, id AlertRuleId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/actions", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListByAlertRuleWithNextLink prepares the ListByAlertRule request with the given nextLink token. -func (c ActionsClient) preparerForListByAlertRuleWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForListByAlertRule handles the response to the ListByAlertRule request. The method always -// closes the http.Response Body. -func (c ActionsClient) responderForListByAlertRule(resp *http.Response) (result ListByAlertRuleOperationResponse, err error) { - type page struct { - Values []ActionResponse `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByAlertRuleOperationResponse, err error) { - req, err := c.preparerForListByAlertRuleWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "ListByAlertRule", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "ListByAlertRule", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForListByAlertRule(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "ListByAlertRule", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListByAlertRuleComplete retrieves all of the results into a single object -func (c ActionsClient) ListByAlertRuleComplete(ctx context.Context, id AlertRuleId) (ListByAlertRuleCompleteResult, error) { - return c.ListByAlertRuleCompleteMatchingPredicate(ctx, id, ActionResponseOperationPredicate{}) -} - -// ListByAlertRuleCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c ActionsClient) ListByAlertRuleCompleteMatchingPredicate(ctx context.Context, id AlertRuleId, predicate ActionResponseOperationPredicate) (resp ListByAlertRuleCompleteResult, err error) { - items := make([]ActionResponse, 0) - - page, err := c.ListByAlertRule(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListByAlertRuleCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/alertrules/client.go b/resource-manager/securityinsights/2021-09-01-preview/alertrules/client.go index 6e34bca2ce3..e6ca04af9da 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/alertrules/client.go +++ b/resource-manager/securityinsights/2021-09-01-preview/alertrules/client.go @@ -1,18 +1,26 @@ package alertrules -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type AlertRulesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewAlertRulesClientWithBaseURI(endpoint string) AlertRulesClient { - return AlertRulesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewAlertRulesClientWithBaseURI(sdkApi sdkEnv.Api) (*AlertRulesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "alertrules", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AlertRulesClient: %+v", err) } + + return &AlertRulesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2021-09-01-preview/alertrules/constants.go b/resource-manager/securityinsights/2021-09-01-preview/alertrules/constants.go index d90cb017b79..ca0025a13d0 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/alertrules/constants.go +++ b/resource-manager/securityinsights/2021-09-01-preview/alertrules/constants.go @@ -1,6 +1,10 @@ package alertrules -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -19,6 +23,19 @@ func PossibleValuesForAlertDetail() []string { } } +func (s *AlertDetail) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertDetail(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertDetail(input string) (*AlertDetail, error) { vals := map[string]AlertDetail{ "displayname": AlertDetailDisplayName, @@ -55,6 +72,19 @@ func PossibleValuesForAlertRuleKind() []string { } } +func (s *AlertRuleKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertRuleKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertRuleKind(input string) (*AlertRuleKind, error) { vals := map[string]AlertRuleKind{ "fusion": AlertRuleKindFusion, @@ -91,6 +121,19 @@ func PossibleValuesForAlertSeverity() []string { } } +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertSeverity(input string) (*AlertSeverity, error) { vals := map[string]AlertSeverity{ "high": AlertSeverityHigh, @@ -143,6 +186,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -214,6 +270,19 @@ func PossibleValuesForEntityMappingType() []string { } } +func (s *EntityMappingType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityMappingType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityMappingType(input string) (*EntityMappingType, error) { vals := map[string]EntityMappingType{ "account": EntityMappingTypeAccount, @@ -258,6 +327,19 @@ func PossibleValuesForEventGroupingAggregationKind() []string { } } +func (s *EventGroupingAggregationKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEventGroupingAggregationKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEventGroupingAggregationKind(input string) (*EventGroupingAggregationKind, error) { vals := map[string]EventGroupingAggregationKind{ "alertperresult": EventGroupingAggregationKindAlertPerResult, @@ -288,6 +370,19 @@ func PossibleValuesForMatchingMethod() []string { } } +func (s *MatchingMethod) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMatchingMethod(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseMatchingMethod(input string) (*MatchingMethod, error) { vals := map[string]MatchingMethod{ "allentities": MatchingMethodAllEntities, @@ -327,6 +422,19 @@ func PossibleValuesForMicrosoftSecurityProductName() []string { } } +func (s *MicrosoftSecurityProductName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMicrosoftSecurityProductName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseMicrosoftSecurityProductName(input string) (*MicrosoftSecurityProductName, error) { vals := map[string]MicrosoftSecurityProductName{ "azure active directory identity protection": MicrosoftSecurityProductNameAzureActiveDirectoryIdentityProtection, @@ -364,6 +472,19 @@ func PossibleValuesForTriggerOperator() []string { } } +func (s *TriggerOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTriggerOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseTriggerOperator(input string) (*TriggerOperator, error) { vals := map[string]TriggerOperator{ "equal": TriggerOperatorEqual, diff --git a/resource-manager/securityinsights/2021-09-01-preview/alertrules/method_createorupdate.go b/resource-manager/securityinsights/2021-09-01-preview/alertrules/method_createorupdate.go new file mode 100644 index 00000000000..f77c7558d09 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/alertrules/method_createorupdate.go @@ -0,0 +1,63 @@ +package alertrules + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AlertRule +} + +// CreateOrUpdate ... +func (c AlertRulesClient) CreateOrUpdate(ctx context.Context, id AlertRuleId, input AlertRule) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalAlertRuleImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/alertrules/method_createorupdate_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/alertrules/method_createorupdate_autorest.go deleted file mode 100644 index 548f6c4ef37..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/alertrules/method_createorupdate_autorest.go +++ /dev/null @@ -1,78 +0,0 @@ -package alertrules - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *AlertRule -} - -// CreateOrUpdate ... -func (c AlertRulesClient) CreateOrUpdate(ctx context.Context, id AlertRuleId, input AlertRule) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c AlertRulesClient) preparerForCreateOrUpdate(ctx context.Context, id AlertRuleId, input AlertRule) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c AlertRulesClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalAlertRuleImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/alertrules/method_delete.go b/resource-manager/securityinsights/2021-09-01-preview/alertrules/method_delete.go new file mode 100644 index 00000000000..aae7085c25e --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/alertrules/method_delete.go @@ -0,0 +1,47 @@ +package alertrules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c AlertRulesClient) Delete(ctx context.Context, id AlertRuleId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/alertrules/method_delete_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/alertrules/method_delete_autorest.go deleted file mode 100644 index 417e1a0017e..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/alertrules/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package alertrules - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c AlertRulesClient) Delete(ctx context.Context, id AlertRuleId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c AlertRulesClient) preparerForDelete(ctx context.Context, id AlertRuleId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c AlertRulesClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/alertrules/method_get.go b/resource-manager/securityinsights/2021-09-01-preview/alertrules/method_get.go new file mode 100644 index 00000000000..945c07bfad1 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/alertrules/method_get.go @@ -0,0 +1,58 @@ +package alertrules + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AlertRule +} + +// Get ... +func (c AlertRulesClient) Get(ctx context.Context, id AlertRuleId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalAlertRuleImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/alertrules/method_get_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/alertrules/method_get_autorest.go deleted file mode 100644 index ddd1836d4de..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/alertrules/method_get_autorest.go +++ /dev/null @@ -1,77 +0,0 @@ -package alertrules - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *AlertRule -} - -// Get ... -func (c AlertRulesClient) Get(ctx context.Context, id AlertRuleId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c AlertRulesClient) preparerForGet(ctx context.Context, id AlertRuleId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c AlertRulesClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalAlertRuleImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/alertrules/method_list.go b/resource-manager/securityinsights/2021-09-01-preview/alertrules/method_list.go new file mode 100644 index 00000000000..5ac99496167 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/alertrules/method_list.go @@ -0,0 +1,103 @@ +package alertrules + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AlertRule +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []AlertRule +} + +// List ... +func (c AlertRulesClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/alertRules", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]AlertRule, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalAlertRuleImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for AlertRule (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// ListComplete retrieves all the results into a single object +func (c AlertRulesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, AlertRuleOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AlertRulesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AlertRuleOperationPredicate) (result ListCompleteResult, err error) { + items := make([]AlertRule, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/alertrules/method_list_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/alertrules/method_list_autorest.go deleted file mode 100644 index f06cf0f6241..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/alertrules/method_list_autorest.go +++ /dev/null @@ -1,196 +0,0 @@ -package alertrules - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]AlertRule - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []AlertRule -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c AlertRulesClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c AlertRulesClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/alertRules", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c AlertRulesClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c AlertRulesClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]AlertRule, 0) - for i, v := range respObj.Values { - val, err := unmarshalAlertRuleImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for AlertRule (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c AlertRulesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, AlertRuleOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c AlertRulesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AlertRuleOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]AlertRule, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/alertruletemplates/client.go b/resource-manager/securityinsights/2021-09-01-preview/alertruletemplates/client.go index c439e5a41c7..2932bf14a55 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/alertruletemplates/client.go +++ b/resource-manager/securityinsights/2021-09-01-preview/alertruletemplates/client.go @@ -1,18 +1,26 @@ package alertruletemplates -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type AlertRuleTemplatesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewAlertRuleTemplatesClientWithBaseURI(endpoint string) AlertRuleTemplatesClient { - return AlertRuleTemplatesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewAlertRuleTemplatesClientWithBaseURI(sdkApi sdkEnv.Api) (*AlertRuleTemplatesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "alertruletemplates", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AlertRuleTemplatesClient: %+v", err) } + + return &AlertRuleTemplatesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2021-09-01-preview/alertruletemplates/constants.go b/resource-manager/securityinsights/2021-09-01-preview/alertruletemplates/constants.go index bf41995ac98..b0dee2366eb 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/alertruletemplates/constants.go +++ b/resource-manager/securityinsights/2021-09-01-preview/alertruletemplates/constants.go @@ -1,6 +1,10 @@ package alertruletemplates -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -27,6 +31,19 @@ func PossibleValuesForAlertRuleKind() []string { } } +func (s *AlertRuleKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertRuleKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertRuleKind(input string) (*AlertRuleKind, error) { vals := map[string]AlertRuleKind{ "fusion": AlertRuleKindFusion, @@ -63,6 +80,19 @@ func PossibleValuesForAlertSeverity() []string { } } +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertSeverity(input string) (*AlertSeverity, error) { vals := map[string]AlertSeverity{ "high": AlertSeverityHigh, @@ -115,6 +145,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -186,6 +229,19 @@ func PossibleValuesForEntityMappingType() []string { } } +func (s *EntityMappingType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityMappingType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityMappingType(input string) (*EntityMappingType, error) { vals := map[string]EntityMappingType{ "account": EntityMappingTypeAccount, @@ -230,6 +286,19 @@ func PossibleValuesForEventGroupingAggregationKind() []string { } } +func (s *EventGroupingAggregationKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEventGroupingAggregationKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEventGroupingAggregationKind(input string) (*EventGroupingAggregationKind, error) { vals := map[string]EventGroupingAggregationKind{ "alertperresult": EventGroupingAggregationKindAlertPerResult, @@ -268,6 +337,19 @@ func PossibleValuesForMicrosoftSecurityProductName() []string { } } +func (s *MicrosoftSecurityProductName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMicrosoftSecurityProductName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseMicrosoftSecurityProductName(input string) (*MicrosoftSecurityProductName, error) { vals := map[string]MicrosoftSecurityProductName{ "azure active directory identity protection": MicrosoftSecurityProductNameAzureActiveDirectoryIdentityProtection, @@ -303,6 +385,19 @@ func PossibleValuesForTemplateStatus() []string { } } +func (s *TemplateStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTemplateStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseTemplateStatus(input string) (*TemplateStatus, error) { vals := map[string]TemplateStatus{ "available": TemplateStatusAvailable, @@ -336,6 +431,19 @@ func PossibleValuesForTriggerOperator() []string { } } +func (s *TriggerOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTriggerOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseTriggerOperator(input string) (*TriggerOperator, error) { vals := map[string]TriggerOperator{ "equal": TriggerOperatorEqual, diff --git a/resource-manager/securityinsights/2021-09-01-preview/alertruletemplates/method_get.go b/resource-manager/securityinsights/2021-09-01-preview/alertruletemplates/method_get.go new file mode 100644 index 00000000000..861712be66a --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/alertruletemplates/method_get.go @@ -0,0 +1,58 @@ +package alertruletemplates + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AlertRuleTemplate +} + +// Get ... +func (c AlertRuleTemplatesClient) Get(ctx context.Context, id AlertRuleTemplateId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalAlertRuleTemplateImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/alertruletemplates/method_get_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/alertruletemplates/method_get_autorest.go deleted file mode 100644 index ad4e0487d83..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/alertruletemplates/method_get_autorest.go +++ /dev/null @@ -1,77 +0,0 @@ -package alertruletemplates - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *AlertRuleTemplate -} - -// Get ... -func (c AlertRuleTemplatesClient) Get(ctx context.Context, id AlertRuleTemplateId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c AlertRuleTemplatesClient) preparerForGet(ctx context.Context, id AlertRuleTemplateId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c AlertRuleTemplatesClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalAlertRuleTemplateImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/alertruletemplates/method_list.go b/resource-manager/securityinsights/2021-09-01-preview/alertruletemplates/method_list.go new file mode 100644 index 00000000000..21f9ceec3de --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/alertruletemplates/method_list.go @@ -0,0 +1,103 @@ +package alertruletemplates + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AlertRuleTemplate +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []AlertRuleTemplate +} + +// List ... +func (c AlertRuleTemplatesClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/alertRuleTemplates", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]AlertRuleTemplate, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalAlertRuleTemplateImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for AlertRuleTemplate (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// ListComplete retrieves all the results into a single object +func (c AlertRuleTemplatesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, AlertRuleTemplateOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AlertRuleTemplatesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AlertRuleTemplateOperationPredicate) (result ListCompleteResult, err error) { + items := make([]AlertRuleTemplate, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/alertruletemplates/method_list_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/alertruletemplates/method_list_autorest.go deleted file mode 100644 index 56794382966..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/alertruletemplates/method_list_autorest.go +++ /dev/null @@ -1,196 +0,0 @@ -package alertruletemplates - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]AlertRuleTemplate - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []AlertRuleTemplate -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c AlertRuleTemplatesClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c AlertRuleTemplatesClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/alertRuleTemplates", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c AlertRuleTemplatesClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c AlertRuleTemplatesClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]AlertRuleTemplate, 0) - for i, v := range respObj.Values { - val, err := unmarshalAlertRuleTemplateImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for AlertRuleTemplate (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c AlertRuleTemplatesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, AlertRuleTemplateOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c AlertRuleTemplatesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AlertRuleTemplateOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]AlertRuleTemplate, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/automationrule/client.go b/resource-manager/securityinsights/2021-09-01-preview/automationrule/client.go index ad845ad4670..76a0832c1f2 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/automationrule/client.go +++ b/resource-manager/securityinsights/2021-09-01-preview/automationrule/client.go @@ -1,18 +1,26 @@ package automationrule -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type AutomationRuleClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewAutomationRuleClientWithBaseURI(endpoint string) AutomationRuleClient { - return AutomationRuleClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewAutomationRuleClientWithBaseURI(sdkApi sdkEnv.Api) (*AutomationRuleClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "automationrule", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AutomationRuleClient: %+v", err) } + + return &AutomationRuleClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2021-09-01-preview/automationrule/method_delete.go b/resource-manager/securityinsights/2021-09-01-preview/automationrule/method_delete.go new file mode 100644 index 00000000000..61f722711f9 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/automationrule/method_delete.go @@ -0,0 +1,47 @@ +package automationrule + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c AutomationRuleClient) Delete(ctx context.Context, id AutomationRuleId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/automationrule/method_delete_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/automationrule/method_delete_autorest.go deleted file mode 100644 index 9970d16275d..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/automationrule/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package automationrule - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c AutomationRuleClient) Delete(ctx context.Context, id AutomationRuleId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrule.AutomationRuleClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrule.AutomationRuleClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrule.AutomationRuleClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c AutomationRuleClient) preparerForDelete(ctx context.Context, id AutomationRuleId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c AutomationRuleClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/automationrules/client.go b/resource-manager/securityinsights/2021-09-01-preview/automationrules/client.go index 960f049c387..18fafea1496 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/automationrules/client.go +++ b/resource-manager/securityinsights/2021-09-01-preview/automationrules/client.go @@ -1,18 +1,26 @@ package automationrules -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type AutomationRulesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewAutomationRulesClientWithBaseURI(endpoint string) AutomationRulesClient { - return AutomationRulesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewAutomationRulesClientWithBaseURI(sdkApi sdkEnv.Api) (*AutomationRulesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "automationrules", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AutomationRulesClient: %+v", err) } + + return &AutomationRulesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2021-09-01-preview/automationrules/constants.go b/resource-manager/securityinsights/2021-09-01-preview/automationrules/constants.go index 2e08095b532..08cda9f4df7 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/automationrules/constants.go +++ b/resource-manager/securityinsights/2021-09-01-preview/automationrules/constants.go @@ -1,6 +1,10 @@ package automationrules -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -19,6 +23,19 @@ func PossibleValuesForAutomationRuleActionType() []string { } } +func (s *AutomationRuleActionType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRuleActionType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAutomationRuleActionType(input string) (*AutomationRuleActionType, error) { vals := map[string]AutomationRuleActionType{ "modifyproperties": AutomationRuleActionTypeModifyProperties, @@ -45,6 +62,19 @@ func PossibleValuesForAutomationRuleConditionType() []string { } } +func (s *AutomationRuleConditionType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRuleConditionType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAutomationRuleConditionType(input string) (*AutomationRuleConditionType, error) { vals := map[string]AutomationRuleConditionType{ "property": AutomationRuleConditionTypeProperty, @@ -84,6 +114,19 @@ func PossibleValuesForAutomationRulePropertyConditionSupportedOperator() []strin } } +func (s *AutomationRulePropertyConditionSupportedOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRulePropertyConditionSupportedOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAutomationRulePropertyConditionSupportedOperator(input string) (*AutomationRulePropertyConditionSupportedOperator, error) { vals := map[string]AutomationRulePropertyConditionSupportedOperator{ "contains": AutomationRulePropertyConditionSupportedOperatorContains, @@ -218,6 +261,19 @@ func PossibleValuesForAutomationRulePropertyConditionSupportedProperty() []strin } } +func (s *AutomationRulePropertyConditionSupportedProperty) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRulePropertyConditionSupportedProperty(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAutomationRulePropertyConditionSupportedProperty(input string) (*AutomationRulePropertyConditionSupportedProperty, error) { vals := map[string]AutomationRulePropertyConditionSupportedProperty{ "accountaadtenantid": AutomationRulePropertyConditionSupportedPropertyAccountAadTenantId, @@ -300,6 +356,19 @@ func PossibleValuesForIncidentClassification() []string { } } +func (s *IncidentClassification) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentClassification(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentClassification(input string) (*IncidentClassification, error) { vals := map[string]IncidentClassification{ "benignpositive": IncidentClassificationBenignPositive, @@ -334,6 +403,19 @@ func PossibleValuesForIncidentClassificationReason() []string { } } +func (s *IncidentClassificationReason) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentClassificationReason(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentClassificationReason(input string) (*IncidentClassificationReason, error) { vals := map[string]IncidentClassificationReason{ "inaccuratedata": IncidentClassificationReasonInaccurateData, @@ -364,6 +446,19 @@ func PossibleValuesForIncidentLabelType() []string { } } +func (s *IncidentLabelType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentLabelType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentLabelType(input string) (*IncidentLabelType, error) { vals := map[string]IncidentLabelType{ "system": IncidentLabelTypeSystem, @@ -396,6 +491,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, @@ -428,6 +536,19 @@ func PossibleValuesForIncidentStatus() []string { } } +func (s *IncidentStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentStatus(input string) (*IncidentStatus, error) { vals := map[string]IncidentStatus{ "active": IncidentStatusActive, @@ -459,6 +580,19 @@ func PossibleValuesForOwnerType() []string { } } +func (s *OwnerType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOwnerType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseOwnerType(input string) (*OwnerType, error) { vals := map[string]OwnerType{ "group": OwnerTypeGroup, @@ -486,6 +620,19 @@ func PossibleValuesForTriggersOn() []string { } } +func (s *TriggersOn) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTriggersOn(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseTriggersOn(input string) (*TriggersOn, error) { vals := map[string]TriggersOn{ "incidents": TriggersOnIncidents, @@ -511,6 +658,19 @@ func PossibleValuesForTriggersWhen() []string { } } +func (s *TriggersWhen) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTriggersWhen(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseTriggersWhen(input string) (*TriggersWhen, error) { vals := map[string]TriggersWhen{ "created": TriggersWhenCreated, diff --git a/resource-manager/securityinsights/2021-09-01-preview/automationrules/method_createorupdate.go b/resource-manager/securityinsights/2021-09-01-preview/automationrules/method_createorupdate.go new file mode 100644 index 00000000000..c0b3c44f2da --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/automationrules/method_createorupdate.go @@ -0,0 +1,56 @@ +package automationrules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AutomationRule +} + +// CreateOrUpdate ... +func (c AutomationRulesClient) CreateOrUpdate(ctx context.Context, id AutomationRuleId, input AutomationRule) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/automationrules/method_createorupdate_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/automationrules/method_createorupdate_autorest.go deleted file mode 100644 index 790f2ff99f9..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/automationrules/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package automationrules - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *AutomationRule -} - -// CreateOrUpdate ... -func (c AutomationRulesClient) CreateOrUpdate(ctx context.Context, id AutomationRuleId, input AutomationRule) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c AutomationRulesClient) preparerForCreateOrUpdate(ctx context.Context, id AutomationRuleId, input AutomationRule) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c AutomationRulesClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/automationrules/method_get.go b/resource-manager/securityinsights/2021-09-01-preview/automationrules/method_get.go new file mode 100644 index 00000000000..0676dc80f40 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/automationrules/method_get.go @@ -0,0 +1,51 @@ +package automationrules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AutomationRule +} + +// Get ... +func (c AutomationRulesClient) Get(ctx context.Context, id AutomationRuleId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/automationrules/method_get_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/automationrules/method_get_autorest.go deleted file mode 100644 index 20f385aa8d7..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/automationrules/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package automationrules - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *AutomationRule -} - -// Get ... -func (c AutomationRulesClient) Get(ctx context.Context, id AutomationRuleId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c AutomationRulesClient) preparerForGet(ctx context.Context, id AutomationRuleId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c AutomationRulesClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/automationrules/method_list.go b/resource-manager/securityinsights/2021-09-01-preview/automationrules/method_list.go new file mode 100644 index 00000000000..a3c7db4995a --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/automationrules/method_list.go @@ -0,0 +1,91 @@ +package automationrules + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AutomationRule +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []AutomationRule +} + +// List ... +func (c AutomationRulesClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/automationRules", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]AutomationRule `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c AutomationRulesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, AutomationRuleOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AutomationRulesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AutomationRuleOperationPredicate) (result ListCompleteResult, err error) { + items := make([]AutomationRule, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/automationrules/method_list_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/automationrules/method_list_autorest.go deleted file mode 100644 index e2818088fcf..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/automationrules/method_list_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package automationrules - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]AutomationRule - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []AutomationRule -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c AutomationRulesClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c AutomationRulesClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/automationRules", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c AutomationRulesClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c AutomationRulesClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []AutomationRule `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c AutomationRulesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, AutomationRuleOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c AutomationRulesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AutomationRuleOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]AutomationRule, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/bookmark/client.go b/resource-manager/securityinsights/2021-09-01-preview/bookmark/client.go index 0bd7283b391..f20b4939301 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/bookmark/client.go +++ b/resource-manager/securityinsights/2021-09-01-preview/bookmark/client.go @@ -1,18 +1,26 @@ package bookmark -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type BookmarkClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewBookmarkClientWithBaseURI(endpoint string) BookmarkClient { - return BookmarkClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewBookmarkClientWithBaseURI(sdkApi sdkEnv.Api) (*BookmarkClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "bookmark", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating BookmarkClient: %+v", err) } + + return &BookmarkClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2021-09-01-preview/bookmark/constants.go b/resource-manager/securityinsights/2021-09-01-preview/bookmark/constants.go index 7afabf7cd2f..6d837b84514 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/bookmark/constants.go +++ b/resource-manager/securityinsights/2021-09-01-preview/bookmark/constants.go @@ -1,6 +1,10 @@ package bookmark -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -57,6 +61,19 @@ func PossibleValuesForEntityKind() []string { } } +func (s *EntityKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityKind(input string) (*EntityKind, error) { vals := map[string]EntityKind{ "account": EntityKindAccount, diff --git a/resource-manager/securityinsights/2021-09-01-preview/bookmark/method_expand.go b/resource-manager/securityinsights/2021-09-01-preview/bookmark/method_expand.go new file mode 100644 index 00000000000..5d8ee564063 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/bookmark/method_expand.go @@ -0,0 +1,56 @@ +package bookmark + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExpandOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *BookmarkExpandResponse +} + +// Expand ... +func (c BookmarkClient) Expand(ctx context.Context, id BookmarkId, input BookmarkExpandParameters) (result ExpandOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/expand", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/bookmark/method_expand_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/bookmark/method_expand_autorest.go deleted file mode 100644 index c01b051eade..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/bookmark/method_expand_autorest.go +++ /dev/null @@ -1,70 +0,0 @@ -package bookmark - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ExpandOperationResponse struct { - HttpResponse *http.Response - Model *BookmarkExpandResponse -} - -// Expand ... -func (c BookmarkClient) Expand(ctx context.Context, id BookmarkId, input BookmarkExpandParameters) (result ExpandOperationResponse, err error) { - req, err := c.preparerForExpand(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmark.BookmarkClient", "Expand", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmark.BookmarkClient", "Expand", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForExpand(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmark.BookmarkClient", "Expand", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForExpand prepares the Expand request. -func (c BookmarkClient) preparerForExpand(ctx context.Context, id BookmarkId, input BookmarkExpandParameters) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/expand", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForExpand handles the response to the Expand request. The method always -// closes the http.Response Body. -func (c BookmarkClient) responderForExpand(resp *http.Response) (result ExpandOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/bookmarkrelations/client.go b/resource-manager/securityinsights/2021-09-01-preview/bookmarkrelations/client.go index c16a1534a9c..7b2f113e83b 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/bookmarkrelations/client.go +++ b/resource-manager/securityinsights/2021-09-01-preview/bookmarkrelations/client.go @@ -1,18 +1,26 @@ package bookmarkrelations -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type BookmarkRelationsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewBookmarkRelationsClientWithBaseURI(endpoint string) BookmarkRelationsClient { - return BookmarkRelationsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewBookmarkRelationsClientWithBaseURI(sdkApi sdkEnv.Api) (*BookmarkRelationsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "bookmarkrelations", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating BookmarkRelationsClient: %+v", err) } + + return &BookmarkRelationsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2021-09-01-preview/bookmarkrelations/method_createorupdate.go b/resource-manager/securityinsights/2021-09-01-preview/bookmarkrelations/method_createorupdate.go new file mode 100644 index 00000000000..c62743243a5 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/bookmarkrelations/method_createorupdate.go @@ -0,0 +1,56 @@ +package bookmarkrelations + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Relation +} + +// CreateOrUpdate ... +func (c BookmarkRelationsClient) CreateOrUpdate(ctx context.Context, id BookmarkRelationId, input Relation) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/bookmarkrelations/method_createorupdate_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/bookmarkrelations/method_createorupdate_autorest.go deleted file mode 100644 index 31cbda7e37e..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/bookmarkrelations/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package bookmarkrelations - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *Relation -} - -// CreateOrUpdate ... -func (c BookmarkRelationsClient) CreateOrUpdate(ctx context.Context, id BookmarkRelationId, input Relation) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarkrelations.BookmarkRelationsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarkrelations.BookmarkRelationsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarkrelations.BookmarkRelationsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c BookmarkRelationsClient) preparerForCreateOrUpdate(ctx context.Context, id BookmarkRelationId, input Relation) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c BookmarkRelationsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/bookmarkrelations/method_delete.go b/resource-manager/securityinsights/2021-09-01-preview/bookmarkrelations/method_delete.go new file mode 100644 index 00000000000..be83fdfe96b --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/bookmarkrelations/method_delete.go @@ -0,0 +1,47 @@ +package bookmarkrelations + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c BookmarkRelationsClient) Delete(ctx context.Context, id BookmarkRelationId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/bookmarkrelations/method_delete_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/bookmarkrelations/method_delete_autorest.go deleted file mode 100644 index b94d5add215..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/bookmarkrelations/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package bookmarkrelations - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c BookmarkRelationsClient) Delete(ctx context.Context, id BookmarkRelationId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarkrelations.BookmarkRelationsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarkrelations.BookmarkRelationsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarkrelations.BookmarkRelationsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c BookmarkRelationsClient) preparerForDelete(ctx context.Context, id BookmarkRelationId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c BookmarkRelationsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/bookmarkrelations/method_get.go b/resource-manager/securityinsights/2021-09-01-preview/bookmarkrelations/method_get.go new file mode 100644 index 00000000000..a689e84623f --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/bookmarkrelations/method_get.go @@ -0,0 +1,51 @@ +package bookmarkrelations + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Relation +} + +// Get ... +func (c BookmarkRelationsClient) Get(ctx context.Context, id BookmarkRelationId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/bookmarkrelations/method_get_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/bookmarkrelations/method_get_autorest.go deleted file mode 100644 index 68c15700cd0..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/bookmarkrelations/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package bookmarkrelations - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *Relation -} - -// Get ... -func (c BookmarkRelationsClient) Get(ctx context.Context, id BookmarkRelationId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarkrelations.BookmarkRelationsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarkrelations.BookmarkRelationsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarkrelations.BookmarkRelationsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c BookmarkRelationsClient) preparerForGet(ctx context.Context, id BookmarkRelationId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c BookmarkRelationsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/bookmarkrelations/method_list.go b/resource-manager/securityinsights/2021-09-01-preview/bookmarkrelations/method_list.go new file mode 100644 index 00000000000..c7b0e80ee33 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/bookmarkrelations/method_list.go @@ -0,0 +1,127 @@ +package bookmarkrelations + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Relation +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Relation +} + +type ListOperationOptions struct { + Filter *string + Orderby *string + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c BookmarkRelationsClient) List(ctx context.Context, id BookmarkId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/relations", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Relation `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c BookmarkRelationsClient) ListComplete(ctx context.Context, id BookmarkId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, RelationOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c BookmarkRelationsClient) ListCompleteMatchingPredicate(ctx context.Context, id BookmarkId, options ListOperationOptions, predicate RelationOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Relation, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/bookmarkrelations/method_list_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/bookmarkrelations/method_list_autorest.go deleted file mode 100644 index df04eb11905..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/bookmarkrelations/method_list_autorest.go +++ /dev/null @@ -1,225 +0,0 @@ -package bookmarkrelations - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]Relation - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []Relation -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ListOperationOptions struct { - Filter *string - Orderby *string - Top *int64 -} - -func DefaultListOperationOptions() ListOperationOptions { - return ListOperationOptions{} -} - -func (o ListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Filter != nil { - out["$filter"] = *o.Filter - } - - if o.Orderby != nil { - out["$orderby"] = *o.Orderby - } - - if o.Top != nil { - out["$top"] = *o.Top - } - - return out -} - -// List ... -func (c BookmarkRelationsClient) List(ctx context.Context, id BookmarkId, options ListOperationOptions) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarkrelations.BookmarkRelationsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarkrelations.BookmarkRelationsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarkrelations.BookmarkRelationsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c BookmarkRelationsClient) preparerForList(ctx context.Context, id BookmarkId, options ListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/relations", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c BookmarkRelationsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c BookmarkRelationsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []Relation `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarkrelations.BookmarkRelationsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarkrelations.BookmarkRelationsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarkrelations.BookmarkRelationsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c BookmarkRelationsClient) ListComplete(ctx context.Context, id BookmarkId, options ListOperationOptions) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, options, RelationOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c BookmarkRelationsClient) ListCompleteMatchingPredicate(ctx context.Context, id BookmarkId, options ListOperationOptions, predicate RelationOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]Relation, 0) - - page, err := c.List(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/bookmarks/client.go b/resource-manager/securityinsights/2021-09-01-preview/bookmarks/client.go index ee8ca229e2d..22469155649 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/bookmarks/client.go +++ b/resource-manager/securityinsights/2021-09-01-preview/bookmarks/client.go @@ -1,18 +1,26 @@ package bookmarks -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type BookmarksClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewBookmarksClientWithBaseURI(endpoint string) BookmarksClient { - return BookmarksClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewBookmarksClientWithBaseURI(sdkApi sdkEnv.Api) (*BookmarksClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "bookmarks", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating BookmarksClient: %+v", err) } + + return &BookmarksClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2021-09-01-preview/bookmarks/constants.go b/resource-manager/securityinsights/2021-09-01-preview/bookmarks/constants.go index f3a9bf2482b..c057284aed1 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/bookmarks/constants.go +++ b/resource-manager/securityinsights/2021-09-01-preview/bookmarks/constants.go @@ -1,6 +1,10 @@ package bookmarks -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -23,6 +27,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, diff --git a/resource-manager/securityinsights/2021-09-01-preview/bookmarks/method_createorupdate.go b/resource-manager/securityinsights/2021-09-01-preview/bookmarks/method_createorupdate.go new file mode 100644 index 00000000000..72b6987ce5b --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/bookmarks/method_createorupdate.go @@ -0,0 +1,56 @@ +package bookmarks + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Bookmark +} + +// CreateOrUpdate ... +func (c BookmarksClient) CreateOrUpdate(ctx context.Context, id BookmarkId, input Bookmark) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/bookmarks/method_createorupdate_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/bookmarks/method_createorupdate_autorest.go deleted file mode 100644 index 6bae46884df..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/bookmarks/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package bookmarks - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *Bookmark -} - -// CreateOrUpdate ... -func (c BookmarksClient) CreateOrUpdate(ctx context.Context, id BookmarkId, input Bookmark) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c BookmarksClient) preparerForCreateOrUpdate(ctx context.Context, id BookmarkId, input Bookmark) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c BookmarksClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/bookmarks/method_delete.go b/resource-manager/securityinsights/2021-09-01-preview/bookmarks/method_delete.go new file mode 100644 index 00000000000..75eef715a7c --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/bookmarks/method_delete.go @@ -0,0 +1,47 @@ +package bookmarks + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c BookmarksClient) Delete(ctx context.Context, id BookmarkId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/bookmarks/method_delete_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/bookmarks/method_delete_autorest.go deleted file mode 100644 index aa1033f513c..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/bookmarks/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package bookmarks - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c BookmarksClient) Delete(ctx context.Context, id BookmarkId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c BookmarksClient) preparerForDelete(ctx context.Context, id BookmarkId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c BookmarksClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/bookmarks/method_get.go b/resource-manager/securityinsights/2021-09-01-preview/bookmarks/method_get.go new file mode 100644 index 00000000000..b8db3d1b69f --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/bookmarks/method_get.go @@ -0,0 +1,51 @@ +package bookmarks + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Bookmark +} + +// Get ... +func (c BookmarksClient) Get(ctx context.Context, id BookmarkId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/bookmarks/method_get_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/bookmarks/method_get_autorest.go deleted file mode 100644 index c76a6c0c211..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/bookmarks/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package bookmarks - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *Bookmark -} - -// Get ... -func (c BookmarksClient) Get(ctx context.Context, id BookmarkId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c BookmarksClient) preparerForGet(ctx context.Context, id BookmarkId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c BookmarksClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/bookmarks/method_list.go b/resource-manager/securityinsights/2021-09-01-preview/bookmarks/method_list.go new file mode 100644 index 00000000000..432b04c413a --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/bookmarks/method_list.go @@ -0,0 +1,91 @@ +package bookmarks + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Bookmark +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Bookmark +} + +// List ... +func (c BookmarksClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/bookmarks", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Bookmark `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c BookmarksClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, BookmarkOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c BookmarksClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate BookmarkOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Bookmark, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/bookmarks/method_list_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/bookmarks/method_list_autorest.go deleted file mode 100644 index 7c4a69eacea..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/bookmarks/method_list_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package bookmarks - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]Bookmark - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []Bookmark -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c BookmarksClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c BookmarksClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/bookmarks", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c BookmarksClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c BookmarksClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []Bookmark `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c BookmarksClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, BookmarkOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c BookmarksClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate BookmarkOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]Bookmark, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/checkdataconnectorrequirements/client.go b/resource-manager/securityinsights/2021-09-01-preview/checkdataconnectorrequirements/client.go index 1eef55a1676..c01575bd213 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/checkdataconnectorrequirements/client.go +++ b/resource-manager/securityinsights/2021-09-01-preview/checkdataconnectorrequirements/client.go @@ -1,18 +1,26 @@ package checkdataconnectorrequirements -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type CheckDataConnectorRequirementsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewCheckDataConnectorRequirementsClientWithBaseURI(endpoint string) CheckDataConnectorRequirementsClient { - return CheckDataConnectorRequirementsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewCheckDataConnectorRequirementsClientWithBaseURI(sdkApi sdkEnv.Api) (*CheckDataConnectorRequirementsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "checkdataconnectorrequirements", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating CheckDataConnectorRequirementsClient: %+v", err) } + + return &CheckDataConnectorRequirementsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2021-09-01-preview/checkdataconnectorrequirements/constants.go b/resource-manager/securityinsights/2021-09-01-preview/checkdataconnectorrequirements/constants.go index e8e2fe9b677..108cfe6cd81 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/checkdataconnectorrequirements/constants.go +++ b/resource-manager/securityinsights/2021-09-01-preview/checkdataconnectorrequirements/constants.go @@ -1,6 +1,10 @@ package checkdataconnectorrequirements -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -19,6 +23,19 @@ func PossibleValuesForDataConnectorAuthorizationState() []string { } } +func (s *DataConnectorAuthorizationState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataConnectorAuthorizationState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDataConnectorAuthorizationState(input string) (*DataConnectorAuthorizationState, error) { vals := map[string]DataConnectorAuthorizationState{ "invalid": DataConnectorAuthorizationStateInvalid, @@ -77,6 +94,19 @@ func PossibleValuesForDataConnectorKind() []string { } } +func (s *DataConnectorKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataConnectorKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDataConnectorKind(input string) (*DataConnectorKind, error) { vals := map[string]DataConnectorKind{ "apipolling": DataConnectorKindAPIPolling, @@ -122,6 +152,19 @@ func PossibleValuesForDataConnectorLicenseState() []string { } } +func (s *DataConnectorLicenseState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataConnectorLicenseState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDataConnectorLicenseState(input string) (*DataConnectorLicenseState, error) { vals := map[string]DataConnectorLicenseState{ "invalid": DataConnectorLicenseStateInvalid, diff --git a/resource-manager/securityinsights/2021-09-01-preview/checkdataconnectorrequirements/method_dataconnectorscheckrequirementspost.go b/resource-manager/securityinsights/2021-09-01-preview/checkdataconnectorrequirements/method_dataconnectorscheckrequirementspost.go new file mode 100644 index 00000000000..91c387f6a09 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/checkdataconnectorrequirements/method_dataconnectorscheckrequirementspost.go @@ -0,0 +1,56 @@ +package checkdataconnectorrequirements + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataConnectorsCheckRequirementsPostOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DataConnectorRequirementsState +} + +// DataConnectorsCheckRequirementsPost ... +func (c CheckDataConnectorRequirementsClient) DataConnectorsCheckRequirementsPost(ctx context.Context, id WorkspaceId, input DataConnectorsCheckRequirements) (result DataConnectorsCheckRequirementsPostOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/dataConnectorsCheckRequirements", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/checkdataconnectorrequirements/method_dataconnectorscheckrequirementspost_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/checkdataconnectorrequirements/method_dataconnectorscheckrequirementspost_autorest.go deleted file mode 100644 index 596830a1ab4..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/checkdataconnectorrequirements/method_dataconnectorscheckrequirementspost_autorest.go +++ /dev/null @@ -1,70 +0,0 @@ -package checkdataconnectorrequirements - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DataConnectorsCheckRequirementsPostOperationResponse struct { - HttpResponse *http.Response - Model *DataConnectorRequirementsState -} - -// DataConnectorsCheckRequirementsPost ... -func (c CheckDataConnectorRequirementsClient) DataConnectorsCheckRequirementsPost(ctx context.Context, id WorkspaceId, input DataConnectorsCheckRequirements) (result DataConnectorsCheckRequirementsPostOperationResponse, err error) { - req, err := c.preparerForDataConnectorsCheckRequirementsPost(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "checkdataconnectorrequirements.CheckDataConnectorRequirementsClient", "DataConnectorsCheckRequirementsPost", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "checkdataconnectorrequirements.CheckDataConnectorRequirementsClient", "DataConnectorsCheckRequirementsPost", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDataConnectorsCheckRequirementsPost(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "checkdataconnectorrequirements.CheckDataConnectorRequirementsClient", "DataConnectorsCheckRequirementsPost", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDataConnectorsCheckRequirementsPost prepares the DataConnectorsCheckRequirementsPost request. -func (c CheckDataConnectorRequirementsClient) preparerForDataConnectorsCheckRequirementsPost(ctx context.Context, id WorkspaceId, input DataConnectorsCheckRequirements) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/dataConnectorsCheckRequirements", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDataConnectorsCheckRequirementsPost handles the response to the DataConnectorsCheckRequirementsPost request. The method always -// closes the http.Response Body. -func (c CheckDataConnectorRequirementsClient) responderForDataConnectorsCheckRequirementsPost(resp *http.Response) (result DataConnectorsCheckRequirementsPostOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/client.go b/resource-manager/securityinsights/2021-09-01-preview/client.go index 0687d4d793a..7e29cfaf20a 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/client.go +++ b/resource-manager/securityinsights/2021-09-01-preview/client.go @@ -4,7 +4,8 @@ package v2021_09_01_preview // Licensed under the MIT License. See NOTICE.txt in the project root for license information. import ( - "github.com/Azure/go-autorest/autorest" + "fmt" + "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2021-09-01-preview/actions" "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2021-09-01-preview/alertrules" "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2021-09-01-preview/alertruletemplates" @@ -38,6 +39,8 @@ import ( "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2021-09-01-preview/threatintelligence" "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2021-09-01-preview/watchlistitems" "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2021-09-01-preview/watchlists" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" ) type Client struct { @@ -76,140 +79,238 @@ type Client struct { Watchlists *watchlists.WatchlistsClient } -func NewClientWithBaseURI(endpoint string, configureAuthFunc func(c *autorest.Client)) Client { - - actionsClient := actions.NewActionsClientWithBaseURI(endpoint) - configureAuthFunc(&actionsClient.Client) - - alertRuleTemplatesClient := alertruletemplates.NewAlertRuleTemplatesClientWithBaseURI(endpoint) - configureAuthFunc(&alertRuleTemplatesClient.Client) +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + actionsClient, err := actions.NewActionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Actions client: %+v", err) + } + configureFunc(actionsClient.Client) - alertRulesClient := alertrules.NewAlertRulesClientWithBaseURI(endpoint) - configureAuthFunc(&alertRulesClient.Client) + alertRuleTemplatesClient, err := alertruletemplates.NewAlertRuleTemplatesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AlertRuleTemplates client: %+v", err) + } + configureFunc(alertRuleTemplatesClient.Client) - automationRuleClient := automationrule.NewAutomationRuleClientWithBaseURI(endpoint) - configureAuthFunc(&automationRuleClient.Client) + alertRulesClient, err := alertrules.NewAlertRulesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AlertRules client: %+v", err) + } + configureFunc(alertRulesClient.Client) - automationRulesClient := automationrules.NewAutomationRulesClientWithBaseURI(endpoint) - configureAuthFunc(&automationRulesClient.Client) + automationRuleClient, err := automationrule.NewAutomationRuleClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AutomationRule client: %+v", err) + } + configureFunc(automationRuleClient.Client) - bookmarkClient := bookmark.NewBookmarkClientWithBaseURI(endpoint) - configureAuthFunc(&bookmarkClient.Client) + automationRulesClient, err := automationrules.NewAutomationRulesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AutomationRules client: %+v", err) + } + configureFunc(automationRulesClient.Client) - bookmarkRelationsClient := bookmarkrelations.NewBookmarkRelationsClientWithBaseURI(endpoint) - configureAuthFunc(&bookmarkRelationsClient.Client) + bookmarkClient, err := bookmark.NewBookmarkClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Bookmark client: %+v", err) + } + configureFunc(bookmarkClient.Client) - bookmarksClient := bookmarks.NewBookmarksClientWithBaseURI(endpoint) - configureAuthFunc(&bookmarksClient.Client) + bookmarkRelationsClient, err := bookmarkrelations.NewBookmarkRelationsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building BookmarkRelations client: %+v", err) + } + configureFunc(bookmarkRelationsClient.Client) - checkDataConnectorRequirementsClient := checkdataconnectorrequirements.NewCheckDataConnectorRequirementsClientWithBaseURI(endpoint) - configureAuthFunc(&checkDataConnectorRequirementsClient.Client) + bookmarksClient, err := bookmarks.NewBookmarksClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Bookmarks client: %+v", err) + } + configureFunc(bookmarksClient.Client) - dataConnectorsClient := dataconnectors.NewDataConnectorsClientWithBaseURI(endpoint) - configureAuthFunc(&dataConnectorsClient.Client) + checkDataConnectorRequirementsClient, err := checkdataconnectorrequirements.NewCheckDataConnectorRequirementsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building CheckDataConnectorRequirements client: %+v", err) + } + configureFunc(checkDataConnectorRequirementsClient.Client) - dataConnectorsConnectClient := dataconnectorsconnect.NewDataConnectorsConnectClientWithBaseURI(endpoint) - configureAuthFunc(&dataConnectorsConnectClient.Client) + dataConnectorsClient, err := dataconnectors.NewDataConnectorsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DataConnectors client: %+v", err) + } + configureFunc(dataConnectorsClient.Client) - dataConnectorsDisconnectClient := dataconnectorsdisconnect.NewDataConnectorsDisconnectClientWithBaseURI(endpoint) - configureAuthFunc(&dataConnectorsDisconnectClient.Client) + dataConnectorsConnectClient, err := dataconnectorsconnect.NewDataConnectorsConnectClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DataConnectorsConnect client: %+v", err) + } + configureFunc(dataConnectorsConnectClient.Client) - enrichmentClient := enrichment.NewEnrichmentClientWithBaseURI(endpoint) - configureAuthFunc(&enrichmentClient.Client) + dataConnectorsDisconnectClient, err := dataconnectorsdisconnect.NewDataConnectorsDisconnectClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DataConnectorsDisconnect client: %+v", err) + } + configureFunc(dataConnectorsDisconnectClient.Client) - entitiesClient := entities.NewEntitiesClientWithBaseURI(endpoint) - configureAuthFunc(&entitiesClient.Client) + enrichmentClient, err := enrichment.NewEnrichmentClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Enrichment client: %+v", err) + } + configureFunc(enrichmentClient.Client) - entityQueriesClient := entityqueries.NewEntityQueriesClientWithBaseURI(endpoint) - configureAuthFunc(&entityQueriesClient.Client) + entitiesClient, err := entities.NewEntitiesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Entities client: %+v", err) + } + configureFunc(entitiesClient.Client) - entityRelationsClient := entityrelations.NewEntityRelationsClientWithBaseURI(endpoint) - configureAuthFunc(&entityRelationsClient.Client) + entityQueriesClient, err := entityqueries.NewEntityQueriesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building EntityQueries client: %+v", err) + } + configureFunc(entityQueriesClient.Client) - entityTypesClient := entitytypes.NewEntityTypesClientWithBaseURI(endpoint) - configureAuthFunc(&entityTypesClient.Client) + entityRelationsClient, err := entityrelations.NewEntityRelationsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building EntityRelations client: %+v", err) + } + configureFunc(entityRelationsClient.Client) - incidentAlertsClient := incidentalerts.NewIncidentAlertsClientWithBaseURI(endpoint) - configureAuthFunc(&incidentAlertsClient.Client) + entityTypesClient, err := entitytypes.NewEntityTypesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building EntityTypes client: %+v", err) + } + configureFunc(entityTypesClient.Client) - incidentBookmarksClient := incidentbookmarks.NewIncidentBookmarksClientWithBaseURI(endpoint) - configureAuthFunc(&incidentBookmarksClient.Client) + incidentAlertsClient, err := incidentalerts.NewIncidentAlertsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IncidentAlerts client: %+v", err) + } + configureFunc(incidentAlertsClient.Client) - incidentCommentsClient := incidentcomments.NewIncidentCommentsClientWithBaseURI(endpoint) - configureAuthFunc(&incidentCommentsClient.Client) + incidentBookmarksClient, err := incidentbookmarks.NewIncidentBookmarksClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IncidentBookmarks client: %+v", err) + } + configureFunc(incidentBookmarksClient.Client) - incidentEntitiesClient := incidententities.NewIncidentEntitiesClientWithBaseURI(endpoint) - configureAuthFunc(&incidentEntitiesClient.Client) + incidentCommentsClient, err := incidentcomments.NewIncidentCommentsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IncidentComments client: %+v", err) + } + configureFunc(incidentCommentsClient.Client) - incidentRelationsClient := incidentrelations.NewIncidentRelationsClientWithBaseURI(endpoint) - configureAuthFunc(&incidentRelationsClient.Client) + incidentEntitiesClient, err := incidententities.NewIncidentEntitiesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IncidentEntities client: %+v", err) + } + configureFunc(incidentEntitiesClient.Client) - incidentTeamClient := incidentteam.NewIncidentTeamClientWithBaseURI(endpoint) - configureAuthFunc(&incidentTeamClient.Client) + incidentRelationsClient, err := incidentrelations.NewIncidentRelationsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IncidentRelations client: %+v", err) + } + configureFunc(incidentRelationsClient.Client) - incidentsClient := incidents.NewIncidentsClientWithBaseURI(endpoint) - configureAuthFunc(&incidentsClient.Client) + incidentTeamClient, err := incidentteam.NewIncidentTeamClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IncidentTeam client: %+v", err) + } + configureFunc(incidentTeamClient.Client) - metadataClient := metadata.NewMetadataClientWithBaseURI(endpoint) - configureAuthFunc(&metadataClient.Client) + incidentsClient, err := incidents.NewIncidentsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Incidents client: %+v", err) + } + configureFunc(incidentsClient.Client) - officeConsentsClient := officeconsents.NewOfficeConsentsClientWithBaseURI(endpoint) - configureAuthFunc(&officeConsentsClient.Client) + metadataClient, err := metadata.NewMetadataClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Metadata client: %+v", err) + } + configureFunc(metadataClient.Client) - repositoriesClient := repositories.NewRepositoriesClientWithBaseURI(endpoint) - configureAuthFunc(&repositoriesClient.Client) + officeConsentsClient, err := officeconsents.NewOfficeConsentsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building OfficeConsents client: %+v", err) + } + configureFunc(officeConsentsClient.Client) - sentinelOnboardingStatesClient := sentinelonboardingstates.NewSentinelOnboardingStatesClientWithBaseURI(endpoint) - configureAuthFunc(&sentinelOnboardingStatesClient.Client) + repositoriesClient, err := repositories.NewRepositoriesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Repositories client: %+v", err) + } + configureFunc(repositoriesClient.Client) - settingsClient := settings.NewSettingsClientWithBaseURI(endpoint) - configureAuthFunc(&settingsClient.Client) + sentinelOnboardingStatesClient, err := sentinelonboardingstates.NewSentinelOnboardingStatesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SentinelOnboardingStates client: %+v", err) + } + configureFunc(sentinelOnboardingStatesClient.Client) - sourceControlsClient := sourcecontrols.NewSourceControlsClientWithBaseURI(endpoint) - configureAuthFunc(&sourceControlsClient.Client) + settingsClient, err := settings.NewSettingsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Settings client: %+v", err) + } + configureFunc(settingsClient.Client) - threatIntelligenceClient := threatintelligence.NewThreatIntelligenceClientWithBaseURI(endpoint) - configureAuthFunc(&threatIntelligenceClient.Client) + sourceControlsClient, err := sourcecontrols.NewSourceControlsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SourceControls client: %+v", err) + } + configureFunc(sourceControlsClient.Client) - watchlistItemsClient := watchlistitems.NewWatchlistItemsClientWithBaseURI(endpoint) - configureAuthFunc(&watchlistItemsClient.Client) + threatIntelligenceClient, err := threatintelligence.NewThreatIntelligenceClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ThreatIntelligence client: %+v", err) + } + configureFunc(threatIntelligenceClient.Client) - watchlistsClient := watchlists.NewWatchlistsClientWithBaseURI(endpoint) - configureAuthFunc(&watchlistsClient.Client) + watchlistItemsClient, err := watchlistitems.NewWatchlistItemsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building WatchlistItems client: %+v", err) + } + configureFunc(watchlistItemsClient.Client) - return Client{ - Actions: &actionsClient, - AlertRuleTemplates: &alertRuleTemplatesClient, - AlertRules: &alertRulesClient, - AutomationRule: &automationRuleClient, - AutomationRules: &automationRulesClient, - Bookmark: &bookmarkClient, - BookmarkRelations: &bookmarkRelationsClient, - Bookmarks: &bookmarksClient, - CheckDataConnectorRequirements: &checkDataConnectorRequirementsClient, - DataConnectors: &dataConnectorsClient, - DataConnectorsConnect: &dataConnectorsConnectClient, - DataConnectorsDisconnect: &dataConnectorsDisconnectClient, - Enrichment: &enrichmentClient, - Entities: &entitiesClient, - EntityQueries: &entityQueriesClient, - EntityRelations: &entityRelationsClient, - EntityTypes: &entityTypesClient, - IncidentAlerts: &incidentAlertsClient, - IncidentBookmarks: &incidentBookmarksClient, - IncidentComments: &incidentCommentsClient, - IncidentEntities: &incidentEntitiesClient, - IncidentRelations: &incidentRelationsClient, - IncidentTeam: &incidentTeamClient, - Incidents: &incidentsClient, - Metadata: &metadataClient, - OfficeConsents: &officeConsentsClient, - Repositories: &repositoriesClient, - SentinelOnboardingStates: &sentinelOnboardingStatesClient, - Settings: &settingsClient, - SourceControls: &sourceControlsClient, - ThreatIntelligence: &threatIntelligenceClient, - WatchlistItems: &watchlistItemsClient, - Watchlists: &watchlistsClient, + watchlistsClient, err := watchlists.NewWatchlistsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Watchlists client: %+v", err) } + configureFunc(watchlistsClient.Client) + + return &Client{ + Actions: actionsClient, + AlertRuleTemplates: alertRuleTemplatesClient, + AlertRules: alertRulesClient, + AutomationRule: automationRuleClient, + AutomationRules: automationRulesClient, + Bookmark: bookmarkClient, + BookmarkRelations: bookmarkRelationsClient, + Bookmarks: bookmarksClient, + CheckDataConnectorRequirements: checkDataConnectorRequirementsClient, + DataConnectors: dataConnectorsClient, + DataConnectorsConnect: dataConnectorsConnectClient, + DataConnectorsDisconnect: dataConnectorsDisconnectClient, + Enrichment: enrichmentClient, + Entities: entitiesClient, + EntityQueries: entityQueriesClient, + EntityRelations: entityRelationsClient, + EntityTypes: entityTypesClient, + IncidentAlerts: incidentAlertsClient, + IncidentBookmarks: incidentBookmarksClient, + IncidentComments: incidentCommentsClient, + IncidentEntities: incidentEntitiesClient, + IncidentRelations: incidentRelationsClient, + IncidentTeam: incidentTeamClient, + Incidents: incidentsClient, + Metadata: metadataClient, + OfficeConsents: officeConsentsClient, + Repositories: repositoriesClient, + SentinelOnboardingStates: sentinelOnboardingStatesClient, + Settings: settingsClient, + SourceControls: sourceControlsClient, + ThreatIntelligence: threatIntelligenceClient, + WatchlistItems: watchlistItemsClient, + Watchlists: watchlistsClient, + }, nil } diff --git a/resource-manager/securityinsights/2021-09-01-preview/dataconnectors/client.go b/resource-manager/securityinsights/2021-09-01-preview/dataconnectors/client.go index cf334b72568..8ed0120c79a 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/dataconnectors/client.go +++ b/resource-manager/securityinsights/2021-09-01-preview/dataconnectors/client.go @@ -1,18 +1,26 @@ package dataconnectors -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type DataConnectorsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewDataConnectorsClientWithBaseURI(endpoint string) DataConnectorsClient { - return DataConnectorsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewDataConnectorsClientWithBaseURI(sdkApi sdkEnv.Api) (*DataConnectorsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "dataconnectors", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DataConnectorsClient: %+v", err) } + + return &DataConnectorsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2021-09-01-preview/dataconnectors/constants.go b/resource-manager/securityinsights/2021-09-01-preview/dataconnectors/constants.go index 79d9f8419f4..27970b1a0d1 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/dataconnectors/constants.go +++ b/resource-manager/securityinsights/2021-09-01-preview/dataconnectors/constants.go @@ -1,6 +1,10 @@ package dataconnectors -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -29,6 +33,19 @@ func PossibleValuesForConnectivityType() []string { } } +func (s *ConnectivityType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConnectivityType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConnectivityType(input string) (*ConnectivityType, error) { vals := map[string]ConnectivityType{ "isconnectedquery": ConnectivityTypeIsConnectedQuery, @@ -86,6 +103,19 @@ func PossibleValuesForDataConnectorKind() []string { } } +func (s *DataConnectorKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataConnectorKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDataConnectorKind(input string) (*DataConnectorKind, error) { vals := map[string]DataConnectorKind{ "apipolling": DataConnectorKindAPIPolling, @@ -129,6 +159,19 @@ func PossibleValuesForDataTypeState() []string { } } +func (s *DataTypeState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataTypeState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDataTypeState(input string) (*DataTypeState, error) { vals := map[string]DataTypeState{ "disabled": DataTypeStateDisabled, @@ -159,6 +202,19 @@ func PossibleValuesForPermissionProviderScope() []string { } } +func (s *PermissionProviderScope) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePermissionProviderScope(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parsePermissionProviderScope(input string) (*PermissionProviderScope, error) { vals := map[string]PermissionProviderScope{ "resourcegroup": PermissionProviderScopeResourceGroup, @@ -190,6 +246,19 @@ func PossibleValuesForPollingFrequency() []string { } } +func (s *PollingFrequency) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePollingFrequency(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parsePollingFrequency(input string) (*PollingFrequency, error) { vals := map[string]PollingFrequency{ "onceaday": PollingFrequencyOnceADay, @@ -227,6 +296,19 @@ func PossibleValuesForProviderName() []string { } } +func (s *ProviderName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProviderName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseProviderName(input string) (*ProviderName, error) { vals := map[string]ProviderName{ "microsoft.authorization/policyassignments": ProviderNameMicrosoftPointAuthorizationPolicyAssignments, @@ -261,6 +343,19 @@ func PossibleValuesForSettingType() []string { } } +func (s *SettingType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSettingType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSettingType(input string) (*SettingType, error) { vals := map[string]SettingType{ "copyablelabel": SettingTypeCopyableLabel, diff --git a/resource-manager/securityinsights/2021-09-01-preview/dataconnectors/method_createorupdate.go b/resource-manager/securityinsights/2021-09-01-preview/dataconnectors/method_createorupdate.go new file mode 100644 index 00000000000..c5f6e5d1503 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/dataconnectors/method_createorupdate.go @@ -0,0 +1,63 @@ +package dataconnectors + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DataConnector +} + +// CreateOrUpdate ... +func (c DataConnectorsClient) CreateOrUpdate(ctx context.Context, id DataConnectorId, input DataConnector) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalDataConnectorImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/dataconnectors/method_createorupdate_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/dataconnectors/method_createorupdate_autorest.go deleted file mode 100644 index 1f259eca36c..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/dataconnectors/method_createorupdate_autorest.go +++ /dev/null @@ -1,78 +0,0 @@ -package dataconnectors - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *DataConnector -} - -// CreateOrUpdate ... -func (c DataConnectorsClient) CreateOrUpdate(ctx context.Context, id DataConnectorId, input DataConnector) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c DataConnectorsClient) preparerForCreateOrUpdate(ctx context.Context, id DataConnectorId, input DataConnector) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c DataConnectorsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalDataConnectorImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/dataconnectors/method_delete.go b/resource-manager/securityinsights/2021-09-01-preview/dataconnectors/method_delete.go new file mode 100644 index 00000000000..8461ec6d8a1 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/dataconnectors/method_delete.go @@ -0,0 +1,47 @@ +package dataconnectors + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c DataConnectorsClient) Delete(ctx context.Context, id DataConnectorId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/dataconnectors/method_delete_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/dataconnectors/method_delete_autorest.go deleted file mode 100644 index ac4ddf57441..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/dataconnectors/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package dataconnectors - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c DataConnectorsClient) Delete(ctx context.Context, id DataConnectorId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c DataConnectorsClient) preparerForDelete(ctx context.Context, id DataConnectorId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c DataConnectorsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/dataconnectors/method_get.go b/resource-manager/securityinsights/2021-09-01-preview/dataconnectors/method_get.go new file mode 100644 index 00000000000..3511ba85477 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/dataconnectors/method_get.go @@ -0,0 +1,58 @@ +package dataconnectors + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DataConnector +} + +// Get ... +func (c DataConnectorsClient) Get(ctx context.Context, id DataConnectorId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalDataConnectorImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/dataconnectors/method_get_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/dataconnectors/method_get_autorest.go deleted file mode 100644 index af56be19c9c..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/dataconnectors/method_get_autorest.go +++ /dev/null @@ -1,77 +0,0 @@ -package dataconnectors - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *DataConnector -} - -// Get ... -func (c DataConnectorsClient) Get(ctx context.Context, id DataConnectorId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c DataConnectorsClient) preparerForGet(ctx context.Context, id DataConnectorId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c DataConnectorsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalDataConnectorImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/dataconnectors/method_list.go b/resource-manager/securityinsights/2021-09-01-preview/dataconnectors/method_list.go new file mode 100644 index 00000000000..6975384fdee --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/dataconnectors/method_list.go @@ -0,0 +1,103 @@ +package dataconnectors + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DataConnector +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []DataConnector +} + +// List ... +func (c DataConnectorsClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/dataConnectors", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]DataConnector, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalDataConnectorImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for DataConnector (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// ListComplete retrieves all the results into a single object +func (c DataConnectorsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, DataConnectorOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DataConnectorsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate DataConnectorOperationPredicate) (result ListCompleteResult, err error) { + items := make([]DataConnector, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/dataconnectors/method_list_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/dataconnectors/method_list_autorest.go deleted file mode 100644 index e08d153a6eb..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/dataconnectors/method_list_autorest.go +++ /dev/null @@ -1,196 +0,0 @@ -package dataconnectors - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]DataConnector - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []DataConnector -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c DataConnectorsClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c DataConnectorsClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/dataConnectors", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c DataConnectorsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c DataConnectorsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]DataConnector, 0) - for i, v := range respObj.Values { - val, err := unmarshalDataConnectorImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for DataConnector (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c DataConnectorsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, DataConnectorOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c DataConnectorsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate DataConnectorOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]DataConnector, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/dataconnectorsconnect/client.go b/resource-manager/securityinsights/2021-09-01-preview/dataconnectorsconnect/client.go index dd44f929cc5..f4ed6b1fb50 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/dataconnectorsconnect/client.go +++ b/resource-manager/securityinsights/2021-09-01-preview/dataconnectorsconnect/client.go @@ -1,18 +1,26 @@ package dataconnectorsconnect -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type DataConnectorsConnectClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewDataConnectorsConnectClientWithBaseURI(endpoint string) DataConnectorsConnectClient { - return DataConnectorsConnectClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewDataConnectorsConnectClientWithBaseURI(sdkApi sdkEnv.Api) (*DataConnectorsConnectClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "dataconnectorsconnect", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DataConnectorsConnectClient: %+v", err) } + + return &DataConnectorsConnectClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2021-09-01-preview/dataconnectorsconnect/constants.go b/resource-manager/securityinsights/2021-09-01-preview/dataconnectorsconnect/constants.go index 04ec07ac553..a5b7f1713ca 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/dataconnectorsconnect/constants.go +++ b/resource-manager/securityinsights/2021-09-01-preview/dataconnectorsconnect/constants.go @@ -1,6 +1,10 @@ package dataconnectorsconnect -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -21,6 +25,19 @@ func PossibleValuesForConnectAuthKind() []string { } } +func (s *ConnectAuthKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConnectAuthKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConnectAuthKind(input string) (*ConnectAuthKind, error) { vals := map[string]ConnectAuthKind{ "apikey": ConnectAuthKindAPIKey, diff --git a/resource-manager/securityinsights/2021-09-01-preview/dataconnectorsconnect/method_dataconnectorsconnect.go b/resource-manager/securityinsights/2021-09-01-preview/dataconnectorsconnect/method_dataconnectorsconnect.go new file mode 100644 index 00000000000..50018e5b900 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/dataconnectorsconnect/method_dataconnectorsconnect.go @@ -0,0 +1,51 @@ +package dataconnectorsconnect + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataConnectorsConnectOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// DataConnectorsConnect ... +func (c DataConnectorsConnectClient) DataConnectorsConnect(ctx context.Context, id DataConnectorId, input DataConnectorConnectBody) (result DataConnectorsConnectOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/connect", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/dataconnectorsconnect/method_dataconnectorsconnect_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/dataconnectorsconnect/method_dataconnectorsconnect_autorest.go deleted file mode 100644 index 191360dda4c..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/dataconnectorsconnect/method_dataconnectorsconnect_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package dataconnectorsconnect - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DataConnectorsConnectOperationResponse struct { - HttpResponse *http.Response -} - -// DataConnectorsConnect ... -func (c DataConnectorsConnectClient) DataConnectorsConnect(ctx context.Context, id DataConnectorId, input DataConnectorConnectBody) (result DataConnectorsConnectOperationResponse, err error) { - req, err := c.preparerForDataConnectorsConnect(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectorsconnect.DataConnectorsConnectClient", "DataConnectorsConnect", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectorsconnect.DataConnectorsConnectClient", "DataConnectorsConnect", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDataConnectorsConnect(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectorsconnect.DataConnectorsConnectClient", "DataConnectorsConnect", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDataConnectorsConnect prepares the DataConnectorsConnect request. -func (c DataConnectorsConnectClient) preparerForDataConnectorsConnect(ctx context.Context, id DataConnectorId, input DataConnectorConnectBody) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/connect", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDataConnectorsConnect handles the response to the DataConnectorsConnect request. The method always -// closes the http.Response Body. -func (c DataConnectorsConnectClient) responderForDataConnectorsConnect(resp *http.Response) (result DataConnectorsConnectOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/dataconnectorsdisconnect/client.go b/resource-manager/securityinsights/2021-09-01-preview/dataconnectorsdisconnect/client.go index cd8304c370a..57ec64abb3c 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/dataconnectorsdisconnect/client.go +++ b/resource-manager/securityinsights/2021-09-01-preview/dataconnectorsdisconnect/client.go @@ -1,18 +1,26 @@ package dataconnectorsdisconnect -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type DataConnectorsDisconnectClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewDataConnectorsDisconnectClientWithBaseURI(endpoint string) DataConnectorsDisconnectClient { - return DataConnectorsDisconnectClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewDataConnectorsDisconnectClientWithBaseURI(sdkApi sdkEnv.Api) (*DataConnectorsDisconnectClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "dataconnectorsdisconnect", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DataConnectorsDisconnectClient: %+v", err) } + + return &DataConnectorsDisconnectClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2021-09-01-preview/dataconnectorsdisconnect/method_dataconnectorsdisconnect.go b/resource-manager/securityinsights/2021-09-01-preview/dataconnectorsdisconnect/method_dataconnectorsdisconnect.go new file mode 100644 index 00000000000..2a883a2c958 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/dataconnectorsdisconnect/method_dataconnectorsdisconnect.go @@ -0,0 +1,47 @@ +package dataconnectorsdisconnect + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataConnectorsDisconnectOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// DataConnectorsDisconnect ... +func (c DataConnectorsDisconnectClient) DataConnectorsDisconnect(ctx context.Context, id DataConnectorId) (result DataConnectorsDisconnectOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/disconnect", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/dataconnectorsdisconnect/method_dataconnectorsdisconnect_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/dataconnectorsdisconnect/method_dataconnectorsdisconnect_autorest.go deleted file mode 100644 index 61c1f036044..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/dataconnectorsdisconnect/method_dataconnectorsdisconnect_autorest.go +++ /dev/null @@ -1,67 +0,0 @@ -package dataconnectorsdisconnect - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DataConnectorsDisconnectOperationResponse struct { - HttpResponse *http.Response -} - -// DataConnectorsDisconnect ... -func (c DataConnectorsDisconnectClient) DataConnectorsDisconnect(ctx context.Context, id DataConnectorId) (result DataConnectorsDisconnectOperationResponse, err error) { - req, err := c.preparerForDataConnectorsDisconnect(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectorsdisconnect.DataConnectorsDisconnectClient", "DataConnectorsDisconnect", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectorsdisconnect.DataConnectorsDisconnectClient", "DataConnectorsDisconnect", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDataConnectorsDisconnect(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectorsdisconnect.DataConnectorsDisconnectClient", "DataConnectorsDisconnect", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDataConnectorsDisconnect prepares the DataConnectorsDisconnect request. -func (c DataConnectorsDisconnectClient) preparerForDataConnectorsDisconnect(ctx context.Context, id DataConnectorId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/disconnect", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDataConnectorsDisconnect handles the response to the DataConnectorsDisconnect request. The method always -// closes the http.Response Body. -func (c DataConnectorsDisconnectClient) responderForDataConnectorsDisconnect(resp *http.Response) (result DataConnectorsDisconnectOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/enrichment/client.go b/resource-manager/securityinsights/2021-09-01-preview/enrichment/client.go index 86c852a64d4..f60a3bef882 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/enrichment/client.go +++ b/resource-manager/securityinsights/2021-09-01-preview/enrichment/client.go @@ -1,18 +1,26 @@ package enrichment -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type EnrichmentClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewEnrichmentClientWithBaseURI(endpoint string) EnrichmentClient { - return EnrichmentClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewEnrichmentClientWithBaseURI(sdkApi sdkEnv.Api) (*EnrichmentClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "enrichment", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating EnrichmentClient: %+v", err) } + + return &EnrichmentClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2021-09-01-preview/enrichment/method_domainwhoisget.go b/resource-manager/securityinsights/2021-09-01-preview/enrichment/method_domainwhoisget.go new file mode 100644 index 00000000000..5598e43044b --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/enrichment/method_domainwhoisget.go @@ -0,0 +1,81 @@ +package enrichment + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DomainWhoisGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EnrichmentDomainWhois +} + +type DomainWhoisGetOperationOptions struct { + Domain *string +} + +func DefaultDomainWhoisGetOperationOptions() DomainWhoisGetOperationOptions { + return DomainWhoisGetOperationOptions{} +} + +func (o DomainWhoisGetOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o DomainWhoisGetOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DomainWhoisGetOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Domain != nil { + out.Append("domain", fmt.Sprintf("%v", *o.Domain)) + } + return &out +} + +// DomainWhoisGet ... +func (c EnrichmentClient) DomainWhoisGet(ctx context.Context, id commonids.ResourceGroupId, options DomainWhoisGetOperationOptions) (result DomainWhoisGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/enrichment/domain/whois", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/enrichment/method_domainwhoisget_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/enrichment/method_domainwhoisget_autorest.go deleted file mode 100644 index 1e0a9800903..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/enrichment/method_domainwhoisget_autorest.go +++ /dev/null @@ -1,99 +0,0 @@ -package enrichment - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DomainWhoisGetOperationResponse struct { - HttpResponse *http.Response - Model *EnrichmentDomainWhois -} - -type DomainWhoisGetOperationOptions struct { - Domain *string -} - -func DefaultDomainWhoisGetOperationOptions() DomainWhoisGetOperationOptions { - return DomainWhoisGetOperationOptions{} -} - -func (o DomainWhoisGetOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o DomainWhoisGetOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Domain != nil { - out["domain"] = *o.Domain - } - - return out -} - -// DomainWhoisGet ... -func (c EnrichmentClient) DomainWhoisGet(ctx context.Context, id commonids.ResourceGroupId, options DomainWhoisGetOperationOptions) (result DomainWhoisGetOperationResponse, err error) { - req, err := c.preparerForDomainWhoisGet(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "enrichment.EnrichmentClient", "DomainWhoisGet", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "enrichment.EnrichmentClient", "DomainWhoisGet", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDomainWhoisGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "enrichment.EnrichmentClient", "DomainWhoisGet", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDomainWhoisGet prepares the DomainWhoisGet request. -func (c EnrichmentClient) preparerForDomainWhoisGet(ctx context.Context, id commonids.ResourceGroupId, options DomainWhoisGetOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/enrichment/domain/whois", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDomainWhoisGet handles the response to the DomainWhoisGet request. The method always -// closes the http.Response Body. -func (c EnrichmentClient) responderForDomainWhoisGet(resp *http.Response) (result DomainWhoisGetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/enrichment/method_ipgeodataget.go b/resource-manager/securityinsights/2021-09-01-preview/enrichment/method_ipgeodataget.go new file mode 100644 index 00000000000..05e73d79b5c --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/enrichment/method_ipgeodataget.go @@ -0,0 +1,81 @@ +package enrichment + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IPGeodataGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EnrichmentIPGeodata +} + +type IPGeodataGetOperationOptions struct { + IPAddress *string +} + +func DefaultIPGeodataGetOperationOptions() IPGeodataGetOperationOptions { + return IPGeodataGetOperationOptions{} +} + +func (o IPGeodataGetOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o IPGeodataGetOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o IPGeodataGetOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.IPAddress != nil { + out.Append("ipAddress", fmt.Sprintf("%v", *o.IPAddress)) + } + return &out +} + +// IPGeodataGet ... +func (c EnrichmentClient) IPGeodataGet(ctx context.Context, id commonids.ResourceGroupId, options IPGeodataGetOperationOptions) (result IPGeodataGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/enrichment/ip/geodata", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/enrichment/method_ipgeodataget_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/enrichment/method_ipgeodataget_autorest.go deleted file mode 100644 index 8c489e6da71..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/enrichment/method_ipgeodataget_autorest.go +++ /dev/null @@ -1,99 +0,0 @@ -package enrichment - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IPGeodataGetOperationResponse struct { - HttpResponse *http.Response - Model *EnrichmentIPGeodata -} - -type IPGeodataGetOperationOptions struct { - IPAddress *string -} - -func DefaultIPGeodataGetOperationOptions() IPGeodataGetOperationOptions { - return IPGeodataGetOperationOptions{} -} - -func (o IPGeodataGetOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o IPGeodataGetOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.IPAddress != nil { - out["ipAddress"] = *o.IPAddress - } - - return out -} - -// IPGeodataGet ... -func (c EnrichmentClient) IPGeodataGet(ctx context.Context, id commonids.ResourceGroupId, options IPGeodataGetOperationOptions) (result IPGeodataGetOperationResponse, err error) { - req, err := c.preparerForIPGeodataGet(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "enrichment.EnrichmentClient", "IPGeodataGet", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "enrichment.EnrichmentClient", "IPGeodataGet", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIPGeodataGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "enrichment.EnrichmentClient", "IPGeodataGet", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIPGeodataGet prepares the IPGeodataGet request. -func (c EnrichmentClient) preparerForIPGeodataGet(ctx context.Context, id commonids.ResourceGroupId, options IPGeodataGetOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/enrichment/ip/geodata", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIPGeodataGet handles the response to the IPGeodataGet request. The method always -// closes the http.Response Body. -func (c EnrichmentClient) responderForIPGeodataGet(resp *http.Response) (result IPGeodataGetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/entities/client.go b/resource-manager/securityinsights/2021-09-01-preview/entities/client.go index c9a2f082154..69f26c8d7e5 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/entities/client.go +++ b/resource-manager/securityinsights/2021-09-01-preview/entities/client.go @@ -1,18 +1,26 @@ package entities -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type EntitiesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewEntitiesClientWithBaseURI(endpoint string) EntitiesClient { - return EntitiesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewEntitiesClientWithBaseURI(sdkApi sdkEnv.Api) (*EntitiesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "entities", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating EntitiesClient: %+v", err) } + + return &EntitiesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2021-09-01-preview/entities/constants.go b/resource-manager/securityinsights/2021-09-01-preview/entities/constants.go index 953f8b7460b..ff63a867e77 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/entities/constants.go +++ b/resource-manager/securityinsights/2021-09-01-preview/entities/constants.go @@ -1,6 +1,10 @@ package entities -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -23,6 +27,19 @@ func PossibleValuesForAlertSeverity() []string { } } +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertSeverity(input string) (*AlertSeverity, error) { vals := map[string]AlertSeverity{ "high": AlertSeverityHigh, @@ -51,6 +68,19 @@ func PossibleValuesForEntityItemQueryKind() []string { } } +func (s *EntityItemQueryKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityItemQueryKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityItemQueryKind(input string) (*EntityItemQueryKind, error) { vals := map[string]EntityItemQueryKind{ "insight": EntityItemQueryKindInsight, @@ -116,6 +146,19 @@ func PossibleValuesForEntityKind() []string { } } +func (s *EntityKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityKind(input string) (*EntityKind, error) { vals := map[string]EntityKind{ "account": EntityKindAccount, @@ -165,6 +208,19 @@ func PossibleValuesForEntityQueryKind() []string { } } +func (s *EntityQueryKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityQueryKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityQueryKind(input string) (*EntityQueryKind, error) { vals := map[string]EntityQueryKind{ "activity": EntityQueryKindActivity, @@ -196,6 +252,19 @@ func PossibleValuesForEntityTimelineKind() []string { } } +func (s *EntityTimelineKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityTimelineKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityTimelineKind(input string) (*EntityTimelineKind, error) { vals := map[string]EntityTimelineKind{ "activity": EntityTimelineKindActivity, @@ -263,6 +332,19 @@ func PossibleValuesForEntityType() []string { } } +func (s *EntityType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityType(input string) (*EntityType, error) { vals := map[string]EntityType{ "account": EntityTypeAccount, @@ -308,6 +390,19 @@ func PossibleValuesForKind() []string { } } +func (s *Kind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseKind(input string) (*Kind, error) { vals := map[string]Kind{ "insight": KindInsight, @@ -339,6 +434,19 @@ func PossibleValuesForOutputType() []string { } } +func (s *OutputType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOutputType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseOutputType(input string) (*OutputType, error) { vals := map[string]OutputType{ "date": OutputTypeDate, diff --git a/resource-manager/securityinsights/2021-09-01-preview/entities/method_expand.go b/resource-manager/securityinsights/2021-09-01-preview/entities/method_expand.go new file mode 100644 index 00000000000..4a41d4bd23a --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/entities/method_expand.go @@ -0,0 +1,56 @@ +package entities + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExpandOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EntityExpandResponse +} + +// Expand ... +func (c EntitiesClient) Expand(ctx context.Context, id EntityId, input EntityExpandParameters) (result ExpandOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/expand", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/entities/method_expand_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/entities/method_expand_autorest.go deleted file mode 100644 index 3b993d594dc..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/entities/method_expand_autorest.go +++ /dev/null @@ -1,70 +0,0 @@ -package entities - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ExpandOperationResponse struct { - HttpResponse *http.Response - Model *EntityExpandResponse -} - -// Expand ... -func (c EntitiesClient) Expand(ctx context.Context, id EntityId, input EntityExpandParameters) (result ExpandOperationResponse, err error) { - req, err := c.preparerForExpand(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "Expand", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "Expand", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForExpand(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "Expand", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForExpand prepares the Expand request. -func (c EntitiesClient) preparerForExpand(ctx context.Context, id EntityId, input EntityExpandParameters) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/expand", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForExpand handles the response to the Expand request. The method always -// closes the http.Response Body. -func (c EntitiesClient) responderForExpand(resp *http.Response) (result ExpandOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/entities/method_get.go b/resource-manager/securityinsights/2021-09-01-preview/entities/method_get.go new file mode 100644 index 00000000000..e3ea4abfc78 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/entities/method_get.go @@ -0,0 +1,51 @@ +package entities + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Entity +} + +// Get ... +func (c EntitiesClient) Get(ctx context.Context, id EntityId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/entities/method_get_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/entities/method_get_autorest.go deleted file mode 100644 index d77e86bbcb4..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/entities/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package entities - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *Entity -} - -// Get ... -func (c EntitiesClient) Get(ctx context.Context, id EntityId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c EntitiesClient) preparerForGet(ctx context.Context, id EntityId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c EntitiesClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/entities/method_getinsights.go b/resource-manager/securityinsights/2021-09-01-preview/entities/method_getinsights.go new file mode 100644 index 00000000000..d1422bda1ec --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/entities/method_getinsights.go @@ -0,0 +1,56 @@ +package entities + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetInsightsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EntityGetInsightsResponse +} + +// GetInsights ... +func (c EntitiesClient) GetInsights(ctx context.Context, id EntityId, input EntityGetInsightsParameters) (result GetInsightsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/getInsights", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/entities/method_getinsights_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/entities/method_getinsights_autorest.go deleted file mode 100644 index c3ae3a1ab75..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/entities/method_getinsights_autorest.go +++ /dev/null @@ -1,70 +0,0 @@ -package entities - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetInsightsOperationResponse struct { - HttpResponse *http.Response - Model *EntityGetInsightsResponse -} - -// GetInsights ... -func (c EntitiesClient) GetInsights(ctx context.Context, id EntityId, input EntityGetInsightsParameters) (result GetInsightsOperationResponse, err error) { - req, err := c.preparerForGetInsights(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "GetInsights", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "GetInsights", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGetInsights(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "GetInsights", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGetInsights prepares the GetInsights request. -func (c EntitiesClient) preparerForGetInsights(ctx context.Context, id EntityId, input EntityGetInsightsParameters) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/getInsights", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGetInsights handles the response to the GetInsights request. The method always -// closes the http.Response Body. -func (c EntitiesClient) responderForGetInsights(resp *http.Response) (result GetInsightsOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/entities/method_gettimelinelist.go b/resource-manager/securityinsights/2021-09-01-preview/entities/method_gettimelinelist.go new file mode 100644 index 00000000000..46c6b6cba26 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/entities/method_gettimelinelist.go @@ -0,0 +1,56 @@ +package entities + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetTimelinelistOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EntityTimelineResponse +} + +// GetTimelinelist ... +func (c EntitiesClient) GetTimelinelist(ctx context.Context, id EntityId, input EntityTimelineParameters) (result GetTimelinelistOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/getTimeline", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/entities/method_gettimelinelist_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/entities/method_gettimelinelist_autorest.go deleted file mode 100644 index e04da4a2b55..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/entities/method_gettimelinelist_autorest.go +++ /dev/null @@ -1,70 +0,0 @@ -package entities - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetTimelinelistOperationResponse struct { - HttpResponse *http.Response - Model *EntityTimelineResponse -} - -// GetTimelinelist ... -func (c EntitiesClient) GetTimelinelist(ctx context.Context, id EntityId, input EntityTimelineParameters) (result GetTimelinelistOperationResponse, err error) { - req, err := c.preparerForGetTimelinelist(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "GetTimelinelist", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "GetTimelinelist", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGetTimelinelist(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "GetTimelinelist", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGetTimelinelist prepares the GetTimelinelist request. -func (c EntitiesClient) preparerForGetTimelinelist(ctx context.Context, id EntityId, input EntityTimelineParameters) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/getTimeline", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGetTimelinelist handles the response to the GetTimelinelist request. The method always -// closes the http.Response Body. -func (c EntitiesClient) responderForGetTimelinelist(resp *http.Response) (result GetTimelinelistOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/entities/method_list.go b/resource-manager/securityinsights/2021-09-01-preview/entities/method_list.go new file mode 100644 index 00000000000..7bd410bbfb5 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/entities/method_list.go @@ -0,0 +1,91 @@ +package entities + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Entity +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Entity +} + +// List ... +func (c EntitiesClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/entities", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Entity `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c EntitiesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, EntityOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c EntitiesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate EntityOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Entity, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/entities/method_list_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/entities/method_list_autorest.go deleted file mode 100644 index 198d6f95594..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/entities/method_list_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package entities - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]Entity - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []Entity -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c EntitiesClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c EntitiesClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/entities", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c EntitiesClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c EntitiesClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []Entity `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c EntitiesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, EntityOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c EntitiesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate EntityOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]Entity, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/entities/method_queries.go b/resource-manager/securityinsights/2021-09-01-preview/entities/method_queries.go new file mode 100644 index 00000000000..ec05d3bd90a --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/entities/method_queries.go @@ -0,0 +1,80 @@ +package entities + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QueriesOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *GetQueriesResponse +} + +type QueriesOperationOptions struct { + Kind *EntityItemQueryKind +} + +func DefaultQueriesOperationOptions() QueriesOperationOptions { + return QueriesOperationOptions{} +} + +func (o QueriesOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o QueriesOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o QueriesOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Kind != nil { + out.Append("kind", fmt.Sprintf("%v", *o.Kind)) + } + return &out +} + +// Queries ... +func (c EntitiesClient) Queries(ctx context.Context, id EntityId, options QueriesOperationOptions) (result QueriesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/queries", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/entities/method_queries_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/entities/method_queries_autorest.go deleted file mode 100644 index 44f69f71e09..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/entities/method_queries_autorest.go +++ /dev/null @@ -1,98 +0,0 @@ -package entities - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type QueriesOperationResponse struct { - HttpResponse *http.Response - Model *GetQueriesResponse -} - -type QueriesOperationOptions struct { - Kind *EntityItemQueryKind -} - -func DefaultQueriesOperationOptions() QueriesOperationOptions { - return QueriesOperationOptions{} -} - -func (o QueriesOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o QueriesOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Kind != nil { - out["kind"] = *o.Kind - } - - return out -} - -// Queries ... -func (c EntitiesClient) Queries(ctx context.Context, id EntityId, options QueriesOperationOptions) (result QueriesOperationResponse, err error) { - req, err := c.preparerForQueries(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "Queries", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "Queries", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForQueries(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "Queries", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForQueries prepares the Queries request. -func (c EntitiesClient) preparerForQueries(ctx context.Context, id EntityId, options QueriesOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/queries", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForQueries handles the response to the Queries request. The method always -// closes the http.Response Body. -func (c EntitiesClient) responderForQueries(resp *http.Response) (result QueriesOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/entityqueries/client.go b/resource-manager/securityinsights/2021-09-01-preview/entityqueries/client.go index a85c205dbc4..4a7620bff39 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/entityqueries/client.go +++ b/resource-manager/securityinsights/2021-09-01-preview/entityqueries/client.go @@ -1,18 +1,26 @@ package entityqueries -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type EntityQueriesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewEntityQueriesClientWithBaseURI(endpoint string) EntityQueriesClient { - return EntityQueriesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewEntityQueriesClientWithBaseURI(sdkApi sdkEnv.Api) (*EntityQueriesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "entityqueries", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating EntityQueriesClient: %+v", err) } + + return &EntityQueriesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2021-09-01-preview/entityqueries/constants.go b/resource-manager/securityinsights/2021-09-01-preview/entityqueries/constants.go index c8c5f73ee48..40a5a40396d 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/entityqueries/constants.go +++ b/resource-manager/securityinsights/2021-09-01-preview/entityqueries/constants.go @@ -1,6 +1,10 @@ package entityqueries -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -17,6 +21,19 @@ func PossibleValuesForCustomEntityQueryKind() []string { } } +func (s *CustomEntityQueryKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCustomEntityQueryKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseCustomEntityQueryKind(input string) (*CustomEntityQueryKind, error) { vals := map[string]CustomEntityQueryKind{ "activity": CustomEntityQueryKindActivity, @@ -46,6 +63,19 @@ func PossibleValuesForEntityQueryKind() []string { } } +func (s *EntityQueryKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityQueryKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityQueryKind(input string) (*EntityQueryKind, error) { vals := map[string]EntityQueryKind{ "activity": EntityQueryKindActivity, @@ -73,6 +103,19 @@ func PossibleValuesForEntityQueryTemplateKind() []string { } } +func (s *EntityQueryTemplateKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityQueryTemplateKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityQueryTemplateKind(input string) (*EntityQueryTemplateKind, error) { vals := map[string]EntityQueryTemplateKind{ "activity": EntityQueryTemplateKindActivity, @@ -138,6 +181,19 @@ func PossibleValuesForEntityType() []string { } } +func (s *EntityType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityType(input string) (*EntityType, error) { vals := map[string]EntityType{ "account": EntityTypeAccount, @@ -185,6 +241,19 @@ func PossibleValuesForKind() []string { } } +func (s *Kind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseKind(input string) (*Kind, error) { vals := map[string]Kind{ "activity": KindActivity, diff --git a/resource-manager/securityinsights/2021-09-01-preview/entityqueries/method_createorupdate.go b/resource-manager/securityinsights/2021-09-01-preview/entityqueries/method_createorupdate.go new file mode 100644 index 00000000000..b9ecc82c257 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/entityqueries/method_createorupdate.go @@ -0,0 +1,63 @@ +package entityqueries + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EntityQuery +} + +// CreateOrUpdate ... +func (c EntityQueriesClient) CreateOrUpdate(ctx context.Context, id EntityQueryId, input CustomEntityQuery) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalEntityQueryImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/entityqueries/method_createorupdate_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/entityqueries/method_createorupdate_autorest.go deleted file mode 100644 index eeec49d03b4..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/entityqueries/method_createorupdate_autorest.go +++ /dev/null @@ -1,78 +0,0 @@ -package entityqueries - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *EntityQuery -} - -// CreateOrUpdate ... -func (c EntityQueriesClient) CreateOrUpdate(ctx context.Context, id EntityQueryId, input CustomEntityQuery) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c EntityQueriesClient) preparerForCreateOrUpdate(ctx context.Context, id EntityQueryId, input CustomEntityQuery) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c EntityQueriesClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalEntityQueryImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/entityqueries/method_delete.go b/resource-manager/securityinsights/2021-09-01-preview/entityqueries/method_delete.go new file mode 100644 index 00000000000..b413ad04691 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/entityqueries/method_delete.go @@ -0,0 +1,47 @@ +package entityqueries + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c EntityQueriesClient) Delete(ctx context.Context, id EntityQueryId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/entityqueries/method_delete_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/entityqueries/method_delete_autorest.go deleted file mode 100644 index 3ad079474b1..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/entityqueries/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package entityqueries - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c EntityQueriesClient) Delete(ctx context.Context, id EntityQueryId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c EntityQueriesClient) preparerForDelete(ctx context.Context, id EntityQueryId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c EntityQueriesClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/entityqueries/method_entityquerytemplatesget.go b/resource-manager/securityinsights/2021-09-01-preview/entityqueries/method_entityquerytemplatesget.go new file mode 100644 index 00000000000..2e55614c8f0 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/entityqueries/method_entityquerytemplatesget.go @@ -0,0 +1,58 @@ +package entityqueries + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EntityQueryTemplatesGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EntityQueryTemplate +} + +// EntityQueryTemplatesGet ... +func (c EntityQueriesClient) EntityQueryTemplatesGet(ctx context.Context, id EntityQueryTemplateId) (result EntityQueryTemplatesGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalEntityQueryTemplateImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/entityqueries/method_entityquerytemplatesget_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/entityqueries/method_entityquerytemplatesget_autorest.go deleted file mode 100644 index e5058178ba0..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/entityqueries/method_entityquerytemplatesget_autorest.go +++ /dev/null @@ -1,77 +0,0 @@ -package entityqueries - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type EntityQueryTemplatesGetOperationResponse struct { - HttpResponse *http.Response - Model *EntityQueryTemplate -} - -// EntityQueryTemplatesGet ... -func (c EntityQueriesClient) EntityQueryTemplatesGet(ctx context.Context, id EntityQueryTemplateId) (result EntityQueryTemplatesGetOperationResponse, err error) { - req, err := c.preparerForEntityQueryTemplatesGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "EntityQueryTemplatesGet", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "EntityQueryTemplatesGet", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForEntityQueryTemplatesGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "EntityQueryTemplatesGet", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForEntityQueryTemplatesGet prepares the EntityQueryTemplatesGet request. -func (c EntityQueriesClient) preparerForEntityQueryTemplatesGet(ctx context.Context, id EntityQueryTemplateId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForEntityQueryTemplatesGet handles the response to the EntityQueryTemplatesGet request. The method always -// closes the http.Response Body. -func (c EntityQueriesClient) responderForEntityQueryTemplatesGet(resp *http.Response) (result EntityQueryTemplatesGetOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalEntityQueryTemplateImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/entityqueries/method_entityquerytemplateslist.go b/resource-manager/securityinsights/2021-09-01-preview/entityqueries/method_entityquerytemplateslist.go new file mode 100644 index 00000000000..80a1a6ce617 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/entityqueries/method_entityquerytemplateslist.go @@ -0,0 +1,131 @@ +package entityqueries + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EntityQueryTemplatesListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]EntityQueryTemplate +} + +type EntityQueryTemplatesListCompleteResult struct { + LatestHttpResponse *http.Response + Items []EntityQueryTemplate +} + +type EntityQueryTemplatesListOperationOptions struct { + Kind *Kind +} + +func DefaultEntityQueryTemplatesListOperationOptions() EntityQueryTemplatesListOperationOptions { + return EntityQueryTemplatesListOperationOptions{} +} + +func (o EntityQueryTemplatesListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o EntityQueryTemplatesListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o EntityQueryTemplatesListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Kind != nil { + out.Append("kind", fmt.Sprintf("%v", *o.Kind)) + } + return &out +} + +// EntityQueryTemplatesList ... +func (c EntityQueriesClient) EntityQueryTemplatesList(ctx context.Context, id WorkspaceId, options EntityQueryTemplatesListOperationOptions) (result EntityQueryTemplatesListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/entityQueryTemplates", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]EntityQueryTemplate, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalEntityQueryTemplateImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for EntityQueryTemplate (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// EntityQueryTemplatesListComplete retrieves all the results into a single object +func (c EntityQueriesClient) EntityQueryTemplatesListComplete(ctx context.Context, id WorkspaceId, options EntityQueryTemplatesListOperationOptions) (EntityQueryTemplatesListCompleteResult, error) { + return c.EntityQueryTemplatesListCompleteMatchingPredicate(ctx, id, options, EntityQueryTemplateOperationPredicate{}) +} + +// EntityQueryTemplatesListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c EntityQueriesClient) EntityQueryTemplatesListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options EntityQueryTemplatesListOperationOptions, predicate EntityQueryTemplateOperationPredicate) (result EntityQueryTemplatesListCompleteResult, err error) { + items := make([]EntityQueryTemplate, 0) + + resp, err := c.EntityQueryTemplatesList(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = EntityQueryTemplatesListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/entityqueries/method_entityquerytemplateslist_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/entityqueries/method_entityquerytemplateslist_autorest.go deleted file mode 100644 index 251984e8d83..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/entityqueries/method_entityquerytemplateslist_autorest.go +++ /dev/null @@ -1,225 +0,0 @@ -package entityqueries - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type EntityQueryTemplatesListOperationResponse struct { - HttpResponse *http.Response - Model *[]EntityQueryTemplate - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (EntityQueryTemplatesListOperationResponse, error) -} - -type EntityQueryTemplatesListCompleteResult struct { - Items []EntityQueryTemplate -} - -func (r EntityQueryTemplatesListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r EntityQueryTemplatesListOperationResponse) LoadMore(ctx context.Context) (resp EntityQueryTemplatesListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type EntityQueryTemplatesListOperationOptions struct { - Kind *Kind -} - -func DefaultEntityQueryTemplatesListOperationOptions() EntityQueryTemplatesListOperationOptions { - return EntityQueryTemplatesListOperationOptions{} -} - -func (o EntityQueryTemplatesListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o EntityQueryTemplatesListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Kind != nil { - out["kind"] = *o.Kind - } - - return out -} - -// EntityQueryTemplatesList ... -func (c EntityQueriesClient) EntityQueryTemplatesList(ctx context.Context, id WorkspaceId, options EntityQueryTemplatesListOperationOptions) (resp EntityQueryTemplatesListOperationResponse, err error) { - req, err := c.preparerForEntityQueryTemplatesList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "EntityQueryTemplatesList", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "EntityQueryTemplatesList", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForEntityQueryTemplatesList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "EntityQueryTemplatesList", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForEntityQueryTemplatesList prepares the EntityQueryTemplatesList request. -func (c EntityQueriesClient) preparerForEntityQueryTemplatesList(ctx context.Context, id WorkspaceId, options EntityQueryTemplatesListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/entityQueryTemplates", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForEntityQueryTemplatesListWithNextLink prepares the EntityQueryTemplatesList request with the given nextLink token. -func (c EntityQueriesClient) preparerForEntityQueryTemplatesListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForEntityQueryTemplatesList handles the response to the EntityQueryTemplatesList request. The method always -// closes the http.Response Body. -func (c EntityQueriesClient) responderForEntityQueryTemplatesList(resp *http.Response) (result EntityQueryTemplatesListOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]EntityQueryTemplate, 0) - for i, v := range respObj.Values { - val, err := unmarshalEntityQueryTemplateImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for EntityQueryTemplate (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result EntityQueryTemplatesListOperationResponse, err error) { - req, err := c.preparerForEntityQueryTemplatesListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "EntityQueryTemplatesList", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "EntityQueryTemplatesList", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForEntityQueryTemplatesList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "EntityQueryTemplatesList", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// EntityQueryTemplatesListComplete retrieves all of the results into a single object -func (c EntityQueriesClient) EntityQueryTemplatesListComplete(ctx context.Context, id WorkspaceId, options EntityQueryTemplatesListOperationOptions) (EntityQueryTemplatesListCompleteResult, error) { - return c.EntityQueryTemplatesListCompleteMatchingPredicate(ctx, id, options, EntityQueryTemplateOperationPredicate{}) -} - -// EntityQueryTemplatesListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c EntityQueriesClient) EntityQueryTemplatesListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options EntityQueryTemplatesListOperationOptions, predicate EntityQueryTemplateOperationPredicate) (resp EntityQueryTemplatesListCompleteResult, err error) { - items := make([]EntityQueryTemplate, 0) - - page, err := c.EntityQueryTemplatesList(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := EntityQueryTemplatesListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/entityqueries/method_get.go b/resource-manager/securityinsights/2021-09-01-preview/entityqueries/method_get.go new file mode 100644 index 00000000000..4a7022fa713 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/entityqueries/method_get.go @@ -0,0 +1,58 @@ +package entityqueries + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EntityQuery +} + +// Get ... +func (c EntityQueriesClient) Get(ctx context.Context, id EntityQueryId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalEntityQueryImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/entityqueries/method_get_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/entityqueries/method_get_autorest.go deleted file mode 100644 index ad9e794be03..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/entityqueries/method_get_autorest.go +++ /dev/null @@ -1,77 +0,0 @@ -package entityqueries - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *EntityQuery -} - -// Get ... -func (c EntityQueriesClient) Get(ctx context.Context, id EntityQueryId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c EntityQueriesClient) preparerForGet(ctx context.Context, id EntityQueryId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c EntityQueriesClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalEntityQueryImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/entityqueries/method_list.go b/resource-manager/securityinsights/2021-09-01-preview/entityqueries/method_list.go new file mode 100644 index 00000000000..5cf5f6c7631 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/entityqueries/method_list.go @@ -0,0 +1,131 @@ +package entityqueries + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]EntityQuery +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []EntityQuery +} + +type ListOperationOptions struct { + Kind *Kind +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Kind != nil { + out.Append("kind", fmt.Sprintf("%v", *o.Kind)) + } + return &out +} + +// List ... +func (c EntityQueriesClient) List(ctx context.Context, id WorkspaceId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/entityQueries", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]EntityQuery, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalEntityQueryImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for EntityQuery (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// ListComplete retrieves all the results into a single object +func (c EntityQueriesClient) ListComplete(ctx context.Context, id WorkspaceId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, EntityQueryOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c EntityQueriesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ListOperationOptions, predicate EntityQueryOperationPredicate) (result ListCompleteResult, err error) { + items := make([]EntityQuery, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/entityqueries/method_list_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/entityqueries/method_list_autorest.go deleted file mode 100644 index be9cadd1c8f..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/entityqueries/method_list_autorest.go +++ /dev/null @@ -1,225 +0,0 @@ -package entityqueries - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]EntityQuery - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []EntityQuery -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ListOperationOptions struct { - Kind *Kind -} - -func DefaultListOperationOptions() ListOperationOptions { - return ListOperationOptions{} -} - -func (o ListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Kind != nil { - out["kind"] = *o.Kind - } - - return out -} - -// List ... -func (c EntityQueriesClient) List(ctx context.Context, id WorkspaceId, options ListOperationOptions) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c EntityQueriesClient) preparerForList(ctx context.Context, id WorkspaceId, options ListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/entityQueries", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c EntityQueriesClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c EntityQueriesClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]EntityQuery, 0) - for i, v := range respObj.Values { - val, err := unmarshalEntityQueryImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for EntityQuery (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c EntityQueriesClient) ListComplete(ctx context.Context, id WorkspaceId, options ListOperationOptions) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, options, EntityQueryOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c EntityQueriesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ListOperationOptions, predicate EntityQueryOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]EntityQuery, 0) - - page, err := c.List(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/entityrelations/client.go b/resource-manager/securityinsights/2021-09-01-preview/entityrelations/client.go index ac243fa003e..85b6978e574 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/entityrelations/client.go +++ b/resource-manager/securityinsights/2021-09-01-preview/entityrelations/client.go @@ -1,18 +1,26 @@ package entityrelations -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type EntityRelationsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewEntityRelationsClientWithBaseURI(endpoint string) EntityRelationsClient { - return EntityRelationsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewEntityRelationsClientWithBaseURI(sdkApi sdkEnv.Api) (*EntityRelationsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "entityrelations", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating EntityRelationsClient: %+v", err) } + + return &EntityRelationsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2021-09-01-preview/entityrelations/method_entitiesrelationslist.go b/resource-manager/securityinsights/2021-09-01-preview/entityrelations/method_entitiesrelationslist.go new file mode 100644 index 00000000000..ffe62e84ee3 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/entityrelations/method_entitiesrelationslist.go @@ -0,0 +1,127 @@ +package entityrelations + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EntitiesRelationsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Relation +} + +type EntitiesRelationsListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Relation +} + +type EntitiesRelationsListOperationOptions struct { + Filter *string + Orderby *string + Top *int64 +} + +func DefaultEntitiesRelationsListOperationOptions() EntitiesRelationsListOperationOptions { + return EntitiesRelationsListOperationOptions{} +} + +func (o EntitiesRelationsListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o EntitiesRelationsListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o EntitiesRelationsListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// EntitiesRelationsList ... +func (c EntityRelationsClient) EntitiesRelationsList(ctx context.Context, id EntityId, options EntitiesRelationsListOperationOptions) (result EntitiesRelationsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/relations", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Relation `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// EntitiesRelationsListComplete retrieves all the results into a single object +func (c EntityRelationsClient) EntitiesRelationsListComplete(ctx context.Context, id EntityId, options EntitiesRelationsListOperationOptions) (EntitiesRelationsListCompleteResult, error) { + return c.EntitiesRelationsListCompleteMatchingPredicate(ctx, id, options, RelationOperationPredicate{}) +} + +// EntitiesRelationsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c EntityRelationsClient) EntitiesRelationsListCompleteMatchingPredicate(ctx context.Context, id EntityId, options EntitiesRelationsListOperationOptions, predicate RelationOperationPredicate) (result EntitiesRelationsListCompleteResult, err error) { + items := make([]Relation, 0) + + resp, err := c.EntitiesRelationsList(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = EntitiesRelationsListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/entityrelations/method_entitiesrelationslist_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/entityrelations/method_entitiesrelationslist_autorest.go deleted file mode 100644 index 7cb48eb2ac6..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/entityrelations/method_entitiesrelationslist_autorest.go +++ /dev/null @@ -1,225 +0,0 @@ -package entityrelations - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type EntitiesRelationsListOperationResponse struct { - HttpResponse *http.Response - Model *[]Relation - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (EntitiesRelationsListOperationResponse, error) -} - -type EntitiesRelationsListCompleteResult struct { - Items []Relation -} - -func (r EntitiesRelationsListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r EntitiesRelationsListOperationResponse) LoadMore(ctx context.Context) (resp EntitiesRelationsListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type EntitiesRelationsListOperationOptions struct { - Filter *string - Orderby *string - Top *int64 -} - -func DefaultEntitiesRelationsListOperationOptions() EntitiesRelationsListOperationOptions { - return EntitiesRelationsListOperationOptions{} -} - -func (o EntitiesRelationsListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o EntitiesRelationsListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Filter != nil { - out["$filter"] = *o.Filter - } - - if o.Orderby != nil { - out["$orderby"] = *o.Orderby - } - - if o.Top != nil { - out["$top"] = *o.Top - } - - return out -} - -// EntitiesRelationsList ... -func (c EntityRelationsClient) EntitiesRelationsList(ctx context.Context, id EntityId, options EntitiesRelationsListOperationOptions) (resp EntitiesRelationsListOperationResponse, err error) { - req, err := c.preparerForEntitiesRelationsList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "entityrelations.EntityRelationsClient", "EntitiesRelationsList", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entityrelations.EntityRelationsClient", "EntitiesRelationsList", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForEntitiesRelationsList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entityrelations.EntityRelationsClient", "EntitiesRelationsList", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForEntitiesRelationsList prepares the EntitiesRelationsList request. -func (c EntityRelationsClient) preparerForEntitiesRelationsList(ctx context.Context, id EntityId, options EntitiesRelationsListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/relations", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForEntitiesRelationsListWithNextLink prepares the EntitiesRelationsList request with the given nextLink token. -func (c EntityRelationsClient) preparerForEntitiesRelationsListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForEntitiesRelationsList handles the response to the EntitiesRelationsList request. The method always -// closes the http.Response Body. -func (c EntityRelationsClient) responderForEntitiesRelationsList(resp *http.Response) (result EntitiesRelationsListOperationResponse, err error) { - type page struct { - Values []Relation `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result EntitiesRelationsListOperationResponse, err error) { - req, err := c.preparerForEntitiesRelationsListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "entityrelations.EntityRelationsClient", "EntitiesRelationsList", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entityrelations.EntityRelationsClient", "EntitiesRelationsList", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForEntitiesRelationsList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entityrelations.EntityRelationsClient", "EntitiesRelationsList", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// EntitiesRelationsListComplete retrieves all of the results into a single object -func (c EntityRelationsClient) EntitiesRelationsListComplete(ctx context.Context, id EntityId, options EntitiesRelationsListOperationOptions) (EntitiesRelationsListCompleteResult, error) { - return c.EntitiesRelationsListCompleteMatchingPredicate(ctx, id, options, RelationOperationPredicate{}) -} - -// EntitiesRelationsListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c EntityRelationsClient) EntitiesRelationsListCompleteMatchingPredicate(ctx context.Context, id EntityId, options EntitiesRelationsListOperationOptions, predicate RelationOperationPredicate) (resp EntitiesRelationsListCompleteResult, err error) { - items := make([]Relation, 0) - - page, err := c.EntitiesRelationsList(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := EntitiesRelationsListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/entityrelations/method_getrelation.go b/resource-manager/securityinsights/2021-09-01-preview/entityrelations/method_getrelation.go new file mode 100644 index 00000000000..e81337d733b --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/entityrelations/method_getrelation.go @@ -0,0 +1,51 @@ +package entityrelations + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetRelationOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Relation +} + +// GetRelation ... +func (c EntityRelationsClient) GetRelation(ctx context.Context, id RelationId) (result GetRelationOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/entityrelations/method_getrelation_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/entityrelations/method_getrelation_autorest.go deleted file mode 100644 index d400c162968..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/entityrelations/method_getrelation_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package entityrelations - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetRelationOperationResponse struct { - HttpResponse *http.Response - Model *Relation -} - -// GetRelation ... -func (c EntityRelationsClient) GetRelation(ctx context.Context, id RelationId) (result GetRelationOperationResponse, err error) { - req, err := c.preparerForGetRelation(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "entityrelations.EntityRelationsClient", "GetRelation", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entityrelations.EntityRelationsClient", "GetRelation", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGetRelation(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entityrelations.EntityRelationsClient", "GetRelation", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGetRelation prepares the GetRelation request. -func (c EntityRelationsClient) preparerForGetRelation(ctx context.Context, id RelationId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGetRelation handles the response to the GetRelation request. The method always -// closes the http.Response Body. -func (c EntityRelationsClient) responderForGetRelation(resp *http.Response) (result GetRelationOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/entitytypes/client.go b/resource-manager/securityinsights/2021-09-01-preview/entitytypes/client.go index 60583ea834f..bcdd09e4029 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/entitytypes/client.go +++ b/resource-manager/securityinsights/2021-09-01-preview/entitytypes/client.go @@ -1,18 +1,26 @@ package entitytypes -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type EntityTypesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewEntityTypesClientWithBaseURI(endpoint string) EntityTypesClient { - return EntityTypesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewEntityTypesClientWithBaseURI(sdkApi sdkEnv.Api) (*EntityTypesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "entitytypes", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating EntityTypesClient: %+v", err) } + + return &EntityTypesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2021-09-01-preview/entitytypes/constants.go b/resource-manager/securityinsights/2021-09-01-preview/entitytypes/constants.go index c391115d37e..797b5f76c02 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/entitytypes/constants.go +++ b/resource-manager/securityinsights/2021-09-01-preview/entitytypes/constants.go @@ -1,6 +1,10 @@ package entitytypes -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -23,6 +27,19 @@ func PossibleValuesForAlertSeverity() []string { } } +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertSeverity(input string) (*AlertSeverity, error) { vals := map[string]AlertSeverity{ "high": AlertSeverityHigh, @@ -59,6 +76,19 @@ func PossibleValuesForAlertStatus() []string { } } +func (s *AlertStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertStatus(input string) (*AlertStatus, error) { vals := map[string]AlertStatus{ "dismissed": AlertStatusDismissed, @@ -94,6 +124,19 @@ func PossibleValuesForAntispamMailDirection() []string { } } +func (s *AntispamMailDirection) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAntispamMailDirection(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAntispamMailDirection(input string) (*AntispamMailDirection, error) { vals := map[string]AntispamMailDirection{ "inbound": AntispamMailDirectionInbound, @@ -146,6 +189,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -187,6 +243,19 @@ func PossibleValuesForConfidenceLevel() []string { } } +func (s *ConfidenceLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceLevel(input string) (*ConfidenceLevel, error) { vals := map[string]ConfidenceLevel{ "high": ConfidenceLevelHigh, @@ -220,6 +289,19 @@ func PossibleValuesForConfidenceScoreStatus() []string { } } +func (s *ConfidenceScoreStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceScoreStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceScoreStatus(input string) (*ConfidenceScoreStatus, error) { vals := map[string]ConfidenceScoreStatus{ "final": ConfidenceScoreStatusFinal, @@ -254,6 +336,19 @@ func PossibleValuesForCreatedByType() []string { } } +func (s *CreatedByType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCreatedByType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseCreatedByType(input string) (*CreatedByType, error) { vals := map[string]CreatedByType{ "application": CreatedByTypeApplication, @@ -290,6 +385,19 @@ func PossibleValuesForDeliveryAction() []string { } } +func (s *DeliveryAction) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeliveryAction(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDeliveryAction(input string) (*DeliveryAction, error) { vals := map[string]DeliveryAction{ "blocked": DeliveryActionBlocked, @@ -335,6 +443,19 @@ func PossibleValuesForDeliveryLocation() []string { } } +func (s *DeliveryLocation) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeliveryLocation(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDeliveryLocation(input string) (*DeliveryLocation, error) { vals := map[string]DeliveryLocation{ "deletedfolder": DeliveryLocationDeletedFolder, @@ -372,6 +493,19 @@ func PossibleValuesForElevationToken() []string { } } +func (s *ElevationToken) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseElevationToken(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseElevationToken(input string) (*ElevationToken, error) { vals := map[string]ElevationToken{ "default": ElevationTokenDefault, @@ -439,6 +573,19 @@ func PossibleValuesForEntityKind() []string { } } +func (s *EntityKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityKind(input string) (*EntityKind, error) { vals := map[string]EntityKind{ "account": EntityKindAccount, @@ -492,6 +639,19 @@ func PossibleValuesForFileHashAlgorithm() []string { } } +func (s *FileHashAlgorithm) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseFileHashAlgorithm(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseFileHashAlgorithm(input string) (*FileHashAlgorithm, error) { vals := map[string]FileHashAlgorithm{ "md5": FileHashAlgorithmMDFive, @@ -527,6 +687,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, @@ -581,6 +754,19 @@ func PossibleValuesForKillChainIntent() []string { } } +func (s *KillChainIntent) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKillChainIntent(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseKillChainIntent(input string) (*KillChainIntent, error) { vals := map[string]KillChainIntent{ "collection": KillChainIntentCollection, @@ -627,6 +813,19 @@ func PossibleValuesForOSFamily() []string { } } +func (s *OSFamily) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOSFamily(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseOSFamily(input string) (*OSFamily, error) { vals := map[string]OSFamily{ "android": OSFamilyAndroid, @@ -674,6 +873,19 @@ func PossibleValuesForRegistryHive() []string { } } +func (s *RegistryHive) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRegistryHive(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseRegistryHive(input string) (*RegistryHive, error) { vals := map[string]RegistryHive{ "hkey_a": RegistryHiveHKEYA, @@ -722,6 +934,19 @@ func PossibleValuesForRegistryValueKind() []string { } } +func (s *RegistryValueKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRegistryValueKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseRegistryValueKind(input string) (*RegistryValueKind, error) { vals := map[string]RegistryValueKind{ "binary": RegistryValueKindBinary, diff --git a/resource-manager/securityinsights/2021-09-01-preview/incidentalerts/client.go b/resource-manager/securityinsights/2021-09-01-preview/incidentalerts/client.go index ae19637d473..53dc2b4cd4e 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/incidentalerts/client.go +++ b/resource-manager/securityinsights/2021-09-01-preview/incidentalerts/client.go @@ -1,18 +1,26 @@ package incidentalerts -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type IncidentAlertsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewIncidentAlertsClientWithBaseURI(endpoint string) IncidentAlertsClient { - return IncidentAlertsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewIncidentAlertsClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentAlertsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidentalerts", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentAlertsClient: %+v", err) } + + return &IncidentAlertsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2021-09-01-preview/incidentalerts/constants.go b/resource-manager/securityinsights/2021-09-01-preview/incidentalerts/constants.go index 529bd9d33ab..e7252cfe5ce 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/incidentalerts/constants.go +++ b/resource-manager/securityinsights/2021-09-01-preview/incidentalerts/constants.go @@ -1,6 +1,10 @@ package incidentalerts -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -23,6 +27,19 @@ func PossibleValuesForAlertSeverity() []string { } } +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertSeverity(input string) (*AlertSeverity, error) { vals := map[string]AlertSeverity{ "high": AlertSeverityHigh, @@ -59,6 +76,19 @@ func PossibleValuesForAlertStatus() []string { } } +func (s *AlertStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertStatus(input string) (*AlertStatus, error) { vals := map[string]AlertStatus{ "dismissed": AlertStatusDismissed, @@ -112,6 +142,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -153,6 +196,19 @@ func PossibleValuesForConfidenceLevel() []string { } } +func (s *ConfidenceLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceLevel(input string) (*ConfidenceLevel, error) { vals := map[string]ConfidenceLevel{ "high": ConfidenceLevelHigh, @@ -186,6 +242,19 @@ func PossibleValuesForConfidenceScoreStatus() []string { } } +func (s *ConfidenceScoreStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceScoreStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceScoreStatus(input string) (*ConfidenceScoreStatus, error) { vals := map[string]ConfidenceScoreStatus{ "final": ConfidenceScoreStatusFinal, @@ -254,6 +323,19 @@ func PossibleValuesForEntityKind() []string { } } +func (s *EntityKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityKind(input string) (*EntityKind, error) { vals := map[string]EntityKind{ "account": EntityKindAccount, @@ -305,6 +387,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, @@ -359,6 +454,19 @@ func PossibleValuesForKillChainIntent() []string { } } +func (s *KillChainIntent) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKillChainIntent(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseKillChainIntent(input string) (*KillChainIntent, error) { vals := map[string]KillChainIntent{ "collection": KillChainIntentCollection, diff --git a/resource-manager/securityinsights/2021-09-01-preview/incidentalerts/method_incidentslistalerts.go b/resource-manager/securityinsights/2021-09-01-preview/incidentalerts/method_incidentslistalerts.go new file mode 100644 index 00000000000..fe83693eae2 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/incidentalerts/method_incidentslistalerts.go @@ -0,0 +1,52 @@ +package incidentalerts + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentsListAlertsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IncidentAlertList +} + +// IncidentsListAlerts ... +func (c IncidentAlertsClient) IncidentsListAlerts(ctx context.Context, id IncidentId) (result IncidentsListAlertsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/alerts", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/incidentalerts/method_incidentslistalerts_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/incidentalerts/method_incidentslistalerts_autorest.go deleted file mode 100644 index de6c08e09a2..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/incidentalerts/method_incidentslistalerts_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package incidentalerts - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IncidentsListAlertsOperationResponse struct { - HttpResponse *http.Response - Model *IncidentAlertList -} - -// IncidentsListAlerts ... -func (c IncidentAlertsClient) IncidentsListAlerts(ctx context.Context, id IncidentId) (result IncidentsListAlertsOperationResponse, err error) { - req, err := c.preparerForIncidentsListAlerts(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentalerts.IncidentAlertsClient", "IncidentsListAlerts", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentalerts.IncidentAlertsClient", "IncidentsListAlerts", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIncidentsListAlerts(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentalerts.IncidentAlertsClient", "IncidentsListAlerts", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIncidentsListAlerts prepares the IncidentsListAlerts request. -func (c IncidentAlertsClient) preparerForIncidentsListAlerts(ctx context.Context, id IncidentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/alerts", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIncidentsListAlerts handles the response to the IncidentsListAlerts request. The method always -// closes the http.Response Body. -func (c IncidentAlertsClient) responderForIncidentsListAlerts(resp *http.Response) (result IncidentsListAlertsOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/incidentbookmarks/client.go b/resource-manager/securityinsights/2021-09-01-preview/incidentbookmarks/client.go index e2fcca6728b..e6a60ede52d 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/incidentbookmarks/client.go +++ b/resource-manager/securityinsights/2021-09-01-preview/incidentbookmarks/client.go @@ -1,18 +1,26 @@ package incidentbookmarks -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type IncidentBookmarksClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewIncidentBookmarksClientWithBaseURI(endpoint string) IncidentBookmarksClient { - return IncidentBookmarksClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewIncidentBookmarksClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentBookmarksClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidentbookmarks", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentBookmarksClient: %+v", err) } + + return &IncidentBookmarksClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2021-09-01-preview/incidentbookmarks/constants.go b/resource-manager/securityinsights/2021-09-01-preview/incidentbookmarks/constants.go index 11b3018ed6e..6a4c429d22f 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/incidentbookmarks/constants.go +++ b/resource-manager/securityinsights/2021-09-01-preview/incidentbookmarks/constants.go @@ -1,6 +1,10 @@ package incidentbookmarks -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -23,6 +27,19 @@ func PossibleValuesForAlertSeverity() []string { } } +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertSeverity(input string) (*AlertSeverity, error) { vals := map[string]AlertSeverity{ "high": AlertSeverityHigh, @@ -59,6 +76,19 @@ func PossibleValuesForAlertStatus() []string { } } +func (s *AlertStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertStatus(input string) (*AlertStatus, error) { vals := map[string]AlertStatus{ "dismissed": AlertStatusDismissed, @@ -112,6 +142,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -153,6 +196,19 @@ func PossibleValuesForConfidenceLevel() []string { } } +func (s *ConfidenceLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceLevel(input string) (*ConfidenceLevel, error) { vals := map[string]ConfidenceLevel{ "high": ConfidenceLevelHigh, @@ -186,6 +242,19 @@ func PossibleValuesForConfidenceScoreStatus() []string { } } +func (s *ConfidenceScoreStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceScoreStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceScoreStatus(input string) (*ConfidenceScoreStatus, error) { vals := map[string]ConfidenceScoreStatus{ "final": ConfidenceScoreStatusFinal, @@ -254,6 +323,19 @@ func PossibleValuesForEntityKind() []string { } } +func (s *EntityKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityKind(input string) (*EntityKind, error) { vals := map[string]EntityKind{ "account": EntityKindAccount, @@ -305,6 +387,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, @@ -359,6 +454,19 @@ func PossibleValuesForKillChainIntent() []string { } } +func (s *KillChainIntent) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKillChainIntent(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseKillChainIntent(input string) (*KillChainIntent, error) { vals := map[string]KillChainIntent{ "collection": KillChainIntentCollection, diff --git a/resource-manager/securityinsights/2021-09-01-preview/incidentbookmarks/method_incidentslistbookmarks.go b/resource-manager/securityinsights/2021-09-01-preview/incidentbookmarks/method_incidentslistbookmarks.go new file mode 100644 index 00000000000..3ac7b9e8b2e --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/incidentbookmarks/method_incidentslistbookmarks.go @@ -0,0 +1,52 @@ +package incidentbookmarks + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentsListBookmarksOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IncidentBookmarkList +} + +// IncidentsListBookmarks ... +func (c IncidentBookmarksClient) IncidentsListBookmarks(ctx context.Context, id IncidentId) (result IncidentsListBookmarksOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/bookmarks", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/incidentbookmarks/method_incidentslistbookmarks_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/incidentbookmarks/method_incidentslistbookmarks_autorest.go deleted file mode 100644 index a5c3a89a09c..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/incidentbookmarks/method_incidentslistbookmarks_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package incidentbookmarks - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IncidentsListBookmarksOperationResponse struct { - HttpResponse *http.Response - Model *IncidentBookmarkList -} - -// IncidentsListBookmarks ... -func (c IncidentBookmarksClient) IncidentsListBookmarks(ctx context.Context, id IncidentId) (result IncidentsListBookmarksOperationResponse, err error) { - req, err := c.preparerForIncidentsListBookmarks(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentbookmarks.IncidentBookmarksClient", "IncidentsListBookmarks", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentbookmarks.IncidentBookmarksClient", "IncidentsListBookmarks", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIncidentsListBookmarks(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentbookmarks.IncidentBookmarksClient", "IncidentsListBookmarks", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIncidentsListBookmarks prepares the IncidentsListBookmarks request. -func (c IncidentBookmarksClient) preparerForIncidentsListBookmarks(ctx context.Context, id IncidentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/bookmarks", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIncidentsListBookmarks handles the response to the IncidentsListBookmarks request. The method always -// closes the http.Response Body. -func (c IncidentBookmarksClient) responderForIncidentsListBookmarks(resp *http.Response) (result IncidentsListBookmarksOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/incidentcomments/client.go b/resource-manager/securityinsights/2021-09-01-preview/incidentcomments/client.go index 4006779247d..981e6f75216 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/incidentcomments/client.go +++ b/resource-manager/securityinsights/2021-09-01-preview/incidentcomments/client.go @@ -1,18 +1,26 @@ package incidentcomments -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type IncidentCommentsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewIncidentCommentsClientWithBaseURI(endpoint string) IncidentCommentsClient { - return IncidentCommentsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewIncidentCommentsClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentCommentsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidentcomments", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentCommentsClient: %+v", err) } + + return &IncidentCommentsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2021-09-01-preview/incidentcomments/method_createorupdate.go b/resource-manager/securityinsights/2021-09-01-preview/incidentcomments/method_createorupdate.go new file mode 100644 index 00000000000..5c59b2be8d3 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/incidentcomments/method_createorupdate.go @@ -0,0 +1,56 @@ +package incidentcomments + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IncidentComment +} + +// CreateOrUpdate ... +func (c IncidentCommentsClient) CreateOrUpdate(ctx context.Context, id CommentId, input IncidentComment) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/incidentcomments/method_createorupdate_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/incidentcomments/method_createorupdate_autorest.go deleted file mode 100644 index b27777aad2c..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/incidentcomments/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package incidentcomments - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *IncidentComment -} - -// CreateOrUpdate ... -func (c IncidentCommentsClient) CreateOrUpdate(ctx context.Context, id CommentId, input IncidentComment) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c IncidentCommentsClient) preparerForCreateOrUpdate(ctx context.Context, id CommentId, input IncidentComment) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c IncidentCommentsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/incidentcomments/method_delete.go b/resource-manager/securityinsights/2021-09-01-preview/incidentcomments/method_delete.go new file mode 100644 index 00000000000..78412a13e76 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/incidentcomments/method_delete.go @@ -0,0 +1,47 @@ +package incidentcomments + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c IncidentCommentsClient) Delete(ctx context.Context, id CommentId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/incidentcomments/method_delete_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/incidentcomments/method_delete_autorest.go deleted file mode 100644 index 6bbb4c92cbf..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/incidentcomments/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package incidentcomments - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c IncidentCommentsClient) Delete(ctx context.Context, id CommentId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c IncidentCommentsClient) preparerForDelete(ctx context.Context, id CommentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c IncidentCommentsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/incidentcomments/method_get.go b/resource-manager/securityinsights/2021-09-01-preview/incidentcomments/method_get.go new file mode 100644 index 00000000000..e8d11306ddb --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/incidentcomments/method_get.go @@ -0,0 +1,51 @@ +package incidentcomments + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IncidentComment +} + +// Get ... +func (c IncidentCommentsClient) Get(ctx context.Context, id CommentId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/incidentcomments/method_get_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/incidentcomments/method_get_autorest.go deleted file mode 100644 index 8402ed77e94..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/incidentcomments/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package incidentcomments - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *IncidentComment -} - -// Get ... -func (c IncidentCommentsClient) Get(ctx context.Context, id CommentId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c IncidentCommentsClient) preparerForGet(ctx context.Context, id CommentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c IncidentCommentsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/incidentcomments/method_list.go b/resource-manager/securityinsights/2021-09-01-preview/incidentcomments/method_list.go new file mode 100644 index 00000000000..b4c16058b38 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/incidentcomments/method_list.go @@ -0,0 +1,127 @@ +package incidentcomments + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]IncidentComment +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []IncidentComment +} + +type ListOperationOptions struct { + Filter *string + Orderby *string + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c IncidentCommentsClient) List(ctx context.Context, id IncidentId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/comments", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]IncidentComment `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c IncidentCommentsClient) ListComplete(ctx context.Context, id IncidentId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, IncidentCommentOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c IncidentCommentsClient) ListCompleteMatchingPredicate(ctx context.Context, id IncidentId, options ListOperationOptions, predicate IncidentCommentOperationPredicate) (result ListCompleteResult, err error) { + items := make([]IncidentComment, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/incidentcomments/method_list_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/incidentcomments/method_list_autorest.go deleted file mode 100644 index 24fb8d1d7e7..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/incidentcomments/method_list_autorest.go +++ /dev/null @@ -1,225 +0,0 @@ -package incidentcomments - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]IncidentComment - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []IncidentComment -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ListOperationOptions struct { - Filter *string - Orderby *string - Top *int64 -} - -func DefaultListOperationOptions() ListOperationOptions { - return ListOperationOptions{} -} - -func (o ListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Filter != nil { - out["$filter"] = *o.Filter - } - - if o.Orderby != nil { - out["$orderby"] = *o.Orderby - } - - if o.Top != nil { - out["$top"] = *o.Top - } - - return out -} - -// List ... -func (c IncidentCommentsClient) List(ctx context.Context, id IncidentId, options ListOperationOptions) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c IncidentCommentsClient) preparerForList(ctx context.Context, id IncidentId, options ListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/comments", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c IncidentCommentsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c IncidentCommentsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []IncidentComment `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c IncidentCommentsClient) ListComplete(ctx context.Context, id IncidentId, options ListOperationOptions) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, options, IncidentCommentOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c IncidentCommentsClient) ListCompleteMatchingPredicate(ctx context.Context, id IncidentId, options ListOperationOptions, predicate IncidentCommentOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]IncidentComment, 0) - - page, err := c.List(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/incidententities/client.go b/resource-manager/securityinsights/2021-09-01-preview/incidententities/client.go index 5f0eaf07782..740e7b81755 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/incidententities/client.go +++ b/resource-manager/securityinsights/2021-09-01-preview/incidententities/client.go @@ -1,18 +1,26 @@ package incidententities -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type IncidentEntitiesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewIncidentEntitiesClientWithBaseURI(endpoint string) IncidentEntitiesClient { - return IncidentEntitiesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewIncidentEntitiesClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentEntitiesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidententities", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentEntitiesClient: %+v", err) } + + return &IncidentEntitiesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2021-09-01-preview/incidententities/constants.go b/resource-manager/securityinsights/2021-09-01-preview/incidententities/constants.go index a78a5c4dbcf..d153eca4b63 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/incidententities/constants.go +++ b/resource-manager/securityinsights/2021-09-01-preview/incidententities/constants.go @@ -1,6 +1,10 @@ package incidententities -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -23,6 +27,19 @@ func PossibleValuesForAlertSeverity() []string { } } +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertSeverity(input string) (*AlertSeverity, error) { vals := map[string]AlertSeverity{ "high": AlertSeverityHigh, @@ -59,6 +76,19 @@ func PossibleValuesForAlertStatus() []string { } } +func (s *AlertStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertStatus(input string) (*AlertStatus, error) { vals := map[string]AlertStatus{ "dismissed": AlertStatusDismissed, @@ -112,6 +142,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -153,6 +196,19 @@ func PossibleValuesForConfidenceLevel() []string { } } +func (s *ConfidenceLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceLevel(input string) (*ConfidenceLevel, error) { vals := map[string]ConfidenceLevel{ "high": ConfidenceLevelHigh, @@ -186,6 +242,19 @@ func PossibleValuesForConfidenceScoreStatus() []string { } } +func (s *ConfidenceScoreStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceScoreStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceScoreStatus(input string) (*ConfidenceScoreStatus, error) { vals := map[string]ConfidenceScoreStatus{ "final": ConfidenceScoreStatusFinal, @@ -254,6 +323,19 @@ func PossibleValuesForEntityKind() []string { } } +func (s *EntityKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityKind(input string) (*EntityKind, error) { vals := map[string]EntityKind{ "account": EntityKindAccount, @@ -305,6 +387,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, @@ -359,6 +454,19 @@ func PossibleValuesForKillChainIntent() []string { } } +func (s *KillChainIntent) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKillChainIntent(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseKillChainIntent(input string) (*KillChainIntent, error) { vals := map[string]KillChainIntent{ "collection": KillChainIntentCollection, diff --git a/resource-manager/securityinsights/2021-09-01-preview/incidententities/method_incidentslistentities.go b/resource-manager/securityinsights/2021-09-01-preview/incidententities/method_incidentslistentities.go new file mode 100644 index 00000000000..36ec8f0c75b --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/incidententities/method_incidentslistentities.go @@ -0,0 +1,52 @@ +package incidententities + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentsListEntitiesOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IncidentEntitiesResponse +} + +// IncidentsListEntities ... +func (c IncidentEntitiesClient) IncidentsListEntities(ctx context.Context, id IncidentId) (result IncidentsListEntitiesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/entities", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/incidententities/method_incidentslistentities_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/incidententities/method_incidentslistentities_autorest.go deleted file mode 100644 index 9d796d431cb..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/incidententities/method_incidentslistentities_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package incidententities - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IncidentsListEntitiesOperationResponse struct { - HttpResponse *http.Response - Model *IncidentEntitiesResponse -} - -// IncidentsListEntities ... -func (c IncidentEntitiesClient) IncidentsListEntities(ctx context.Context, id IncidentId) (result IncidentsListEntitiesOperationResponse, err error) { - req, err := c.preparerForIncidentsListEntities(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidententities.IncidentEntitiesClient", "IncidentsListEntities", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidententities.IncidentEntitiesClient", "IncidentsListEntities", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIncidentsListEntities(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidententities.IncidentEntitiesClient", "IncidentsListEntities", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIncidentsListEntities prepares the IncidentsListEntities request. -func (c IncidentEntitiesClient) preparerForIncidentsListEntities(ctx context.Context, id IncidentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/entities", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIncidentsListEntities handles the response to the IncidentsListEntities request. The method always -// closes the http.Response Body. -func (c IncidentEntitiesClient) responderForIncidentsListEntities(resp *http.Response) (result IncidentsListEntitiesOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/incidentrelations/client.go b/resource-manager/securityinsights/2021-09-01-preview/incidentrelations/client.go index 58aa27c43e8..4e8fbfeb71d 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/incidentrelations/client.go +++ b/resource-manager/securityinsights/2021-09-01-preview/incidentrelations/client.go @@ -1,18 +1,26 @@ package incidentrelations -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type IncidentRelationsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewIncidentRelationsClientWithBaseURI(endpoint string) IncidentRelationsClient { - return IncidentRelationsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewIncidentRelationsClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentRelationsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidentrelations", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentRelationsClient: %+v", err) } + + return &IncidentRelationsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2021-09-01-preview/incidentrelations/method_createorupdate.go b/resource-manager/securityinsights/2021-09-01-preview/incidentrelations/method_createorupdate.go new file mode 100644 index 00000000000..e87f1b4b752 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/incidentrelations/method_createorupdate.go @@ -0,0 +1,56 @@ +package incidentrelations + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Relation +} + +// CreateOrUpdate ... +func (c IncidentRelationsClient) CreateOrUpdate(ctx context.Context, id IncidentRelationId, input Relation) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/incidentrelations/method_createorupdate_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/incidentrelations/method_createorupdate_autorest.go deleted file mode 100644 index 26334017af9..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/incidentrelations/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package incidentrelations - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *Relation -} - -// CreateOrUpdate ... -func (c IncidentRelationsClient) CreateOrUpdate(ctx context.Context, id IncidentRelationId, input Relation) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c IncidentRelationsClient) preparerForCreateOrUpdate(ctx context.Context, id IncidentRelationId, input Relation) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c IncidentRelationsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/incidentrelations/method_delete.go b/resource-manager/securityinsights/2021-09-01-preview/incidentrelations/method_delete.go new file mode 100644 index 00000000000..7206ac26d08 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/incidentrelations/method_delete.go @@ -0,0 +1,47 @@ +package incidentrelations + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c IncidentRelationsClient) Delete(ctx context.Context, id IncidentRelationId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/incidentrelations/method_delete_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/incidentrelations/method_delete_autorest.go deleted file mode 100644 index d288fdf5e60..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/incidentrelations/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package incidentrelations - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c IncidentRelationsClient) Delete(ctx context.Context, id IncidentRelationId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c IncidentRelationsClient) preparerForDelete(ctx context.Context, id IncidentRelationId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c IncidentRelationsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/incidentrelations/method_get.go b/resource-manager/securityinsights/2021-09-01-preview/incidentrelations/method_get.go new file mode 100644 index 00000000000..a6e7333f2e6 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/incidentrelations/method_get.go @@ -0,0 +1,51 @@ +package incidentrelations + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Relation +} + +// Get ... +func (c IncidentRelationsClient) Get(ctx context.Context, id IncidentRelationId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/incidentrelations/method_get_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/incidentrelations/method_get_autorest.go deleted file mode 100644 index 4cb22a2ba53..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/incidentrelations/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package incidentrelations - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *Relation -} - -// Get ... -func (c IncidentRelationsClient) Get(ctx context.Context, id IncidentRelationId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c IncidentRelationsClient) preparerForGet(ctx context.Context, id IncidentRelationId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c IncidentRelationsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/incidentrelations/method_list.go b/resource-manager/securityinsights/2021-09-01-preview/incidentrelations/method_list.go new file mode 100644 index 00000000000..80873d441b4 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/incidentrelations/method_list.go @@ -0,0 +1,127 @@ +package incidentrelations + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Relation +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Relation +} + +type ListOperationOptions struct { + Filter *string + Orderby *string + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c IncidentRelationsClient) List(ctx context.Context, id IncidentId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/relations", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Relation `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c IncidentRelationsClient) ListComplete(ctx context.Context, id IncidentId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, RelationOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c IncidentRelationsClient) ListCompleteMatchingPredicate(ctx context.Context, id IncidentId, options ListOperationOptions, predicate RelationOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Relation, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/incidentrelations/method_list_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/incidentrelations/method_list_autorest.go deleted file mode 100644 index a270a442886..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/incidentrelations/method_list_autorest.go +++ /dev/null @@ -1,225 +0,0 @@ -package incidentrelations - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]Relation - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []Relation -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ListOperationOptions struct { - Filter *string - Orderby *string - Top *int64 -} - -func DefaultListOperationOptions() ListOperationOptions { - return ListOperationOptions{} -} - -func (o ListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Filter != nil { - out["$filter"] = *o.Filter - } - - if o.Orderby != nil { - out["$orderby"] = *o.Orderby - } - - if o.Top != nil { - out["$top"] = *o.Top - } - - return out -} - -// List ... -func (c IncidentRelationsClient) List(ctx context.Context, id IncidentId, options ListOperationOptions) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c IncidentRelationsClient) preparerForList(ctx context.Context, id IncidentId, options ListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/relations", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c IncidentRelationsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c IncidentRelationsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []Relation `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c IncidentRelationsClient) ListComplete(ctx context.Context, id IncidentId, options ListOperationOptions) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, options, RelationOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c IncidentRelationsClient) ListCompleteMatchingPredicate(ctx context.Context, id IncidentId, options ListOperationOptions, predicate RelationOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]Relation, 0) - - page, err := c.List(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/incidents/client.go b/resource-manager/securityinsights/2021-09-01-preview/incidents/client.go index 659897d18d7..aaf38071c39 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/incidents/client.go +++ b/resource-manager/securityinsights/2021-09-01-preview/incidents/client.go @@ -1,18 +1,26 @@ package incidents -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type IncidentsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewIncidentsClientWithBaseURI(endpoint string) IncidentsClient { - return IncidentsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewIncidentsClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidents", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentsClient: %+v", err) } + + return &IncidentsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2021-09-01-preview/incidents/constants.go b/resource-manager/securityinsights/2021-09-01-preview/incidents/constants.go index 53073c5f397..a7c1b98fad1 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/incidents/constants.go +++ b/resource-manager/securityinsights/2021-09-01-preview/incidents/constants.go @@ -1,6 +1,10 @@ package incidents -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -41,6 +45,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -84,6 +101,19 @@ func PossibleValuesForIncidentClassification() []string { } } +func (s *IncidentClassification) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentClassification(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentClassification(input string) (*IncidentClassification, error) { vals := map[string]IncidentClassification{ "benignpositive": IncidentClassificationBenignPositive, @@ -118,6 +148,19 @@ func PossibleValuesForIncidentClassificationReason() []string { } } +func (s *IncidentClassificationReason) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentClassificationReason(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentClassificationReason(input string) (*IncidentClassificationReason, error) { vals := map[string]IncidentClassificationReason{ "inaccuratedata": IncidentClassificationReasonInaccurateData, @@ -148,6 +191,19 @@ func PossibleValuesForIncidentLabelType() []string { } } +func (s *IncidentLabelType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentLabelType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentLabelType(input string) (*IncidentLabelType, error) { vals := map[string]IncidentLabelType{ "system": IncidentLabelTypeSystem, @@ -180,6 +236,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, @@ -212,6 +281,19 @@ func PossibleValuesForIncidentStatus() []string { } } +func (s *IncidentStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentStatus(input string) (*IncidentStatus, error) { vals := map[string]IncidentStatus{ "active": IncidentStatusActive, @@ -243,6 +325,19 @@ func PossibleValuesForOwnerType() []string { } } +func (s *OwnerType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOwnerType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseOwnerType(input string) (*OwnerType, error) { vals := map[string]OwnerType{ "group": OwnerTypeGroup, diff --git a/resource-manager/securityinsights/2021-09-01-preview/incidents/method_createorupdate.go b/resource-manager/securityinsights/2021-09-01-preview/incidents/method_createorupdate.go new file mode 100644 index 00000000000..3fcc110ed02 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/incidents/method_createorupdate.go @@ -0,0 +1,56 @@ +package incidents + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Incident +} + +// CreateOrUpdate ... +func (c IncidentsClient) CreateOrUpdate(ctx context.Context, id IncidentId, input Incident) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/incidents/method_createorupdate_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/incidents/method_createorupdate_autorest.go deleted file mode 100644 index 837aa7c92a0..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/incidents/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package incidents - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *Incident -} - -// CreateOrUpdate ... -func (c IncidentsClient) CreateOrUpdate(ctx context.Context, id IncidentId, input Incident) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c IncidentsClient) preparerForCreateOrUpdate(ctx context.Context, id IncidentId, input Incident) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c IncidentsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/incidents/method_delete.go b/resource-manager/securityinsights/2021-09-01-preview/incidents/method_delete.go new file mode 100644 index 00000000000..9b3205af5fc --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/incidents/method_delete.go @@ -0,0 +1,47 @@ +package incidents + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c IncidentsClient) Delete(ctx context.Context, id IncidentId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/incidents/method_delete_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/incidents/method_delete_autorest.go deleted file mode 100644 index 280832422f8..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/incidents/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package incidents - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c IncidentsClient) Delete(ctx context.Context, id IncidentId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c IncidentsClient) preparerForDelete(ctx context.Context, id IncidentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c IncidentsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/incidents/method_get.go b/resource-manager/securityinsights/2021-09-01-preview/incidents/method_get.go new file mode 100644 index 00000000000..e6d4e9e933b --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/incidents/method_get.go @@ -0,0 +1,51 @@ +package incidents + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Incident +} + +// Get ... +func (c IncidentsClient) Get(ctx context.Context, id IncidentId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/incidents/method_get_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/incidents/method_get_autorest.go deleted file mode 100644 index d8d2b7debeb..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/incidents/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package incidents - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *Incident -} - -// Get ... -func (c IncidentsClient) Get(ctx context.Context, id IncidentId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c IncidentsClient) preparerForGet(ctx context.Context, id IncidentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c IncidentsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/incidents/method_list.go b/resource-manager/securityinsights/2021-09-01-preview/incidents/method_list.go new file mode 100644 index 00000000000..fe19cd4d9ff --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/incidents/method_list.go @@ -0,0 +1,127 @@ +package incidents + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Incident +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Incident +} + +type ListOperationOptions struct { + Filter *string + Orderby *string + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c IncidentsClient) List(ctx context.Context, id WorkspaceId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/incidents", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Incident `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c IncidentsClient) ListComplete(ctx context.Context, id WorkspaceId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, IncidentOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c IncidentsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ListOperationOptions, predicate IncidentOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Incident, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/incidents/method_list_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/incidents/method_list_autorest.go deleted file mode 100644 index 8d2f5acc547..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/incidents/method_list_autorest.go +++ /dev/null @@ -1,225 +0,0 @@ -package incidents - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]Incident - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []Incident -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ListOperationOptions struct { - Filter *string - Orderby *string - Top *int64 -} - -func DefaultListOperationOptions() ListOperationOptions { - return ListOperationOptions{} -} - -func (o ListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Filter != nil { - out["$filter"] = *o.Filter - } - - if o.Orderby != nil { - out["$orderby"] = *o.Orderby - } - - if o.Top != nil { - out["$top"] = *o.Top - } - - return out -} - -// List ... -func (c IncidentsClient) List(ctx context.Context, id WorkspaceId, options ListOperationOptions) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c IncidentsClient) preparerForList(ctx context.Context, id WorkspaceId, options ListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/incidents", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c IncidentsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c IncidentsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []Incident `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c IncidentsClient) ListComplete(ctx context.Context, id WorkspaceId, options ListOperationOptions) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, options, IncidentOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c IncidentsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ListOperationOptions, predicate IncidentOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]Incident, 0) - - page, err := c.List(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/incidentteam/client.go b/resource-manager/securityinsights/2021-09-01-preview/incidentteam/client.go index c48730b50ab..75ab2cfb3b1 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/incidentteam/client.go +++ b/resource-manager/securityinsights/2021-09-01-preview/incidentteam/client.go @@ -1,18 +1,26 @@ package incidentteam -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type IncidentTeamClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewIncidentTeamClientWithBaseURI(endpoint string) IncidentTeamClient { - return IncidentTeamClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewIncidentTeamClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentTeamClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidentteam", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentTeamClient: %+v", err) } + + return &IncidentTeamClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2021-09-01-preview/incidentteam/method_incidentscreateteam.go b/resource-manager/securityinsights/2021-09-01-preview/incidentteam/method_incidentscreateteam.go new file mode 100644 index 00000000000..934052e83a4 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/incidentteam/method_incidentscreateteam.go @@ -0,0 +1,56 @@ +package incidentteam + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentsCreateTeamOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *TeamInformation +} + +// IncidentsCreateTeam ... +func (c IncidentTeamClient) IncidentsCreateTeam(ctx context.Context, id IncidentId, input TeamProperties) (result IncidentsCreateTeamOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/createTeam", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/incidentteam/method_incidentscreateteam_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/incidentteam/method_incidentscreateteam_autorest.go deleted file mode 100644 index 028fc51c6a2..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/incidentteam/method_incidentscreateteam_autorest.go +++ /dev/null @@ -1,70 +0,0 @@ -package incidentteam - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IncidentsCreateTeamOperationResponse struct { - HttpResponse *http.Response - Model *TeamInformation -} - -// IncidentsCreateTeam ... -func (c IncidentTeamClient) IncidentsCreateTeam(ctx context.Context, id IncidentId, input TeamProperties) (result IncidentsCreateTeamOperationResponse, err error) { - req, err := c.preparerForIncidentsCreateTeam(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentteam.IncidentTeamClient", "IncidentsCreateTeam", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentteam.IncidentTeamClient", "IncidentsCreateTeam", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIncidentsCreateTeam(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentteam.IncidentTeamClient", "IncidentsCreateTeam", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIncidentsCreateTeam prepares the IncidentsCreateTeam request. -func (c IncidentTeamClient) preparerForIncidentsCreateTeam(ctx context.Context, id IncidentId, input TeamProperties) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/createTeam", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIncidentsCreateTeam handles the response to the IncidentsCreateTeam request. The method always -// closes the http.Response Body. -func (c IncidentTeamClient) responderForIncidentsCreateTeam(resp *http.Response) (result IncidentsCreateTeamOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/metadata/client.go b/resource-manager/securityinsights/2021-09-01-preview/metadata/client.go index 05f0e7940c0..59e4192159f 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/metadata/client.go +++ b/resource-manager/securityinsights/2021-09-01-preview/metadata/client.go @@ -1,18 +1,26 @@ package metadata -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type MetadataClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewMetadataClientWithBaseURI(endpoint string) MetadataClient { - return MetadataClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewMetadataClientWithBaseURI(sdkApi sdkEnv.Api) (*MetadataClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "metadata", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating MetadataClient: %+v", err) } + + return &MetadataClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2021-09-01-preview/metadata/constants.go b/resource-manager/securityinsights/2021-09-01-preview/metadata/constants.go index f83bc24f3e3..6ae0aae9bec 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/metadata/constants.go +++ b/resource-manager/securityinsights/2021-09-01-preview/metadata/constants.go @@ -1,6 +1,10 @@ package metadata -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -43,6 +47,19 @@ func PossibleValuesForKind() []string { } } +func (s *Kind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseKind(input string) (*Kind, error) { vals := map[string]Kind{ "analyticsrule": KindAnalyticsRule, @@ -83,6 +100,19 @@ func PossibleValuesForOperator() []string { } } +func (s *Operator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseOperator(input string) (*Operator, error) { vals := map[string]Operator{ "and": OperatorAND, @@ -115,6 +145,19 @@ func PossibleValuesForSourceKind() []string { } } +func (s *SourceKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSourceKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSourceKind(input string) (*SourceKind, error) { vals := map[string]SourceKind{ "community": SourceKindCommunity, @@ -147,6 +190,19 @@ func PossibleValuesForSupportTier() []string { } } +func (s *SupportTier) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSupportTier(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSupportTier(input string) (*SupportTier, error) { vals := map[string]SupportTier{ "community": SupportTierCommunity, diff --git a/resource-manager/securityinsights/2021-09-01-preview/metadata/method_create.go b/resource-manager/securityinsights/2021-09-01-preview/metadata/method_create.go new file mode 100644 index 00000000000..36522e6397c --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/metadata/method_create.go @@ -0,0 +1,56 @@ +package metadata + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *MetadataModel +} + +// Create ... +func (c MetadataClient) Create(ctx context.Context, id MetadataId, input MetadataModel) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/metadata/method_create_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/metadata/method_create_autorest.go deleted file mode 100644 index 1ae47584687..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/metadata/method_create_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package metadata - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOperationResponse struct { - HttpResponse *http.Response - Model *MetadataModel -} - -// Create ... -func (c MetadataClient) Create(ctx context.Context, id MetadataId, input MetadataModel) (result CreateOperationResponse, err error) { - req, err := c.preparerForCreate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Create", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Create", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Create", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreate prepares the Create request. -func (c MetadataClient) preparerForCreate(ctx context.Context, id MetadataId, input MetadataModel) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreate handles the response to the Create request. The method always -// closes the http.Response Body. -func (c MetadataClient) responderForCreate(resp *http.Response) (result CreateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/metadata/method_delete.go b/resource-manager/securityinsights/2021-09-01-preview/metadata/method_delete.go new file mode 100644 index 00000000000..559f479cb03 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/metadata/method_delete.go @@ -0,0 +1,47 @@ +package metadata + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c MetadataClient) Delete(ctx context.Context, id MetadataId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/metadata/method_delete_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/metadata/method_delete_autorest.go deleted file mode 100644 index 3a151eefd21..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/metadata/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package metadata - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c MetadataClient) Delete(ctx context.Context, id MetadataId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c MetadataClient) preparerForDelete(ctx context.Context, id MetadataId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c MetadataClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/metadata/method_get.go b/resource-manager/securityinsights/2021-09-01-preview/metadata/method_get.go new file mode 100644 index 00000000000..a687bafec62 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/metadata/method_get.go @@ -0,0 +1,51 @@ +package metadata + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *MetadataModel +} + +// Get ... +func (c MetadataClient) Get(ctx context.Context, id MetadataId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/metadata/method_get_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/metadata/method_get_autorest.go deleted file mode 100644 index 25827d74702..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/metadata/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package metadata - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *MetadataModel -} - -// Get ... -func (c MetadataClient) Get(ctx context.Context, id MetadataId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c MetadataClient) preparerForGet(ctx context.Context, id MetadataId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c MetadataClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/metadata/method_list.go b/resource-manager/securityinsights/2021-09-01-preview/metadata/method_list.go new file mode 100644 index 00000000000..58267143629 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/metadata/method_list.go @@ -0,0 +1,131 @@ +package metadata + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]MetadataModel +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []MetadataModel +} + +type ListOperationOptions struct { + Filter *string + Orderby *string + Skip *int64 + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c MetadataClient) List(ctx context.Context, id WorkspaceId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/metadata", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]MetadataModel `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c MetadataClient) ListComplete(ctx context.Context, id WorkspaceId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, MetadataModelOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c MetadataClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ListOperationOptions, predicate MetadataModelOperationPredicate) (result ListCompleteResult, err error) { + items := make([]MetadataModel, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/metadata/method_list_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/metadata/method_list_autorest.go deleted file mode 100644 index e5f025d62ee..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/metadata/method_list_autorest.go +++ /dev/null @@ -1,230 +0,0 @@ -package metadata - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]MetadataModel - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []MetadataModel -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ListOperationOptions struct { - Filter *string - Orderby *string - Skip *int64 - Top *int64 -} - -func DefaultListOperationOptions() ListOperationOptions { - return ListOperationOptions{} -} - -func (o ListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Filter != nil { - out["$filter"] = *o.Filter - } - - if o.Orderby != nil { - out["$orderby"] = *o.Orderby - } - - if o.Skip != nil { - out["$skip"] = *o.Skip - } - - if o.Top != nil { - out["$top"] = *o.Top - } - - return out -} - -// List ... -func (c MetadataClient) List(ctx context.Context, id WorkspaceId, options ListOperationOptions) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c MetadataClient) preparerForList(ctx context.Context, id WorkspaceId, options ListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/metadata", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c MetadataClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c MetadataClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []MetadataModel `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c MetadataClient) ListComplete(ctx context.Context, id WorkspaceId, options ListOperationOptions) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, options, MetadataModelOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c MetadataClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ListOperationOptions, predicate MetadataModelOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]MetadataModel, 0) - - page, err := c.List(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/metadata/method_update.go b/resource-manager/securityinsights/2021-09-01-preview/metadata/method_update.go new file mode 100644 index 00000000000..47f777cee27 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/metadata/method_update.go @@ -0,0 +1,55 @@ +package metadata + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *MetadataModel +} + +// Update ... +func (c MetadataClient) Update(ctx context.Context, id MetadataId, input MetadataPatch) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/metadata/method_update_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/metadata/method_update_autorest.go deleted file mode 100644 index a4bd18d08d6..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/metadata/method_update_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package metadata - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type UpdateOperationResponse struct { - HttpResponse *http.Response - Model *MetadataModel -} - -// Update ... -func (c MetadataClient) Update(ctx context.Context, id MetadataId, input MetadataPatch) (result UpdateOperationResponse, err error) { - req, err := c.preparerForUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Update", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Update", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Update", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForUpdate prepares the Update request. -func (c MetadataClient) preparerForUpdate(ctx context.Context, id MetadataId, input MetadataPatch) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPatch(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForUpdate handles the response to the Update request. The method always -// closes the http.Response Body. -func (c MetadataClient) responderForUpdate(resp *http.Response) (result UpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/officeconsents/client.go b/resource-manager/securityinsights/2021-09-01-preview/officeconsents/client.go index 7f0466f7160..2c2efc37d3d 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/officeconsents/client.go +++ b/resource-manager/securityinsights/2021-09-01-preview/officeconsents/client.go @@ -1,18 +1,26 @@ package officeconsents -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type OfficeConsentsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewOfficeConsentsClientWithBaseURI(endpoint string) OfficeConsentsClient { - return OfficeConsentsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewOfficeConsentsClientWithBaseURI(sdkApi sdkEnv.Api) (*OfficeConsentsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "officeconsents", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating OfficeConsentsClient: %+v", err) } + + return &OfficeConsentsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2021-09-01-preview/officeconsents/method_delete.go b/resource-manager/securityinsights/2021-09-01-preview/officeconsents/method_delete.go new file mode 100644 index 00000000000..3c098e73784 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/officeconsents/method_delete.go @@ -0,0 +1,47 @@ +package officeconsents + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c OfficeConsentsClient) Delete(ctx context.Context, id OfficeConsentId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/officeconsents/method_delete_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/officeconsents/method_delete_autorest.go deleted file mode 100644 index 231f4a35afd..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/officeconsents/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package officeconsents - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c OfficeConsentsClient) Delete(ctx context.Context, id OfficeConsentId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "officeconsents.OfficeConsentsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "officeconsents.OfficeConsentsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "officeconsents.OfficeConsentsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c OfficeConsentsClient) preparerForDelete(ctx context.Context, id OfficeConsentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c OfficeConsentsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/officeconsents/method_get.go b/resource-manager/securityinsights/2021-09-01-preview/officeconsents/method_get.go new file mode 100644 index 00000000000..4d81ae6bf20 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/officeconsents/method_get.go @@ -0,0 +1,51 @@ +package officeconsents + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *OfficeConsent +} + +// Get ... +func (c OfficeConsentsClient) Get(ctx context.Context, id OfficeConsentId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/officeconsents/method_get_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/officeconsents/method_get_autorest.go deleted file mode 100644 index bb10097614d..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/officeconsents/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package officeconsents - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *OfficeConsent -} - -// Get ... -func (c OfficeConsentsClient) Get(ctx context.Context, id OfficeConsentId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "officeconsents.OfficeConsentsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "officeconsents.OfficeConsentsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "officeconsents.OfficeConsentsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c OfficeConsentsClient) preparerForGet(ctx context.Context, id OfficeConsentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c OfficeConsentsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/officeconsents/method_list.go b/resource-manager/securityinsights/2021-09-01-preview/officeconsents/method_list.go new file mode 100644 index 00000000000..e23bd7dddfb --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/officeconsents/method_list.go @@ -0,0 +1,91 @@ +package officeconsents + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]OfficeConsent +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []OfficeConsent +} + +// List ... +func (c OfficeConsentsClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/officeConsents", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]OfficeConsent `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c OfficeConsentsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, OfficeConsentOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c OfficeConsentsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate OfficeConsentOperationPredicate) (result ListCompleteResult, err error) { + items := make([]OfficeConsent, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/officeconsents/method_list_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/officeconsents/method_list_autorest.go deleted file mode 100644 index d306e76d443..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/officeconsents/method_list_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package officeconsents - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]OfficeConsent - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []OfficeConsent -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c OfficeConsentsClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "officeconsents.OfficeConsentsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "officeconsents.OfficeConsentsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "officeconsents.OfficeConsentsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c OfficeConsentsClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/officeConsents", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c OfficeConsentsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c OfficeConsentsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []OfficeConsent `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "officeconsents.OfficeConsentsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "officeconsents.OfficeConsentsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "officeconsents.OfficeConsentsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c OfficeConsentsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, OfficeConsentOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c OfficeConsentsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate OfficeConsentOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]OfficeConsent, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/repositories/client.go b/resource-manager/securityinsights/2021-09-01-preview/repositories/client.go index 562953712b0..62b7be88387 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/repositories/client.go +++ b/resource-manager/securityinsights/2021-09-01-preview/repositories/client.go @@ -1,18 +1,26 @@ package repositories -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type RepositoriesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewRepositoriesClientWithBaseURI(endpoint string) RepositoriesClient { - return RepositoriesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewRepositoriesClientWithBaseURI(sdkApi sdkEnv.Api) (*RepositoriesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "repositories", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating RepositoriesClient: %+v", err) } + + return &RepositoriesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2021-09-01-preview/repositories/constants.go b/resource-manager/securityinsights/2021-09-01-preview/repositories/constants.go index b8d5b729aae..828121b73be 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/repositories/constants.go +++ b/resource-manager/securityinsights/2021-09-01-preview/repositories/constants.go @@ -1,6 +1,10 @@ package repositories -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -19,6 +23,19 @@ func PossibleValuesForRepoType() []string { } } +func (s *RepoType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRepoType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseRepoType(input string) (*RepoType, error) { vals := map[string]RepoType{ "devops": RepoTypeDevOps, diff --git a/resource-manager/securityinsights/2021-09-01-preview/repositories/method_sourcecontrollistrepositories.go b/resource-manager/securityinsights/2021-09-01-preview/repositories/method_sourcecontrollistrepositories.go new file mode 100644 index 00000000000..3a007266273 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/repositories/method_sourcecontrollistrepositories.go @@ -0,0 +1,91 @@ +package repositories + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SourceControllistRepositoriesOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Repo +} + +type SourceControllistRepositoriesCompleteResult struct { + LatestHttpResponse *http.Response + Items []Repo +} + +// SourceControllistRepositories ... +func (c RepositoriesClient) SourceControllistRepositories(ctx context.Context, id WorkspaceId, input RepoType) (result SourceControllistRepositoriesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/listRepositories", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Repo `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// SourceControllistRepositoriesComplete retrieves all the results into a single object +func (c RepositoriesClient) SourceControllistRepositoriesComplete(ctx context.Context, id WorkspaceId, input RepoType) (SourceControllistRepositoriesCompleteResult, error) { + return c.SourceControllistRepositoriesCompleteMatchingPredicate(ctx, id, input, RepoOperationPredicate{}) +} + +// SourceControllistRepositoriesCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c RepositoriesClient) SourceControllistRepositoriesCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, input RepoType, predicate RepoOperationPredicate) (result SourceControllistRepositoriesCompleteResult, err error) { + items := make([]Repo, 0) + + resp, err := c.SourceControllistRepositories(ctx, id, input) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = SourceControllistRepositoriesCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/repositories/method_sourcecontrollistrepositories_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/repositories/method_sourcecontrollistrepositories_autorest.go deleted file mode 100644 index 1bbe7743728..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/repositories/method_sourcecontrollistrepositories_autorest.go +++ /dev/null @@ -1,187 +0,0 @@ -package repositories - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type SourceControllistRepositoriesOperationResponse struct { - HttpResponse *http.Response - Model *[]Repo - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (SourceControllistRepositoriesOperationResponse, error) -} - -type SourceControllistRepositoriesCompleteResult struct { - Items []Repo -} - -func (r SourceControllistRepositoriesOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r SourceControllistRepositoriesOperationResponse) LoadMore(ctx context.Context) (resp SourceControllistRepositoriesOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// SourceControllistRepositories ... -func (c RepositoriesClient) SourceControllistRepositories(ctx context.Context, id WorkspaceId, input RepoType) (resp SourceControllistRepositoriesOperationResponse, err error) { - req, err := c.preparerForSourceControllistRepositories(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "repositories.RepositoriesClient", "SourceControllistRepositories", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "repositories.RepositoriesClient", "SourceControllistRepositories", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForSourceControllistRepositories(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "repositories.RepositoriesClient", "SourceControllistRepositories", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForSourceControllistRepositories prepares the SourceControllistRepositories request. -func (c RepositoriesClient) preparerForSourceControllistRepositories(ctx context.Context, id WorkspaceId, input RepoType) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/listRepositories", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForSourceControllistRepositoriesWithNextLink prepares the SourceControllistRepositories request with the given nextLink token. -func (c RepositoriesClient) preparerForSourceControllistRepositoriesWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForSourceControllistRepositories handles the response to the SourceControllistRepositories request. The method always -// closes the http.Response Body. -func (c RepositoriesClient) responderForSourceControllistRepositories(resp *http.Response) (result SourceControllistRepositoriesOperationResponse, err error) { - type page struct { - Values []Repo `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result SourceControllistRepositoriesOperationResponse, err error) { - req, err := c.preparerForSourceControllistRepositoriesWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "repositories.RepositoriesClient", "SourceControllistRepositories", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "repositories.RepositoriesClient", "SourceControllistRepositories", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForSourceControllistRepositories(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "repositories.RepositoriesClient", "SourceControllistRepositories", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// SourceControllistRepositoriesComplete retrieves all of the results into a single object -func (c RepositoriesClient) SourceControllistRepositoriesComplete(ctx context.Context, id WorkspaceId, input RepoType) (SourceControllistRepositoriesCompleteResult, error) { - return c.SourceControllistRepositoriesCompleteMatchingPredicate(ctx, id, input, RepoOperationPredicate{}) -} - -// SourceControllistRepositoriesCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c RepositoriesClient) SourceControllistRepositoriesCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, input RepoType, predicate RepoOperationPredicate) (resp SourceControllistRepositoriesCompleteResult, err error) { - items := make([]Repo, 0) - - page, err := c.SourceControllistRepositories(ctx, id, input) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := SourceControllistRepositoriesCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/sentinelonboardingstates/client.go b/resource-manager/securityinsights/2021-09-01-preview/sentinelonboardingstates/client.go index 0ae442ba3fa..94701ed853a 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/sentinelonboardingstates/client.go +++ b/resource-manager/securityinsights/2021-09-01-preview/sentinelonboardingstates/client.go @@ -1,18 +1,26 @@ package sentinelonboardingstates -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type SentinelOnboardingStatesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewSentinelOnboardingStatesClientWithBaseURI(endpoint string) SentinelOnboardingStatesClient { - return SentinelOnboardingStatesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewSentinelOnboardingStatesClientWithBaseURI(sdkApi sdkEnv.Api) (*SentinelOnboardingStatesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sentinelonboardingstates", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SentinelOnboardingStatesClient: %+v", err) } + + return &SentinelOnboardingStatesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2021-09-01-preview/sentinelonboardingstates/method_create.go b/resource-manager/securityinsights/2021-09-01-preview/sentinelonboardingstates/method_create.go new file mode 100644 index 00000000000..af163a9d66b --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/sentinelonboardingstates/method_create.go @@ -0,0 +1,56 @@ +package sentinelonboardingstates + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SentinelOnboardingState +} + +// Create ... +func (c SentinelOnboardingStatesClient) Create(ctx context.Context, id OnboardingStateId, input SentinelOnboardingState) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/sentinelonboardingstates/method_create_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/sentinelonboardingstates/method_create_autorest.go deleted file mode 100644 index 9ad88e95157..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/sentinelonboardingstates/method_create_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package sentinelonboardingstates - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOperationResponse struct { - HttpResponse *http.Response - Model *SentinelOnboardingState -} - -// Create ... -func (c SentinelOnboardingStatesClient) Create(ctx context.Context, id OnboardingStateId, input SentinelOnboardingState) (result CreateOperationResponse, err error) { - req, err := c.preparerForCreate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Create", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Create", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Create", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreate prepares the Create request. -func (c SentinelOnboardingStatesClient) preparerForCreate(ctx context.Context, id OnboardingStateId, input SentinelOnboardingState) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreate handles the response to the Create request. The method always -// closes the http.Response Body. -func (c SentinelOnboardingStatesClient) responderForCreate(resp *http.Response) (result CreateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/sentinelonboardingstates/method_delete.go b/resource-manager/securityinsights/2021-09-01-preview/sentinelonboardingstates/method_delete.go new file mode 100644 index 00000000000..1c6c5e372d7 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/sentinelonboardingstates/method_delete.go @@ -0,0 +1,47 @@ +package sentinelonboardingstates + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c SentinelOnboardingStatesClient) Delete(ctx context.Context, id OnboardingStateId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/sentinelonboardingstates/method_delete_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/sentinelonboardingstates/method_delete_autorest.go deleted file mode 100644 index 65fa74282f7..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/sentinelonboardingstates/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package sentinelonboardingstates - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c SentinelOnboardingStatesClient) Delete(ctx context.Context, id OnboardingStateId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c SentinelOnboardingStatesClient) preparerForDelete(ctx context.Context, id OnboardingStateId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c SentinelOnboardingStatesClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/sentinelonboardingstates/method_get.go b/resource-manager/securityinsights/2021-09-01-preview/sentinelonboardingstates/method_get.go new file mode 100644 index 00000000000..82165662910 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/sentinelonboardingstates/method_get.go @@ -0,0 +1,51 @@ +package sentinelonboardingstates + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SentinelOnboardingState +} + +// Get ... +func (c SentinelOnboardingStatesClient) Get(ctx context.Context, id OnboardingStateId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/sentinelonboardingstates/method_get_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/sentinelonboardingstates/method_get_autorest.go deleted file mode 100644 index d6174a7522a..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/sentinelonboardingstates/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package sentinelonboardingstates - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *SentinelOnboardingState -} - -// Get ... -func (c SentinelOnboardingStatesClient) Get(ctx context.Context, id OnboardingStateId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c SentinelOnboardingStatesClient) preparerForGet(ctx context.Context, id OnboardingStateId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c SentinelOnboardingStatesClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/sentinelonboardingstates/method_list.go b/resource-manager/securityinsights/2021-09-01-preview/sentinelonboardingstates/method_list.go new file mode 100644 index 00000000000..2efd1d41230 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/sentinelonboardingstates/method_list.go @@ -0,0 +1,52 @@ +package sentinelonboardingstates + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SentinelOnboardingStatesList +} + +// List ... +func (c SentinelOnboardingStatesClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/onboardingStates", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/sentinelonboardingstates/method_list_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/sentinelonboardingstates/method_list_autorest.go deleted file mode 100644 index 6a00bb3d3fd..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/sentinelonboardingstates/method_list_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package sentinelonboardingstates - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *SentinelOnboardingStatesList -} - -// List ... -func (c SentinelOnboardingStatesClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForList prepares the List request. -func (c SentinelOnboardingStatesClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/onboardingStates", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c SentinelOnboardingStatesClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/settings/client.go b/resource-manager/securityinsights/2021-09-01-preview/settings/client.go index fe7a909262c..7a9bd9ec8a1 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/settings/client.go +++ b/resource-manager/securityinsights/2021-09-01-preview/settings/client.go @@ -1,18 +1,26 @@ package settings -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type SettingsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewSettingsClientWithBaseURI(endpoint string) SettingsClient { - return SettingsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewSettingsClientWithBaseURI(sdkApi sdkEnv.Api) (*SettingsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "settings", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SettingsClient: %+v", err) } + + return &SettingsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2021-09-01-preview/settings/constants.go b/resource-manager/securityinsights/2021-09-01-preview/settings/constants.go index e8b75fd9e75..692555e3b04 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/settings/constants.go +++ b/resource-manager/securityinsights/2021-09-01-preview/settings/constants.go @@ -1,6 +1,10 @@ package settings -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -23,6 +27,19 @@ func PossibleValuesForSettingKind() []string { } } +func (s *SettingKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSettingKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSettingKind(input string) (*SettingKind, error) { vals := map[string]SettingKind{ "anomalies": SettingKindAnomalies, @@ -57,6 +74,19 @@ func PossibleValuesForUebaDataSources() []string { } } +func (s *UebaDataSources) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseUebaDataSources(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseUebaDataSources(input string) (*UebaDataSources, error) { vals := map[string]UebaDataSources{ "auditlogs": UebaDataSourcesAuditLogs, diff --git a/resource-manager/securityinsights/2021-09-01-preview/settings/method_productsettingsdelete.go b/resource-manager/securityinsights/2021-09-01-preview/settings/method_productsettingsdelete.go new file mode 100644 index 00000000000..3306b03a761 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/settings/method_productsettingsdelete.go @@ -0,0 +1,47 @@ +package settings + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProductSettingsDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// ProductSettingsDelete ... +func (c SettingsClient) ProductSettingsDelete(ctx context.Context, id SettingId) (result ProductSettingsDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/settings/method_productsettingsdelete_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/settings/method_productsettingsdelete_autorest.go deleted file mode 100644 index 820be252b48..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/settings/method_productsettingsdelete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package settings - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ProductSettingsDeleteOperationResponse struct { - HttpResponse *http.Response -} - -// ProductSettingsDelete ... -func (c SettingsClient) ProductSettingsDelete(ctx context.Context, id SettingId) (result ProductSettingsDeleteOperationResponse, err error) { - req, err := c.preparerForProductSettingsDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "settings.SettingsClient", "ProductSettingsDelete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "settings.SettingsClient", "ProductSettingsDelete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForProductSettingsDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "settings.SettingsClient", "ProductSettingsDelete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForProductSettingsDelete prepares the ProductSettingsDelete request. -func (c SettingsClient) preparerForProductSettingsDelete(ctx context.Context, id SettingId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForProductSettingsDelete handles the response to the ProductSettingsDelete request. The method always -// closes the http.Response Body. -func (c SettingsClient) responderForProductSettingsDelete(resp *http.Response) (result ProductSettingsDeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/settings/method_productsettingsget.go b/resource-manager/securityinsights/2021-09-01-preview/settings/method_productsettingsget.go new file mode 100644 index 00000000000..3d546bae766 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/settings/method_productsettingsget.go @@ -0,0 +1,58 @@ +package settings + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProductSettingsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Settings +} + +// ProductSettingsGet ... +func (c SettingsClient) ProductSettingsGet(ctx context.Context, id SettingId) (result ProductSettingsGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalSettingsImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/settings/method_productsettingsget_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/settings/method_productsettingsget_autorest.go deleted file mode 100644 index bcaeab3e1a3..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/settings/method_productsettingsget_autorest.go +++ /dev/null @@ -1,77 +0,0 @@ -package settings - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ProductSettingsGetOperationResponse struct { - HttpResponse *http.Response - Model *Settings -} - -// ProductSettingsGet ... -func (c SettingsClient) ProductSettingsGet(ctx context.Context, id SettingId) (result ProductSettingsGetOperationResponse, err error) { - req, err := c.preparerForProductSettingsGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "settings.SettingsClient", "ProductSettingsGet", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "settings.SettingsClient", "ProductSettingsGet", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForProductSettingsGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "settings.SettingsClient", "ProductSettingsGet", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForProductSettingsGet prepares the ProductSettingsGet request. -func (c SettingsClient) preparerForProductSettingsGet(ctx context.Context, id SettingId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForProductSettingsGet handles the response to the ProductSettingsGet request. The method always -// closes the http.Response Body. -func (c SettingsClient) responderForProductSettingsGet(resp *http.Response) (result ProductSettingsGetOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalSettingsImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/settings/method_productsettingslist.go b/resource-manager/securityinsights/2021-09-01-preview/settings/method_productsettingslist.go new file mode 100644 index 00000000000..55114738bc5 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/settings/method_productsettingslist.go @@ -0,0 +1,52 @@ +package settings + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProductSettingsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SettingList +} + +// ProductSettingsList ... +func (c SettingsClient) ProductSettingsList(ctx context.Context, id WorkspaceId) (result ProductSettingsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/settings", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/settings/method_productsettingslist_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/settings/method_productsettingslist_autorest.go deleted file mode 100644 index 1242ef0a94b..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/settings/method_productsettingslist_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package settings - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ProductSettingsListOperationResponse struct { - HttpResponse *http.Response - Model *SettingList -} - -// ProductSettingsList ... -func (c SettingsClient) ProductSettingsList(ctx context.Context, id WorkspaceId) (result ProductSettingsListOperationResponse, err error) { - req, err := c.preparerForProductSettingsList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "settings.SettingsClient", "ProductSettingsList", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "settings.SettingsClient", "ProductSettingsList", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForProductSettingsList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "settings.SettingsClient", "ProductSettingsList", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForProductSettingsList prepares the ProductSettingsList request. -func (c SettingsClient) preparerForProductSettingsList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/settings", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForProductSettingsList handles the response to the ProductSettingsList request. The method always -// closes the http.Response Body. -func (c SettingsClient) responderForProductSettingsList(resp *http.Response) (result ProductSettingsListOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/settings/method_productsettingsupdate.go b/resource-manager/securityinsights/2021-09-01-preview/settings/method_productsettingsupdate.go new file mode 100644 index 00000000000..1f33013bb47 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/settings/method_productsettingsupdate.go @@ -0,0 +1,62 @@ +package settings + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProductSettingsUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Settings +} + +// ProductSettingsUpdate ... +func (c SettingsClient) ProductSettingsUpdate(ctx context.Context, id SettingId, input Settings) (result ProductSettingsUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalSettingsImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/settings/method_productsettingsupdate_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/settings/method_productsettingsupdate_autorest.go deleted file mode 100644 index 1b7573688b3..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/settings/method_productsettingsupdate_autorest.go +++ /dev/null @@ -1,78 +0,0 @@ -package settings - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ProductSettingsUpdateOperationResponse struct { - HttpResponse *http.Response - Model *Settings -} - -// ProductSettingsUpdate ... -func (c SettingsClient) ProductSettingsUpdate(ctx context.Context, id SettingId, input Settings) (result ProductSettingsUpdateOperationResponse, err error) { - req, err := c.preparerForProductSettingsUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "settings.SettingsClient", "ProductSettingsUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "settings.SettingsClient", "ProductSettingsUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForProductSettingsUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "settings.SettingsClient", "ProductSettingsUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForProductSettingsUpdate prepares the ProductSettingsUpdate request. -func (c SettingsClient) preparerForProductSettingsUpdate(ctx context.Context, id SettingId, input Settings) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForProductSettingsUpdate handles the response to the ProductSettingsUpdate request. The method always -// closes the http.Response Body. -func (c SettingsClient) responderForProductSettingsUpdate(resp *http.Response) (result ProductSettingsUpdateOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalSettingsImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/sourcecontrols/client.go b/resource-manager/securityinsights/2021-09-01-preview/sourcecontrols/client.go index c0d5d5424c2..9bfd651a63a 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/sourcecontrols/client.go +++ b/resource-manager/securityinsights/2021-09-01-preview/sourcecontrols/client.go @@ -1,18 +1,26 @@ package sourcecontrols -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type SourceControlsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewSourceControlsClientWithBaseURI(endpoint string) SourceControlsClient { - return SourceControlsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewSourceControlsClientWithBaseURI(sdkApi sdkEnv.Api) (*SourceControlsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sourcecontrols", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SourceControlsClient: %+v", err) } + + return &SourceControlsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2021-09-01-preview/sourcecontrols/constants.go b/resource-manager/securityinsights/2021-09-01-preview/sourcecontrols/constants.go index 224c3a25f83..3a0fbd1e544 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/sourcecontrols/constants.go +++ b/resource-manager/securityinsights/2021-09-01-preview/sourcecontrols/constants.go @@ -1,6 +1,10 @@ package sourcecontrols -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -19,6 +23,19 @@ func PossibleValuesForContentType() []string { } } +func (s *ContentType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseContentType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseContentType(input string) (*ContentType, error) { vals := map[string]ContentType{ "analyticrule": ContentTypeAnalyticRule, @@ -47,6 +64,19 @@ func PossibleValuesForRepoType() []string { } } +func (s *RepoType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRepoType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseRepoType(input string) (*RepoType, error) { vals := map[string]RepoType{ "devops": RepoTypeDevOps, diff --git a/resource-manager/securityinsights/2021-09-01-preview/sourcecontrols/method_create.go b/resource-manager/securityinsights/2021-09-01-preview/sourcecontrols/method_create.go new file mode 100644 index 00000000000..ee70a7cb64f --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/sourcecontrols/method_create.go @@ -0,0 +1,56 @@ +package sourcecontrols + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SourceControl +} + +// Create ... +func (c SourceControlsClient) Create(ctx context.Context, id SourceControlId, input SourceControl) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/sourcecontrols/method_create_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/sourcecontrols/method_create_autorest.go deleted file mode 100644 index fbf91a3cc21..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/sourcecontrols/method_create_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package sourcecontrols - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOperationResponse struct { - HttpResponse *http.Response - Model *SourceControl -} - -// Create ... -func (c SourceControlsClient) Create(ctx context.Context, id SourceControlId, input SourceControl) (result CreateOperationResponse, err error) { - req, err := c.preparerForCreate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "Create", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "Create", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "Create", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreate prepares the Create request. -func (c SourceControlsClient) preparerForCreate(ctx context.Context, id SourceControlId, input SourceControl) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreate handles the response to the Create request. The method always -// closes the http.Response Body. -func (c SourceControlsClient) responderForCreate(resp *http.Response) (result CreateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/sourcecontrols/method_delete.go b/resource-manager/securityinsights/2021-09-01-preview/sourcecontrols/method_delete.go new file mode 100644 index 00000000000..579d919b3df --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/sourcecontrols/method_delete.go @@ -0,0 +1,47 @@ +package sourcecontrols + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c SourceControlsClient) Delete(ctx context.Context, id SourceControlId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/sourcecontrols/method_delete_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/sourcecontrols/method_delete_autorest.go deleted file mode 100644 index 44699d5360d..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/sourcecontrols/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package sourcecontrols - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c SourceControlsClient) Delete(ctx context.Context, id SourceControlId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c SourceControlsClient) preparerForDelete(ctx context.Context, id SourceControlId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c SourceControlsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/sourcecontrols/method_get.go b/resource-manager/securityinsights/2021-09-01-preview/sourcecontrols/method_get.go new file mode 100644 index 00000000000..3a1cb1bf276 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/sourcecontrols/method_get.go @@ -0,0 +1,51 @@ +package sourcecontrols + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SourceControl +} + +// Get ... +func (c SourceControlsClient) Get(ctx context.Context, id SourceControlId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/sourcecontrols/method_get_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/sourcecontrols/method_get_autorest.go deleted file mode 100644 index 80b8d99a662..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/sourcecontrols/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package sourcecontrols - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *SourceControl -} - -// Get ... -func (c SourceControlsClient) Get(ctx context.Context, id SourceControlId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c SourceControlsClient) preparerForGet(ctx context.Context, id SourceControlId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c SourceControlsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/sourcecontrols/method_list.go b/resource-manager/securityinsights/2021-09-01-preview/sourcecontrols/method_list.go new file mode 100644 index 00000000000..f058d0ec61e --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/sourcecontrols/method_list.go @@ -0,0 +1,91 @@ +package sourcecontrols + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SourceControl +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []SourceControl +} + +// List ... +func (c SourceControlsClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/sourceControls", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]SourceControl `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c SourceControlsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, SourceControlOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SourceControlsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate SourceControlOperationPredicate) (result ListCompleteResult, err error) { + items := make([]SourceControl, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/sourcecontrols/method_list_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/sourcecontrols/method_list_autorest.go deleted file mode 100644 index 04f2a205623..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/sourcecontrols/method_list_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package sourcecontrols - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]SourceControl - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []SourceControl -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c SourceControlsClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c SourceControlsClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/sourceControls", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c SourceControlsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c SourceControlsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []SourceControl `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c SourceControlsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, SourceControlOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c SourceControlsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate SourceControlOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]SourceControl, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/client.go b/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/client.go index 35caff31357..edf96c3143f 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/client.go +++ b/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/client.go @@ -1,18 +1,26 @@ package threatintelligence -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type ThreatIntelligenceClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewThreatIntelligenceClientWithBaseURI(endpoint string) ThreatIntelligenceClient { - return ThreatIntelligenceClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewThreatIntelligenceClientWithBaseURI(sdkApi sdkEnv.Api) (*ThreatIntelligenceClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "threatintelligence", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ThreatIntelligenceClient: %+v", err) } + + return &ThreatIntelligenceClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/constants.go b/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/constants.go index 3549cbffe94..3047e7d6d68 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/constants.go +++ b/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/constants.go @@ -1,6 +1,10 @@ package threatintelligence -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -17,6 +21,19 @@ func PossibleValuesForThreatIntelligenceResourceKindEnum() []string { } } +func (s *ThreatIntelligenceResourceKindEnum) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseThreatIntelligenceResourceKindEnum(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseThreatIntelligenceResourceKindEnum(input string) (*ThreatIntelligenceResourceKindEnum, error) { vals := map[string]ThreatIntelligenceResourceKindEnum{ "indicator": ThreatIntelligenceResourceKindEnumIndicator, @@ -46,6 +63,19 @@ func PossibleValuesForThreatIntelligenceSortingCriteriaEnum() []string { } } +func (s *ThreatIntelligenceSortingCriteriaEnum) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseThreatIntelligenceSortingCriteriaEnum(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseThreatIntelligenceSortingCriteriaEnum(input string) (*ThreatIntelligenceSortingCriteriaEnum, error) { vals := map[string]ThreatIntelligenceSortingCriteriaEnum{ "ascending": ThreatIntelligenceSortingCriteriaEnumAscending, diff --git a/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatorappendtags.go b/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatorappendtags.go new file mode 100644 index 00000000000..4384327485d --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatorappendtags.go @@ -0,0 +1,51 @@ +package threatintelligence + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorAppendTagsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// IndicatorAppendTags ... +func (c ThreatIntelligenceClient) IndicatorAppendTags(ctx context.Context, id IndicatorId, input ThreatIntelligenceAppendTags) (result IndicatorAppendTagsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/appendTags", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatorappendtags_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatorappendtags_autorest.go deleted file mode 100644 index 18b86a166fe..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatorappendtags_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package threatintelligence - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorAppendTagsOperationResponse struct { - HttpResponse *http.Response -} - -// IndicatorAppendTags ... -func (c ThreatIntelligenceClient) IndicatorAppendTags(ctx context.Context, id IndicatorId, input ThreatIntelligenceAppendTags) (result IndicatorAppendTagsOperationResponse, err error) { - req, err := c.preparerForIndicatorAppendTags(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorAppendTags", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorAppendTags", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorAppendTags(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorAppendTags", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorAppendTags prepares the IndicatorAppendTags request. -func (c ThreatIntelligenceClient) preparerForIndicatorAppendTags(ctx context.Context, id IndicatorId, input ThreatIntelligenceAppendTags) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/appendTags", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorAppendTags handles the response to the IndicatorAppendTags request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorAppendTags(resp *http.Response) (result IndicatorAppendTagsOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatorcreate.go b/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatorcreate.go new file mode 100644 index 00000000000..9cd68b9070e --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatorcreate.go @@ -0,0 +1,63 @@ +package threatintelligence + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorCreateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ThreatIntelligenceInformation +} + +// IndicatorCreate ... +func (c ThreatIntelligenceClient) IndicatorCreate(ctx context.Context, id IndicatorId, input ThreatIntelligenceIndicatorModelForRequestBody) (result IndicatorCreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatorcreate_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatorcreate_autorest.go deleted file mode 100644 index 1276c39b09a..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatorcreate_autorest.go +++ /dev/null @@ -1,78 +0,0 @@ -package threatintelligence - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorCreateOperationResponse struct { - HttpResponse *http.Response - Model *ThreatIntelligenceInformation -} - -// IndicatorCreate ... -func (c ThreatIntelligenceClient) IndicatorCreate(ctx context.Context, id IndicatorId, input ThreatIntelligenceIndicatorModelForRequestBody) (result IndicatorCreateOperationResponse, err error) { - req, err := c.preparerForIndicatorCreate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorCreate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorCreate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorCreate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorCreate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorCreate prepares the IndicatorCreate request. -func (c ThreatIntelligenceClient) preparerForIndicatorCreate(ctx context.Context, id IndicatorId, input ThreatIntelligenceIndicatorModelForRequestBody) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorCreate handles the response to the IndicatorCreate request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorCreate(resp *http.Response) (result IndicatorCreateOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatorcreateindicator.go b/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatorcreateindicator.go new file mode 100644 index 00000000000..8cc69065279 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatorcreateindicator.go @@ -0,0 +1,63 @@ +package threatintelligence + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorCreateIndicatorOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ThreatIntelligenceInformation +} + +// IndicatorCreateIndicator ... +func (c ThreatIntelligenceClient) IndicatorCreateIndicator(ctx context.Context, id WorkspaceId, input ThreatIntelligenceIndicatorModelForRequestBody) (result IndicatorCreateIndicatorOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/createIndicator", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatorcreateindicator_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatorcreateindicator_autorest.go deleted file mode 100644 index 40b23fa2317..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatorcreateindicator_autorest.go +++ /dev/null @@ -1,79 +0,0 @@ -package threatintelligence - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorCreateIndicatorOperationResponse struct { - HttpResponse *http.Response - Model *ThreatIntelligenceInformation -} - -// IndicatorCreateIndicator ... -func (c ThreatIntelligenceClient) IndicatorCreateIndicator(ctx context.Context, id WorkspaceId, input ThreatIntelligenceIndicatorModelForRequestBody) (result IndicatorCreateIndicatorOperationResponse, err error) { - req, err := c.preparerForIndicatorCreateIndicator(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorCreateIndicator", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorCreateIndicator", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorCreateIndicator(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorCreateIndicator", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorCreateIndicator prepares the IndicatorCreateIndicator request. -func (c ThreatIntelligenceClient) preparerForIndicatorCreateIndicator(ctx context.Context, id WorkspaceId, input ThreatIntelligenceIndicatorModelForRequestBody) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/createIndicator", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorCreateIndicator handles the response to the IndicatorCreateIndicator request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorCreateIndicator(resp *http.Response) (result IndicatorCreateIndicatorOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatordelete.go b/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatordelete.go new file mode 100644 index 00000000000..4de264524d5 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatordelete.go @@ -0,0 +1,47 @@ +package threatintelligence + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// IndicatorDelete ... +func (c ThreatIntelligenceClient) IndicatorDelete(ctx context.Context, id IndicatorId) (result IndicatorDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatordelete_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatordelete_autorest.go deleted file mode 100644 index 825d3b911ce..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatordelete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package threatintelligence - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorDeleteOperationResponse struct { - HttpResponse *http.Response -} - -// IndicatorDelete ... -func (c ThreatIntelligenceClient) IndicatorDelete(ctx context.Context, id IndicatorId) (result IndicatorDeleteOperationResponse, err error) { - req, err := c.preparerForIndicatorDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorDelete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorDelete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorDelete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorDelete prepares the IndicatorDelete request. -func (c ThreatIntelligenceClient) preparerForIndicatorDelete(ctx context.Context, id IndicatorId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorDelete handles the response to the IndicatorDelete request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorDelete(resp *http.Response) (result IndicatorDeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatorget.go b/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatorget.go new file mode 100644 index 00000000000..3358363f139 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatorget.go @@ -0,0 +1,58 @@ +package threatintelligence + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ThreatIntelligenceInformation +} + +// IndicatorGet ... +func (c ThreatIntelligenceClient) IndicatorGet(ctx context.Context, id IndicatorId) (result IndicatorGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatorget_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatorget_autorest.go deleted file mode 100644 index ac1187fb285..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatorget_autorest.go +++ /dev/null @@ -1,77 +0,0 @@ -package threatintelligence - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorGetOperationResponse struct { - HttpResponse *http.Response - Model *ThreatIntelligenceInformation -} - -// IndicatorGet ... -func (c ThreatIntelligenceClient) IndicatorGet(ctx context.Context, id IndicatorId) (result IndicatorGetOperationResponse, err error) { - req, err := c.preparerForIndicatorGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorGet", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorGet", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorGet", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorGet prepares the IndicatorGet request. -func (c ThreatIntelligenceClient) preparerForIndicatorGet(ctx context.Context, id IndicatorId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorGet handles the response to the IndicatorGet request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorGet(resp *http.Response) (result IndicatorGetOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatormetricslist.go b/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatormetricslist.go new file mode 100644 index 00000000000..688ff3c16d1 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatormetricslist.go @@ -0,0 +1,52 @@ +package threatintelligence + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorMetricsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ThreatIntelligenceMetricsList +} + +// IndicatorMetricsList ... +func (c ThreatIntelligenceClient) IndicatorMetricsList(ctx context.Context, id WorkspaceId) (result IndicatorMetricsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/metrics", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatormetricslist_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatormetricslist_autorest.go deleted file mode 100644 index 1835c26ed96..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatormetricslist_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package threatintelligence - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorMetricsListOperationResponse struct { - HttpResponse *http.Response - Model *ThreatIntelligenceMetricsList -} - -// IndicatorMetricsList ... -func (c ThreatIntelligenceClient) IndicatorMetricsList(ctx context.Context, id WorkspaceId) (result IndicatorMetricsListOperationResponse, err error) { - req, err := c.preparerForIndicatorMetricsList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorMetricsList", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorMetricsList", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorMetricsList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorMetricsList", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorMetricsList prepares the IndicatorMetricsList request. -func (c ThreatIntelligenceClient) preparerForIndicatorMetricsList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/metrics", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorMetricsList handles the response to the IndicatorMetricsList request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorMetricsList(resp *http.Response) (result IndicatorMetricsListOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatorqueryindicators.go b/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatorqueryindicators.go new file mode 100644 index 00000000000..8ce639f2623 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatorqueryindicators.go @@ -0,0 +1,103 @@ +package threatintelligence + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorQueryIndicatorsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ThreatIntelligenceInformation +} + +type IndicatorQueryIndicatorsCompleteResult struct { + LatestHttpResponse *http.Response + Items []ThreatIntelligenceInformation +} + +// IndicatorQueryIndicators ... +func (c ThreatIntelligenceClient) IndicatorQueryIndicators(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria) (result IndicatorQueryIndicatorsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/queryIndicators", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]ThreatIntelligenceInformation, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalThreatIntelligenceInformationImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for ThreatIntelligenceInformation (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// IndicatorQueryIndicatorsComplete retrieves all the results into a single object +func (c ThreatIntelligenceClient) IndicatorQueryIndicatorsComplete(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria) (IndicatorQueryIndicatorsCompleteResult, error) { + return c.IndicatorQueryIndicatorsCompleteMatchingPredicate(ctx, id, input, ThreatIntelligenceInformationOperationPredicate{}) +} + +// IndicatorQueryIndicatorsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ThreatIntelligenceClient) IndicatorQueryIndicatorsCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria, predicate ThreatIntelligenceInformationOperationPredicate) (result IndicatorQueryIndicatorsCompleteResult, err error) { + items := make([]ThreatIntelligenceInformation, 0) + + resp, err := c.IndicatorQueryIndicators(ctx, id, input) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = IndicatorQueryIndicatorsCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatorqueryindicators_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatorqueryindicators_autorest.go deleted file mode 100644 index fcbe7c74758..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatorqueryindicators_autorest.go +++ /dev/null @@ -1,197 +0,0 @@ -package threatintelligence - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorQueryIndicatorsOperationResponse struct { - HttpResponse *http.Response - Model *[]ThreatIntelligenceInformation - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (IndicatorQueryIndicatorsOperationResponse, error) -} - -type IndicatorQueryIndicatorsCompleteResult struct { - Items []ThreatIntelligenceInformation -} - -func (r IndicatorQueryIndicatorsOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r IndicatorQueryIndicatorsOperationResponse) LoadMore(ctx context.Context) (resp IndicatorQueryIndicatorsOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// IndicatorQueryIndicators ... -func (c ThreatIntelligenceClient) IndicatorQueryIndicators(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria) (resp IndicatorQueryIndicatorsOperationResponse, err error) { - req, err := c.preparerForIndicatorQueryIndicators(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorQueryIndicators", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorQueryIndicators", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForIndicatorQueryIndicators(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorQueryIndicators", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForIndicatorQueryIndicators prepares the IndicatorQueryIndicators request. -func (c ThreatIntelligenceClient) preparerForIndicatorQueryIndicators(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/queryIndicators", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForIndicatorQueryIndicatorsWithNextLink prepares the IndicatorQueryIndicators request with the given nextLink token. -func (c ThreatIntelligenceClient) preparerForIndicatorQueryIndicatorsWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorQueryIndicators handles the response to the IndicatorQueryIndicators request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorQueryIndicators(resp *http.Response) (result IndicatorQueryIndicatorsOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]ThreatIntelligenceInformation, 0) - for i, v := range respObj.Values { - val, err := unmarshalThreatIntelligenceInformationImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for ThreatIntelligenceInformation (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result IndicatorQueryIndicatorsOperationResponse, err error) { - req, err := c.preparerForIndicatorQueryIndicatorsWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorQueryIndicators", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorQueryIndicators", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorQueryIndicators(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorQueryIndicators", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// IndicatorQueryIndicatorsComplete retrieves all of the results into a single object -func (c ThreatIntelligenceClient) IndicatorQueryIndicatorsComplete(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria) (IndicatorQueryIndicatorsCompleteResult, error) { - return c.IndicatorQueryIndicatorsCompleteMatchingPredicate(ctx, id, input, ThreatIntelligenceInformationOperationPredicate{}) -} - -// IndicatorQueryIndicatorsCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c ThreatIntelligenceClient) IndicatorQueryIndicatorsCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria, predicate ThreatIntelligenceInformationOperationPredicate) (resp IndicatorQueryIndicatorsCompleteResult, err error) { - items := make([]ThreatIntelligenceInformation, 0) - - page, err := c.IndicatorQueryIndicators(ctx, id, input) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := IndicatorQueryIndicatorsCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatorreplacetags.go b/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatorreplacetags.go new file mode 100644 index 00000000000..20da1141fcd --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatorreplacetags.go @@ -0,0 +1,63 @@ +package threatintelligence + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorReplaceTagsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ThreatIntelligenceInformation +} + +// IndicatorReplaceTags ... +func (c ThreatIntelligenceClient) IndicatorReplaceTags(ctx context.Context, id IndicatorId, input ThreatIntelligenceIndicatorModelForRequestBody) (result IndicatorReplaceTagsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/replaceTags", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatorreplacetags_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatorreplacetags_autorest.go deleted file mode 100644 index 514d0274b0c..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatorreplacetags_autorest.go +++ /dev/null @@ -1,79 +0,0 @@ -package threatintelligence - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorReplaceTagsOperationResponse struct { - HttpResponse *http.Response - Model *ThreatIntelligenceInformation -} - -// IndicatorReplaceTags ... -func (c ThreatIntelligenceClient) IndicatorReplaceTags(ctx context.Context, id IndicatorId, input ThreatIntelligenceIndicatorModelForRequestBody) (result IndicatorReplaceTagsOperationResponse, err error) { - req, err := c.preparerForIndicatorReplaceTags(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorReplaceTags", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorReplaceTags", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorReplaceTags(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorReplaceTags", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorReplaceTags prepares the IndicatorReplaceTags request. -func (c ThreatIntelligenceClient) preparerForIndicatorReplaceTags(ctx context.Context, id IndicatorId, input ThreatIntelligenceIndicatorModelForRequestBody) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/replaceTags", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorReplaceTags handles the response to the IndicatorReplaceTags request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorReplaceTags(resp *http.Response) (result IndicatorReplaceTagsOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatorslist.go b/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatorslist.go new file mode 100644 index 00000000000..860ecd26255 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatorslist.go @@ -0,0 +1,139 @@ +package threatintelligence + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ThreatIntelligenceInformation +} + +type IndicatorsListCompleteResult struct { + LatestHttpResponse *http.Response + Items []ThreatIntelligenceInformation +} + +type IndicatorsListOperationOptions struct { + Filter *string + Orderby *string + Top *int64 +} + +func DefaultIndicatorsListOperationOptions() IndicatorsListOperationOptions { + return IndicatorsListOperationOptions{} +} + +func (o IndicatorsListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o IndicatorsListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o IndicatorsListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// IndicatorsList ... +func (c ThreatIntelligenceClient) IndicatorsList(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions) (result IndicatorsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/indicators", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]ThreatIntelligenceInformation, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalThreatIntelligenceInformationImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for ThreatIntelligenceInformation (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// IndicatorsListComplete retrieves all the results into a single object +func (c ThreatIntelligenceClient) IndicatorsListComplete(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions) (IndicatorsListCompleteResult, error) { + return c.IndicatorsListCompleteMatchingPredicate(ctx, id, options, ThreatIntelligenceInformationOperationPredicate{}) +} + +// IndicatorsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ThreatIntelligenceClient) IndicatorsListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions, predicate ThreatIntelligenceInformationOperationPredicate) (result IndicatorsListCompleteResult, err error) { + items := make([]ThreatIntelligenceInformation, 0) + + resp, err := c.IndicatorsList(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = IndicatorsListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatorslist_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatorslist_autorest.go deleted file mode 100644 index 22ef9d7b193..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/threatintelligence/method_indicatorslist_autorest.go +++ /dev/null @@ -1,235 +0,0 @@ -package threatintelligence - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorsListOperationResponse struct { - HttpResponse *http.Response - Model *[]ThreatIntelligenceInformation - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (IndicatorsListOperationResponse, error) -} - -type IndicatorsListCompleteResult struct { - Items []ThreatIntelligenceInformation -} - -func (r IndicatorsListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r IndicatorsListOperationResponse) LoadMore(ctx context.Context) (resp IndicatorsListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type IndicatorsListOperationOptions struct { - Filter *string - Orderby *string - Top *int64 -} - -func DefaultIndicatorsListOperationOptions() IndicatorsListOperationOptions { - return IndicatorsListOperationOptions{} -} - -func (o IndicatorsListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o IndicatorsListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Filter != nil { - out["$filter"] = *o.Filter - } - - if o.Orderby != nil { - out["$orderby"] = *o.Orderby - } - - if o.Top != nil { - out["$top"] = *o.Top - } - - return out -} - -// IndicatorsList ... -func (c ThreatIntelligenceClient) IndicatorsList(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions) (resp IndicatorsListOperationResponse, err error) { - req, err := c.preparerForIndicatorsList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForIndicatorsList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForIndicatorsList prepares the IndicatorsList request. -func (c ThreatIntelligenceClient) preparerForIndicatorsList(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/indicators", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForIndicatorsListWithNextLink prepares the IndicatorsList request with the given nextLink token. -func (c ThreatIntelligenceClient) preparerForIndicatorsListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorsList handles the response to the IndicatorsList request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorsList(resp *http.Response) (result IndicatorsListOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]ThreatIntelligenceInformation, 0) - for i, v := range respObj.Values { - val, err := unmarshalThreatIntelligenceInformationImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for ThreatIntelligenceInformation (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result IndicatorsListOperationResponse, err error) { - req, err := c.preparerForIndicatorsListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorsList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// IndicatorsListComplete retrieves all of the results into a single object -func (c ThreatIntelligenceClient) IndicatorsListComplete(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions) (IndicatorsListCompleteResult, error) { - return c.IndicatorsListCompleteMatchingPredicate(ctx, id, options, ThreatIntelligenceInformationOperationPredicate{}) -} - -// IndicatorsListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c ThreatIntelligenceClient) IndicatorsListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions, predicate ThreatIntelligenceInformationOperationPredicate) (resp IndicatorsListCompleteResult, err error) { - items := make([]ThreatIntelligenceInformation, 0) - - page, err := c.IndicatorsList(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := IndicatorsListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/watchlistitems/client.go b/resource-manager/securityinsights/2021-09-01-preview/watchlistitems/client.go index 9403755456e..d3193694a48 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/watchlistitems/client.go +++ b/resource-manager/securityinsights/2021-09-01-preview/watchlistitems/client.go @@ -1,18 +1,26 @@ package watchlistitems -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type WatchlistItemsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewWatchlistItemsClientWithBaseURI(endpoint string) WatchlistItemsClient { - return WatchlistItemsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewWatchlistItemsClientWithBaseURI(sdkApi sdkEnv.Api) (*WatchlistItemsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "watchlistitems", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating WatchlistItemsClient: %+v", err) } + + return &WatchlistItemsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2021-09-01-preview/watchlistitems/method_createorupdate.go b/resource-manager/securityinsights/2021-09-01-preview/watchlistitems/method_createorupdate.go new file mode 100644 index 00000000000..d02782f71bc --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/watchlistitems/method_createorupdate.go @@ -0,0 +1,56 @@ +package watchlistitems + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *WatchlistItem +} + +// CreateOrUpdate ... +func (c WatchlistItemsClient) CreateOrUpdate(ctx context.Context, id WatchlistItemId, input WatchlistItem) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/watchlistitems/method_createorupdate_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/watchlistitems/method_createorupdate_autorest.go deleted file mode 100644 index 15d8fdcc2be..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/watchlistitems/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package watchlistitems - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *WatchlistItem -} - -// CreateOrUpdate ... -func (c WatchlistItemsClient) CreateOrUpdate(ctx context.Context, id WatchlistItemId, input WatchlistItem) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c WatchlistItemsClient) preparerForCreateOrUpdate(ctx context.Context, id WatchlistItemId, input WatchlistItem) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c WatchlistItemsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/watchlistitems/method_delete.go b/resource-manager/securityinsights/2021-09-01-preview/watchlistitems/method_delete.go new file mode 100644 index 00000000000..5565b767fa5 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/watchlistitems/method_delete.go @@ -0,0 +1,47 @@ +package watchlistitems + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c WatchlistItemsClient) Delete(ctx context.Context, id WatchlistItemId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/watchlistitems/method_delete_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/watchlistitems/method_delete_autorest.go deleted file mode 100644 index c9b8c46f9e5..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/watchlistitems/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package watchlistitems - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c WatchlistItemsClient) Delete(ctx context.Context, id WatchlistItemId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c WatchlistItemsClient) preparerForDelete(ctx context.Context, id WatchlistItemId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c WatchlistItemsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/watchlistitems/method_get.go b/resource-manager/securityinsights/2021-09-01-preview/watchlistitems/method_get.go new file mode 100644 index 00000000000..ff9a8e143fa --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/watchlistitems/method_get.go @@ -0,0 +1,51 @@ +package watchlistitems + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *WatchlistItem +} + +// Get ... +func (c WatchlistItemsClient) Get(ctx context.Context, id WatchlistItemId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/watchlistitems/method_get_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/watchlistitems/method_get_autorest.go deleted file mode 100644 index b294f999f64..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/watchlistitems/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package watchlistitems - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *WatchlistItem -} - -// Get ... -func (c WatchlistItemsClient) Get(ctx context.Context, id WatchlistItemId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c WatchlistItemsClient) preparerForGet(ctx context.Context, id WatchlistItemId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c WatchlistItemsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/watchlistitems/method_list.go b/resource-manager/securityinsights/2021-09-01-preview/watchlistitems/method_list.go new file mode 100644 index 00000000000..8a4d418ea0b --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/watchlistitems/method_list.go @@ -0,0 +1,91 @@ +package watchlistitems + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]WatchlistItem +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []WatchlistItem +} + +// List ... +func (c WatchlistItemsClient) List(ctx context.Context, id WatchlistId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/watchlistItems", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]WatchlistItem `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c WatchlistItemsClient) ListComplete(ctx context.Context, id WatchlistId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, WatchlistItemOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c WatchlistItemsClient) ListCompleteMatchingPredicate(ctx context.Context, id WatchlistId, predicate WatchlistItemOperationPredicate) (result ListCompleteResult, err error) { + items := make([]WatchlistItem, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/watchlistitems/method_list_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/watchlistitems/method_list_autorest.go deleted file mode 100644 index d8e4bf85bf1..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/watchlistitems/method_list_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package watchlistitems - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]WatchlistItem - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []WatchlistItem -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c WatchlistItemsClient) List(ctx context.Context, id WatchlistId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c WatchlistItemsClient) preparerForList(ctx context.Context, id WatchlistId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/watchlistItems", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c WatchlistItemsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c WatchlistItemsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []WatchlistItem `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c WatchlistItemsClient) ListComplete(ctx context.Context, id WatchlistId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, WatchlistItemOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c WatchlistItemsClient) ListCompleteMatchingPredicate(ctx context.Context, id WatchlistId, predicate WatchlistItemOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]WatchlistItem, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/watchlists/client.go b/resource-manager/securityinsights/2021-09-01-preview/watchlists/client.go index 61cfa3d0ac3..45211175054 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/watchlists/client.go +++ b/resource-manager/securityinsights/2021-09-01-preview/watchlists/client.go @@ -1,18 +1,26 @@ package watchlists -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type WatchlistsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewWatchlistsClientWithBaseURI(endpoint string) WatchlistsClient { - return WatchlistsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewWatchlistsClientWithBaseURI(sdkApi sdkEnv.Api) (*WatchlistsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "watchlists", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating WatchlistsClient: %+v", err) } + + return &WatchlistsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2021-09-01-preview/watchlists/constants.go b/resource-manager/securityinsights/2021-09-01-preview/watchlists/constants.go index 504c5ecef48..2ec351b8408 100644 --- a/resource-manager/securityinsights/2021-09-01-preview/watchlists/constants.go +++ b/resource-manager/securityinsights/2021-09-01-preview/watchlists/constants.go @@ -1,6 +1,10 @@ package watchlists -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -19,6 +23,19 @@ func PossibleValuesForSource() []string { } } +func (s *Source) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSource(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSource(input string) (*Source, error) { vals := map[string]Source{ "local file": SourceLocalFile, diff --git a/resource-manager/securityinsights/2021-09-01-preview/watchlists/method_createorupdate.go b/resource-manager/securityinsights/2021-09-01-preview/watchlists/method_createorupdate.go new file mode 100644 index 00000000000..cf0dc47e9d7 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/watchlists/method_createorupdate.go @@ -0,0 +1,56 @@ +package watchlists + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Watchlist +} + +// CreateOrUpdate ... +func (c WatchlistsClient) CreateOrUpdate(ctx context.Context, id WatchlistId, input Watchlist) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/watchlists/method_createorupdate_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/watchlists/method_createorupdate_autorest.go deleted file mode 100644 index e6d8a5976b8..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/watchlists/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package watchlists - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *Watchlist -} - -// CreateOrUpdate ... -func (c WatchlistsClient) CreateOrUpdate(ctx context.Context, id WatchlistId, input Watchlist) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c WatchlistsClient) preparerForCreateOrUpdate(ctx context.Context, id WatchlistId, input Watchlist) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c WatchlistsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/watchlists/method_delete.go b/resource-manager/securityinsights/2021-09-01-preview/watchlists/method_delete.go new file mode 100644 index 00000000000..9d495f99c57 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/watchlists/method_delete.go @@ -0,0 +1,47 @@ +package watchlists + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c WatchlistsClient) Delete(ctx context.Context, id WatchlistId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/watchlists/method_delete_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/watchlists/method_delete_autorest.go deleted file mode 100644 index 56234124b82..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/watchlists/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package watchlists - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c WatchlistsClient) Delete(ctx context.Context, id WatchlistId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c WatchlistsClient) preparerForDelete(ctx context.Context, id WatchlistId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c WatchlistsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/watchlists/method_get.go b/resource-manager/securityinsights/2021-09-01-preview/watchlists/method_get.go new file mode 100644 index 00000000000..39ec92feaeb --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/watchlists/method_get.go @@ -0,0 +1,51 @@ +package watchlists + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Watchlist +} + +// Get ... +func (c WatchlistsClient) Get(ctx context.Context, id WatchlistId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/watchlists/method_get_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/watchlists/method_get_autorest.go deleted file mode 100644 index d7253f62215..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/watchlists/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package watchlists - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *Watchlist -} - -// Get ... -func (c WatchlistsClient) Get(ctx context.Context, id WatchlistId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c WatchlistsClient) preparerForGet(ctx context.Context, id WatchlistId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c WatchlistsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2021-09-01-preview/watchlists/method_list.go b/resource-manager/securityinsights/2021-09-01-preview/watchlists/method_list.go new file mode 100644 index 00000000000..9122b014815 --- /dev/null +++ b/resource-manager/securityinsights/2021-09-01-preview/watchlists/method_list.go @@ -0,0 +1,91 @@ +package watchlists + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Watchlist +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Watchlist +} + +// List ... +func (c WatchlistsClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/watchlists", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Watchlist `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c WatchlistsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, WatchlistOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c WatchlistsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate WatchlistOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Watchlist, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2021-09-01-preview/watchlists/method_list_autorest.go b/resource-manager/securityinsights/2021-09-01-preview/watchlists/method_list_autorest.go deleted file mode 100644 index a3a2c27c15e..00000000000 --- a/resource-manager/securityinsights/2021-09-01-preview/watchlists/method_list_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package watchlists - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]Watchlist - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []Watchlist -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c WatchlistsClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c WatchlistsClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/watchlists", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c WatchlistsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c WatchlistsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []Watchlist `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c WatchlistsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, WatchlistOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c WatchlistsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate WatchlistOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]Watchlist, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/actions/client.go b/resource-manager/securityinsights/2022-07-01-preview/actions/client.go index 9a66b55eb82..a2b7d01bfe1 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/actions/client.go +++ b/resource-manager/securityinsights/2022-07-01-preview/actions/client.go @@ -1,18 +1,26 @@ package actions -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type ActionsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewActionsClientWithBaseURI(endpoint string) ActionsClient { - return ActionsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewActionsClientWithBaseURI(sdkApi sdkEnv.Api) (*ActionsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "actions", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ActionsClient: %+v", err) } + + return &ActionsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-07-01-preview/actions/method_createorupdate.go b/resource-manager/securityinsights/2022-07-01-preview/actions/method_createorupdate.go new file mode 100644 index 00000000000..1672bf99a0f --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/actions/method_createorupdate.go @@ -0,0 +1,56 @@ +package actions + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ActionResponse +} + +// CreateOrUpdate ... +func (c ActionsClient) CreateOrUpdate(ctx context.Context, id ActionId, input ActionRequest) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/actions/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/actions/method_createorupdate_autorest.go deleted file mode 100644 index f5145e1a555..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/actions/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package actions - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *ActionResponse -} - -// CreateOrUpdate ... -func (c ActionsClient) CreateOrUpdate(ctx context.Context, id ActionId, input ActionRequest) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c ActionsClient) preparerForCreateOrUpdate(ctx context.Context, id ActionId, input ActionRequest) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c ActionsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/actions/method_delete.go b/resource-manager/securityinsights/2022-07-01-preview/actions/method_delete.go new file mode 100644 index 00000000000..0f8a28307c2 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/actions/method_delete.go @@ -0,0 +1,47 @@ +package actions + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c ActionsClient) Delete(ctx context.Context, id ActionId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/actions/method_delete_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/actions/method_delete_autorest.go deleted file mode 100644 index d142f9f3054..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/actions/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package actions - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c ActionsClient) Delete(ctx context.Context, id ActionId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c ActionsClient) preparerForDelete(ctx context.Context, id ActionId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c ActionsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/actions/method_get.go b/resource-manager/securityinsights/2022-07-01-preview/actions/method_get.go new file mode 100644 index 00000000000..76d3593e1f1 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/actions/method_get.go @@ -0,0 +1,51 @@ +package actions + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ActionResponse +} + +// Get ... +func (c ActionsClient) Get(ctx context.Context, id ActionId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/actions/method_get_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/actions/method_get_autorest.go deleted file mode 100644 index aa1388a0c31..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/actions/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package actions - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *ActionResponse -} - -// Get ... -func (c ActionsClient) Get(ctx context.Context, id ActionId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c ActionsClient) preparerForGet(ctx context.Context, id ActionId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c ActionsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/actions/method_listbyalertrule.go b/resource-manager/securityinsights/2022-07-01-preview/actions/method_listbyalertrule.go new file mode 100644 index 00000000000..09d32b9d82d --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/actions/method_listbyalertrule.go @@ -0,0 +1,91 @@ +package actions + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByAlertRuleOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ActionResponse +} + +type ListByAlertRuleCompleteResult struct { + LatestHttpResponse *http.Response + Items []ActionResponse +} + +// ListByAlertRule ... +func (c ActionsClient) ListByAlertRule(ctx context.Context, id AlertRuleId) (result ListByAlertRuleOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/actions", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ActionResponse `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByAlertRuleComplete retrieves all the results into a single object +func (c ActionsClient) ListByAlertRuleComplete(ctx context.Context, id AlertRuleId) (ListByAlertRuleCompleteResult, error) { + return c.ListByAlertRuleCompleteMatchingPredicate(ctx, id, ActionResponseOperationPredicate{}) +} + +// ListByAlertRuleCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ActionsClient) ListByAlertRuleCompleteMatchingPredicate(ctx context.Context, id AlertRuleId, predicate ActionResponseOperationPredicate) (result ListByAlertRuleCompleteResult, err error) { + items := make([]ActionResponse, 0) + + resp, err := c.ListByAlertRule(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByAlertRuleCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/actions/method_listbyalertrule_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/actions/method_listbyalertrule_autorest.go deleted file mode 100644 index a58a9738f1f..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/actions/method_listbyalertrule_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package actions - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListByAlertRuleOperationResponse struct { - HttpResponse *http.Response - Model *[]ActionResponse - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListByAlertRuleOperationResponse, error) -} - -type ListByAlertRuleCompleteResult struct { - Items []ActionResponse -} - -func (r ListByAlertRuleOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListByAlertRuleOperationResponse) LoadMore(ctx context.Context) (resp ListByAlertRuleOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// ListByAlertRule ... -func (c ActionsClient) ListByAlertRule(ctx context.Context, id AlertRuleId) (resp ListByAlertRuleOperationResponse, err error) { - req, err := c.preparerForListByAlertRule(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "ListByAlertRule", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "ListByAlertRule", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForListByAlertRule(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "ListByAlertRule", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForListByAlertRule prepares the ListByAlertRule request. -func (c ActionsClient) preparerForListByAlertRule(ctx context.Context, id AlertRuleId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/actions", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListByAlertRuleWithNextLink prepares the ListByAlertRule request with the given nextLink token. -func (c ActionsClient) preparerForListByAlertRuleWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForListByAlertRule handles the response to the ListByAlertRule request. The method always -// closes the http.Response Body. -func (c ActionsClient) responderForListByAlertRule(resp *http.Response) (result ListByAlertRuleOperationResponse, err error) { - type page struct { - Values []ActionResponse `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByAlertRuleOperationResponse, err error) { - req, err := c.preparerForListByAlertRuleWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "ListByAlertRule", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "ListByAlertRule", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForListByAlertRule(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "ListByAlertRule", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListByAlertRuleComplete retrieves all of the results into a single object -func (c ActionsClient) ListByAlertRuleComplete(ctx context.Context, id AlertRuleId) (ListByAlertRuleCompleteResult, error) { - return c.ListByAlertRuleCompleteMatchingPredicate(ctx, id, ActionResponseOperationPredicate{}) -} - -// ListByAlertRuleCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c ActionsClient) ListByAlertRuleCompleteMatchingPredicate(ctx context.Context, id AlertRuleId, predicate ActionResponseOperationPredicate) (resp ListByAlertRuleCompleteResult, err error) { - items := make([]ActionResponse, 0) - - page, err := c.ListByAlertRule(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListByAlertRuleCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/alertrules/client.go b/resource-manager/securityinsights/2022-07-01-preview/alertrules/client.go index 6e34bca2ce3..e6ca04af9da 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/alertrules/client.go +++ b/resource-manager/securityinsights/2022-07-01-preview/alertrules/client.go @@ -1,18 +1,26 @@ package alertrules -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type AlertRulesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewAlertRulesClientWithBaseURI(endpoint string) AlertRulesClient { - return AlertRulesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewAlertRulesClientWithBaseURI(sdkApi sdkEnv.Api) (*AlertRulesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "alertrules", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AlertRulesClient: %+v", err) } + + return &AlertRulesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-07-01-preview/alertrules/constants.go b/resource-manager/securityinsights/2022-07-01-preview/alertrules/constants.go index f6c889d1b38..b6058aaf656 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/alertrules/constants.go +++ b/resource-manager/securityinsights/2022-07-01-preview/alertrules/constants.go @@ -1,6 +1,10 @@ package alertrules -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -19,6 +23,19 @@ func PossibleValuesForAlertDetail() []string { } } +func (s *AlertDetail) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertDetail(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertDetail(input string) (*AlertDetail, error) { vals := map[string]AlertDetail{ "displayname": AlertDetailDisplayName, @@ -55,6 +72,19 @@ func PossibleValuesForAlertRuleKind() []string { } } +func (s *AlertRuleKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertRuleKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertRuleKind(input string) (*AlertRuleKind, error) { vals := map[string]AlertRuleKind{ "fusion": AlertRuleKindFusion, @@ -91,6 +121,19 @@ func PossibleValuesForAlertSeverity() []string { } } +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertSeverity(input string) (*AlertSeverity, error) { vals := map[string]AlertSeverity{ "high": AlertSeverityHigh, @@ -151,6 +194,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -226,6 +282,19 @@ func PossibleValuesForEntityMappingType() []string { } } +func (s *EntityMappingType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityMappingType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityMappingType(input string) (*EntityMappingType, error) { vals := map[string]EntityMappingType{ "account": EntityMappingTypeAccount, @@ -270,6 +339,19 @@ func PossibleValuesForEventGroupingAggregationKind() []string { } } +func (s *EventGroupingAggregationKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEventGroupingAggregationKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEventGroupingAggregationKind(input string) (*EventGroupingAggregationKind, error) { vals := map[string]EventGroupingAggregationKind{ "alertperresult": EventGroupingAggregationKindAlertPerResult, @@ -300,6 +382,19 @@ func PossibleValuesForMatchingMethod() []string { } } +func (s *MatchingMethod) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMatchingMethod(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseMatchingMethod(input string) (*MatchingMethod, error) { vals := map[string]MatchingMethod{ "allentities": MatchingMethodAllEntities, @@ -339,6 +434,19 @@ func PossibleValuesForMicrosoftSecurityProductName() []string { } } +func (s *MicrosoftSecurityProductName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMicrosoftSecurityProductName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseMicrosoftSecurityProductName(input string) (*MicrosoftSecurityProductName, error) { vals := map[string]MicrosoftSecurityProductName{ "azure active directory identity protection": MicrosoftSecurityProductNameAzureActiveDirectoryIdentityProtection, @@ -376,6 +484,19 @@ func PossibleValuesForTriggerOperator() []string { } } +func (s *TriggerOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTriggerOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseTriggerOperator(input string) (*TriggerOperator, error) { vals := map[string]TriggerOperator{ "equal": TriggerOperatorEqual, diff --git a/resource-manager/securityinsights/2022-07-01-preview/alertrules/method_createorupdate.go b/resource-manager/securityinsights/2022-07-01-preview/alertrules/method_createorupdate.go new file mode 100644 index 00000000000..f77c7558d09 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/alertrules/method_createorupdate.go @@ -0,0 +1,63 @@ +package alertrules + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AlertRule +} + +// CreateOrUpdate ... +func (c AlertRulesClient) CreateOrUpdate(ctx context.Context, id AlertRuleId, input AlertRule) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalAlertRuleImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/alertrules/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/alertrules/method_createorupdate_autorest.go deleted file mode 100644 index 548f6c4ef37..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/alertrules/method_createorupdate_autorest.go +++ /dev/null @@ -1,78 +0,0 @@ -package alertrules - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *AlertRule -} - -// CreateOrUpdate ... -func (c AlertRulesClient) CreateOrUpdate(ctx context.Context, id AlertRuleId, input AlertRule) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c AlertRulesClient) preparerForCreateOrUpdate(ctx context.Context, id AlertRuleId, input AlertRule) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c AlertRulesClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalAlertRuleImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/alertrules/method_delete.go b/resource-manager/securityinsights/2022-07-01-preview/alertrules/method_delete.go new file mode 100644 index 00000000000..aae7085c25e --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/alertrules/method_delete.go @@ -0,0 +1,47 @@ +package alertrules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c AlertRulesClient) Delete(ctx context.Context, id AlertRuleId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/alertrules/method_delete_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/alertrules/method_delete_autorest.go deleted file mode 100644 index 417e1a0017e..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/alertrules/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package alertrules - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c AlertRulesClient) Delete(ctx context.Context, id AlertRuleId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c AlertRulesClient) preparerForDelete(ctx context.Context, id AlertRuleId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c AlertRulesClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/alertrules/method_get.go b/resource-manager/securityinsights/2022-07-01-preview/alertrules/method_get.go new file mode 100644 index 00000000000..945c07bfad1 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/alertrules/method_get.go @@ -0,0 +1,58 @@ +package alertrules + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AlertRule +} + +// Get ... +func (c AlertRulesClient) Get(ctx context.Context, id AlertRuleId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalAlertRuleImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/alertrules/method_get_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/alertrules/method_get_autorest.go deleted file mode 100644 index ddd1836d4de..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/alertrules/method_get_autorest.go +++ /dev/null @@ -1,77 +0,0 @@ -package alertrules - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *AlertRule -} - -// Get ... -func (c AlertRulesClient) Get(ctx context.Context, id AlertRuleId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c AlertRulesClient) preparerForGet(ctx context.Context, id AlertRuleId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c AlertRulesClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalAlertRuleImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/alertrules/method_list.go b/resource-manager/securityinsights/2022-07-01-preview/alertrules/method_list.go new file mode 100644 index 00000000000..5ac99496167 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/alertrules/method_list.go @@ -0,0 +1,103 @@ +package alertrules + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AlertRule +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []AlertRule +} + +// List ... +func (c AlertRulesClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/alertRules", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]AlertRule, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalAlertRuleImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for AlertRule (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// ListComplete retrieves all the results into a single object +func (c AlertRulesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, AlertRuleOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AlertRulesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AlertRuleOperationPredicate) (result ListCompleteResult, err error) { + items := make([]AlertRule, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/alertrules/method_list_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/alertrules/method_list_autorest.go deleted file mode 100644 index f06cf0f6241..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/alertrules/method_list_autorest.go +++ /dev/null @@ -1,196 +0,0 @@ -package alertrules - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]AlertRule - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []AlertRule -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c AlertRulesClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c AlertRulesClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/alertRules", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c AlertRulesClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c AlertRulesClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]AlertRule, 0) - for i, v := range respObj.Values { - val, err := unmarshalAlertRuleImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for AlertRule (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c AlertRulesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, AlertRuleOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c AlertRulesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AlertRuleOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]AlertRule, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/alertruletemplates/client.go b/resource-manager/securityinsights/2022-07-01-preview/alertruletemplates/client.go index c439e5a41c7..2932bf14a55 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/alertruletemplates/client.go +++ b/resource-manager/securityinsights/2022-07-01-preview/alertruletemplates/client.go @@ -1,18 +1,26 @@ package alertruletemplates -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type AlertRuleTemplatesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewAlertRuleTemplatesClientWithBaseURI(endpoint string) AlertRuleTemplatesClient { - return AlertRuleTemplatesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewAlertRuleTemplatesClientWithBaseURI(sdkApi sdkEnv.Api) (*AlertRuleTemplatesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "alertruletemplates", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AlertRuleTemplatesClient: %+v", err) } + + return &AlertRuleTemplatesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-07-01-preview/alertruletemplates/constants.go b/resource-manager/securityinsights/2022-07-01-preview/alertruletemplates/constants.go index 3f2ae0e7c35..bd47949dd74 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/alertruletemplates/constants.go +++ b/resource-manager/securityinsights/2022-07-01-preview/alertruletemplates/constants.go @@ -1,6 +1,10 @@ package alertruletemplates -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -27,6 +31,19 @@ func PossibleValuesForAlertRuleKind() []string { } } +func (s *AlertRuleKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertRuleKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertRuleKind(input string) (*AlertRuleKind, error) { vals := map[string]AlertRuleKind{ "fusion": AlertRuleKindFusion, @@ -63,6 +80,19 @@ func PossibleValuesForAlertSeverity() []string { } } +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertSeverity(input string) (*AlertSeverity, error) { vals := map[string]AlertSeverity{ "high": AlertSeverityHigh, @@ -123,6 +153,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -198,6 +241,19 @@ func PossibleValuesForEntityMappingType() []string { } } +func (s *EntityMappingType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityMappingType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityMappingType(input string) (*EntityMappingType, error) { vals := map[string]EntityMappingType{ "account": EntityMappingTypeAccount, @@ -242,6 +298,19 @@ func PossibleValuesForEventGroupingAggregationKind() []string { } } +func (s *EventGroupingAggregationKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEventGroupingAggregationKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEventGroupingAggregationKind(input string) (*EventGroupingAggregationKind, error) { vals := map[string]EventGroupingAggregationKind{ "alertperresult": EventGroupingAggregationKindAlertPerResult, @@ -280,6 +349,19 @@ func PossibleValuesForMicrosoftSecurityProductName() []string { } } +func (s *MicrosoftSecurityProductName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMicrosoftSecurityProductName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseMicrosoftSecurityProductName(input string) (*MicrosoftSecurityProductName, error) { vals := map[string]MicrosoftSecurityProductName{ "azure active directory identity protection": MicrosoftSecurityProductNameAzureActiveDirectoryIdentityProtection, @@ -315,6 +397,19 @@ func PossibleValuesForTemplateStatus() []string { } } +func (s *TemplateStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTemplateStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseTemplateStatus(input string) (*TemplateStatus, error) { vals := map[string]TemplateStatus{ "available": TemplateStatusAvailable, @@ -348,6 +443,19 @@ func PossibleValuesForTriggerOperator() []string { } } +func (s *TriggerOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTriggerOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseTriggerOperator(input string) (*TriggerOperator, error) { vals := map[string]TriggerOperator{ "equal": TriggerOperatorEqual, diff --git a/resource-manager/securityinsights/2022-07-01-preview/alertruletemplates/method_get.go b/resource-manager/securityinsights/2022-07-01-preview/alertruletemplates/method_get.go new file mode 100644 index 00000000000..861712be66a --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/alertruletemplates/method_get.go @@ -0,0 +1,58 @@ +package alertruletemplates + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AlertRuleTemplate +} + +// Get ... +func (c AlertRuleTemplatesClient) Get(ctx context.Context, id AlertRuleTemplateId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalAlertRuleTemplateImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/alertruletemplates/method_get_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/alertruletemplates/method_get_autorest.go deleted file mode 100644 index ad4e0487d83..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/alertruletemplates/method_get_autorest.go +++ /dev/null @@ -1,77 +0,0 @@ -package alertruletemplates - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *AlertRuleTemplate -} - -// Get ... -func (c AlertRuleTemplatesClient) Get(ctx context.Context, id AlertRuleTemplateId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c AlertRuleTemplatesClient) preparerForGet(ctx context.Context, id AlertRuleTemplateId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c AlertRuleTemplatesClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalAlertRuleTemplateImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/alertruletemplates/method_list.go b/resource-manager/securityinsights/2022-07-01-preview/alertruletemplates/method_list.go new file mode 100644 index 00000000000..21f9ceec3de --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/alertruletemplates/method_list.go @@ -0,0 +1,103 @@ +package alertruletemplates + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AlertRuleTemplate +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []AlertRuleTemplate +} + +// List ... +func (c AlertRuleTemplatesClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/alertRuleTemplates", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]AlertRuleTemplate, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalAlertRuleTemplateImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for AlertRuleTemplate (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// ListComplete retrieves all the results into a single object +func (c AlertRuleTemplatesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, AlertRuleTemplateOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AlertRuleTemplatesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AlertRuleTemplateOperationPredicate) (result ListCompleteResult, err error) { + items := make([]AlertRuleTemplate, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/alertruletemplates/method_list_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/alertruletemplates/method_list_autorest.go deleted file mode 100644 index 56794382966..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/alertruletemplates/method_list_autorest.go +++ /dev/null @@ -1,196 +0,0 @@ -package alertruletemplates - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]AlertRuleTemplate - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []AlertRuleTemplate -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c AlertRuleTemplatesClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c AlertRuleTemplatesClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/alertRuleTemplates", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c AlertRuleTemplatesClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c AlertRuleTemplatesClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]AlertRuleTemplate, 0) - for i, v := range respObj.Values { - val, err := unmarshalAlertRuleTemplateImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for AlertRuleTemplate (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c AlertRuleTemplatesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, AlertRuleTemplateOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c AlertRuleTemplatesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AlertRuleTemplateOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]AlertRuleTemplate, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/automationrules/client.go b/resource-manager/securityinsights/2022-07-01-preview/automationrules/client.go index 960f049c387..18fafea1496 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/automationrules/client.go +++ b/resource-manager/securityinsights/2022-07-01-preview/automationrules/client.go @@ -1,18 +1,26 @@ package automationrules -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type AutomationRulesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewAutomationRulesClientWithBaseURI(endpoint string) AutomationRulesClient { - return AutomationRulesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewAutomationRulesClientWithBaseURI(sdkApi sdkEnv.Api) (*AutomationRulesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "automationrules", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AutomationRulesClient: %+v", err) } + + return &AutomationRulesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-07-01-preview/automationrules/constants.go b/resource-manager/securityinsights/2022-07-01-preview/automationrules/constants.go index 975546514d3..c5f119d44c3 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/automationrules/constants.go +++ b/resource-manager/securityinsights/2022-07-01-preview/automationrules/constants.go @@ -1,6 +1,10 @@ package automationrules -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -19,6 +23,19 @@ func PossibleValuesForActionType() []string { } } +func (s *ActionType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseActionType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseActionType(input string) (*ActionType, error) { vals := map[string]ActionType{ "modifyproperties": ActionTypeModifyProperties, @@ -51,6 +68,19 @@ func PossibleValuesForAutomationRulePropertyArrayChangedConditionSupportedArrayT } } +func (s *AutomationRulePropertyArrayChangedConditionSupportedArrayType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRulePropertyArrayChangedConditionSupportedArrayType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAutomationRulePropertyArrayChangedConditionSupportedArrayType(input string) (*AutomationRulePropertyArrayChangedConditionSupportedArrayType, error) { vals := map[string]AutomationRulePropertyArrayChangedConditionSupportedArrayType{ "alerts": AutomationRulePropertyArrayChangedConditionSupportedArrayTypeAlerts, @@ -79,6 +109,19 @@ func PossibleValuesForAutomationRulePropertyArrayChangedConditionSupportedChange } } +func (s *AutomationRulePropertyArrayChangedConditionSupportedChangeType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRulePropertyArrayChangedConditionSupportedChangeType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAutomationRulePropertyArrayChangedConditionSupportedChangeType(input string) (*AutomationRulePropertyArrayChangedConditionSupportedChangeType, error) { vals := map[string]AutomationRulePropertyArrayChangedConditionSupportedChangeType{ "added": AutomationRulePropertyArrayChangedConditionSupportedChangeTypeAdded, @@ -106,6 +149,19 @@ func PossibleValuesForAutomationRulePropertyChangedConditionSupportedChangedType } } +func (s *AutomationRulePropertyChangedConditionSupportedChangedType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRulePropertyChangedConditionSupportedChangedType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAutomationRulePropertyChangedConditionSupportedChangedType(input string) (*AutomationRulePropertyChangedConditionSupportedChangedType, error) { vals := map[string]AutomationRulePropertyChangedConditionSupportedChangedType{ "changedfrom": AutomationRulePropertyChangedConditionSupportedChangedTypeChangedFrom, @@ -136,6 +192,19 @@ func PossibleValuesForAutomationRulePropertyChangedConditionSupportedPropertyTyp } } +func (s *AutomationRulePropertyChangedConditionSupportedPropertyType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRulePropertyChangedConditionSupportedPropertyType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAutomationRulePropertyChangedConditionSupportedPropertyType(input string) (*AutomationRulePropertyChangedConditionSupportedPropertyType, error) { vals := map[string]AutomationRulePropertyChangedConditionSupportedPropertyType{ "incidentowner": AutomationRulePropertyChangedConditionSupportedPropertyTypeIncidentOwner, @@ -177,6 +246,19 @@ func PossibleValuesForAutomationRulePropertyConditionSupportedOperator() []strin } } +func (s *AutomationRulePropertyConditionSupportedOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRulePropertyConditionSupportedOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAutomationRulePropertyConditionSupportedOperator(input string) (*AutomationRulePropertyConditionSupportedOperator, error) { vals := map[string]AutomationRulePropertyConditionSupportedOperator{ "contains": AutomationRulePropertyConditionSupportedOperatorContains, @@ -317,6 +399,19 @@ func PossibleValuesForAutomationRulePropertyConditionSupportedProperty() []strin } } +func (s *AutomationRulePropertyConditionSupportedProperty) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRulePropertyConditionSupportedProperty(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAutomationRulePropertyConditionSupportedProperty(input string) (*AutomationRulePropertyConditionSupportedProperty, error) { vals := map[string]AutomationRulePropertyConditionSupportedProperty{ "accountaadtenantid": AutomationRulePropertyConditionSupportedPropertyAccountAadTenantId, @@ -400,6 +495,19 @@ func PossibleValuesForConditionType() []string { } } +func (s *ConditionType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConditionType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConditionType(input string) (*ConditionType, error) { vals := map[string]ConditionType{ "property": ConditionTypeProperty, @@ -433,6 +541,19 @@ func PossibleValuesForIncidentClassification() []string { } } +func (s *IncidentClassification) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentClassification(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentClassification(input string) (*IncidentClassification, error) { vals := map[string]IncidentClassification{ "benignpositive": IncidentClassificationBenignPositive, @@ -467,6 +588,19 @@ func PossibleValuesForIncidentClassificationReason() []string { } } +func (s *IncidentClassificationReason) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentClassificationReason(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentClassificationReason(input string) (*IncidentClassificationReason, error) { vals := map[string]IncidentClassificationReason{ "inaccuratedata": IncidentClassificationReasonInaccurateData, @@ -497,6 +631,19 @@ func PossibleValuesForIncidentLabelType() []string { } } +func (s *IncidentLabelType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentLabelType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentLabelType(input string) (*IncidentLabelType, error) { vals := map[string]IncidentLabelType{ "autoassigned": IncidentLabelTypeAutoAssigned, @@ -529,6 +676,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, @@ -561,6 +721,19 @@ func PossibleValuesForIncidentStatus() []string { } } +func (s *IncidentStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentStatus(input string) (*IncidentStatus, error) { vals := map[string]IncidentStatus{ "active": IncidentStatusActive, @@ -592,6 +765,19 @@ func PossibleValuesForOwnerType() []string { } } +func (s *OwnerType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOwnerType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseOwnerType(input string) (*OwnerType, error) { vals := map[string]OwnerType{ "group": OwnerTypeGroup, @@ -621,6 +807,19 @@ func PossibleValuesForTriggersOn() []string { } } +func (s *TriggersOn) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTriggersOn(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseTriggersOn(input string) (*TriggersOn, error) { vals := map[string]TriggersOn{ "alerts": TriggersOnAlerts, @@ -649,6 +848,19 @@ func PossibleValuesForTriggersWhen() []string { } } +func (s *TriggersWhen) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTriggersWhen(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseTriggersWhen(input string) (*TriggersWhen, error) { vals := map[string]TriggersWhen{ "created": TriggersWhenCreated, diff --git a/resource-manager/securityinsights/2022-07-01-preview/automationrules/method_createorupdate.go b/resource-manager/securityinsights/2022-07-01-preview/automationrules/method_createorupdate.go new file mode 100644 index 00000000000..c0b3c44f2da --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/automationrules/method_createorupdate.go @@ -0,0 +1,56 @@ +package automationrules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AutomationRule +} + +// CreateOrUpdate ... +func (c AutomationRulesClient) CreateOrUpdate(ctx context.Context, id AutomationRuleId, input AutomationRule) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/automationrules/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/automationrules/method_createorupdate_autorest.go deleted file mode 100644 index 790f2ff99f9..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/automationrules/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package automationrules - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *AutomationRule -} - -// CreateOrUpdate ... -func (c AutomationRulesClient) CreateOrUpdate(ctx context.Context, id AutomationRuleId, input AutomationRule) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c AutomationRulesClient) preparerForCreateOrUpdate(ctx context.Context, id AutomationRuleId, input AutomationRule) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c AutomationRulesClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/automationrules/method_delete.go b/resource-manager/securityinsights/2022-07-01-preview/automationrules/method_delete.go new file mode 100644 index 00000000000..682e97ed619 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/automationrules/method_delete.go @@ -0,0 +1,52 @@ +package automationrules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *interface{} +} + +// Delete ... +func (c AutomationRulesClient) Delete(ctx context.Context, id AutomationRuleId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/automationrules/method_delete_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/automationrules/method_delete_autorest.go deleted file mode 100644 index cd33f79070e..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/automationrules/method_delete_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package automationrules - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response - Model *interface{} -} - -// Delete ... -func (c AutomationRulesClient) Delete(ctx context.Context, id AutomationRuleId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c AutomationRulesClient) preparerForDelete(ctx context.Context, id AutomationRuleId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c AutomationRulesClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/automationrules/method_get.go b/resource-manager/securityinsights/2022-07-01-preview/automationrules/method_get.go new file mode 100644 index 00000000000..0676dc80f40 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/automationrules/method_get.go @@ -0,0 +1,51 @@ +package automationrules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AutomationRule +} + +// Get ... +func (c AutomationRulesClient) Get(ctx context.Context, id AutomationRuleId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/automationrules/method_get_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/automationrules/method_get_autorest.go deleted file mode 100644 index 20f385aa8d7..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/automationrules/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package automationrules - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *AutomationRule -} - -// Get ... -func (c AutomationRulesClient) Get(ctx context.Context, id AutomationRuleId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c AutomationRulesClient) preparerForGet(ctx context.Context, id AutomationRuleId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c AutomationRulesClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/automationrules/method_list.go b/resource-manager/securityinsights/2022-07-01-preview/automationrules/method_list.go new file mode 100644 index 00000000000..a3c7db4995a --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/automationrules/method_list.go @@ -0,0 +1,91 @@ +package automationrules + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AutomationRule +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []AutomationRule +} + +// List ... +func (c AutomationRulesClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/automationRules", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]AutomationRule `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c AutomationRulesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, AutomationRuleOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AutomationRulesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AutomationRuleOperationPredicate) (result ListCompleteResult, err error) { + items := make([]AutomationRule, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/automationrules/method_list_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/automationrules/method_list_autorest.go deleted file mode 100644 index e2818088fcf..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/automationrules/method_list_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package automationrules - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]AutomationRule - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []AutomationRule -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c AutomationRulesClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c AutomationRulesClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/automationRules", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c AutomationRulesClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c AutomationRulesClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []AutomationRule `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c AutomationRulesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, AutomationRuleOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c AutomationRulesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AutomationRuleOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]AutomationRule, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/bookmark/client.go b/resource-manager/securityinsights/2022-07-01-preview/bookmark/client.go index 0bd7283b391..f20b4939301 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/bookmark/client.go +++ b/resource-manager/securityinsights/2022-07-01-preview/bookmark/client.go @@ -1,18 +1,26 @@ package bookmark -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type BookmarkClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewBookmarkClientWithBaseURI(endpoint string) BookmarkClient { - return BookmarkClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewBookmarkClientWithBaseURI(sdkApi sdkEnv.Api) (*BookmarkClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "bookmark", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating BookmarkClient: %+v", err) } + + return &BookmarkClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-07-01-preview/bookmark/constants.go b/resource-manager/securityinsights/2022-07-01-preview/bookmark/constants.go index 017a99af542..95e462c1392 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/bookmark/constants.go +++ b/resource-manager/securityinsights/2022-07-01-preview/bookmark/constants.go @@ -1,6 +1,10 @@ package bookmark -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -59,6 +63,19 @@ func PossibleValuesForEntityKind() []string { } } +func (s *EntityKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityKind(input string) (*EntityKind, error) { vals := map[string]EntityKind{ "account": EntityKindAccount, diff --git a/resource-manager/securityinsights/2022-07-01-preview/bookmark/method_expand.go b/resource-manager/securityinsights/2022-07-01-preview/bookmark/method_expand.go new file mode 100644 index 00000000000..5d8ee564063 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/bookmark/method_expand.go @@ -0,0 +1,56 @@ +package bookmark + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExpandOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *BookmarkExpandResponse +} + +// Expand ... +func (c BookmarkClient) Expand(ctx context.Context, id BookmarkId, input BookmarkExpandParameters) (result ExpandOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/expand", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/bookmark/method_expand_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/bookmark/method_expand_autorest.go deleted file mode 100644 index c01b051eade..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/bookmark/method_expand_autorest.go +++ /dev/null @@ -1,70 +0,0 @@ -package bookmark - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ExpandOperationResponse struct { - HttpResponse *http.Response - Model *BookmarkExpandResponse -} - -// Expand ... -func (c BookmarkClient) Expand(ctx context.Context, id BookmarkId, input BookmarkExpandParameters) (result ExpandOperationResponse, err error) { - req, err := c.preparerForExpand(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmark.BookmarkClient", "Expand", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmark.BookmarkClient", "Expand", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForExpand(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmark.BookmarkClient", "Expand", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForExpand prepares the Expand request. -func (c BookmarkClient) preparerForExpand(ctx context.Context, id BookmarkId, input BookmarkExpandParameters) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/expand", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForExpand handles the response to the Expand request. The method always -// closes the http.Response Body. -func (c BookmarkClient) responderForExpand(resp *http.Response) (result ExpandOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/bookmarkrelations/client.go b/resource-manager/securityinsights/2022-07-01-preview/bookmarkrelations/client.go index c16a1534a9c..7b2f113e83b 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/bookmarkrelations/client.go +++ b/resource-manager/securityinsights/2022-07-01-preview/bookmarkrelations/client.go @@ -1,18 +1,26 @@ package bookmarkrelations -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type BookmarkRelationsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewBookmarkRelationsClientWithBaseURI(endpoint string) BookmarkRelationsClient { - return BookmarkRelationsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewBookmarkRelationsClientWithBaseURI(sdkApi sdkEnv.Api) (*BookmarkRelationsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "bookmarkrelations", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating BookmarkRelationsClient: %+v", err) } + + return &BookmarkRelationsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-07-01-preview/bookmarkrelations/method_createorupdate.go b/resource-manager/securityinsights/2022-07-01-preview/bookmarkrelations/method_createorupdate.go new file mode 100644 index 00000000000..c62743243a5 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/bookmarkrelations/method_createorupdate.go @@ -0,0 +1,56 @@ +package bookmarkrelations + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Relation +} + +// CreateOrUpdate ... +func (c BookmarkRelationsClient) CreateOrUpdate(ctx context.Context, id BookmarkRelationId, input Relation) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/bookmarkrelations/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/bookmarkrelations/method_createorupdate_autorest.go deleted file mode 100644 index 31cbda7e37e..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/bookmarkrelations/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package bookmarkrelations - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *Relation -} - -// CreateOrUpdate ... -func (c BookmarkRelationsClient) CreateOrUpdate(ctx context.Context, id BookmarkRelationId, input Relation) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarkrelations.BookmarkRelationsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarkrelations.BookmarkRelationsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarkrelations.BookmarkRelationsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c BookmarkRelationsClient) preparerForCreateOrUpdate(ctx context.Context, id BookmarkRelationId, input Relation) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c BookmarkRelationsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/bookmarkrelations/method_delete.go b/resource-manager/securityinsights/2022-07-01-preview/bookmarkrelations/method_delete.go new file mode 100644 index 00000000000..be83fdfe96b --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/bookmarkrelations/method_delete.go @@ -0,0 +1,47 @@ +package bookmarkrelations + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c BookmarkRelationsClient) Delete(ctx context.Context, id BookmarkRelationId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/bookmarkrelations/method_delete_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/bookmarkrelations/method_delete_autorest.go deleted file mode 100644 index b94d5add215..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/bookmarkrelations/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package bookmarkrelations - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c BookmarkRelationsClient) Delete(ctx context.Context, id BookmarkRelationId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarkrelations.BookmarkRelationsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarkrelations.BookmarkRelationsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarkrelations.BookmarkRelationsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c BookmarkRelationsClient) preparerForDelete(ctx context.Context, id BookmarkRelationId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c BookmarkRelationsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/bookmarkrelations/method_get.go b/resource-manager/securityinsights/2022-07-01-preview/bookmarkrelations/method_get.go new file mode 100644 index 00000000000..a689e84623f --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/bookmarkrelations/method_get.go @@ -0,0 +1,51 @@ +package bookmarkrelations + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Relation +} + +// Get ... +func (c BookmarkRelationsClient) Get(ctx context.Context, id BookmarkRelationId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/bookmarkrelations/method_get_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/bookmarkrelations/method_get_autorest.go deleted file mode 100644 index 68c15700cd0..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/bookmarkrelations/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package bookmarkrelations - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *Relation -} - -// Get ... -func (c BookmarkRelationsClient) Get(ctx context.Context, id BookmarkRelationId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarkrelations.BookmarkRelationsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarkrelations.BookmarkRelationsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarkrelations.BookmarkRelationsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c BookmarkRelationsClient) preparerForGet(ctx context.Context, id BookmarkRelationId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c BookmarkRelationsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/bookmarkrelations/method_list.go b/resource-manager/securityinsights/2022-07-01-preview/bookmarkrelations/method_list.go new file mode 100644 index 00000000000..c7b0e80ee33 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/bookmarkrelations/method_list.go @@ -0,0 +1,127 @@ +package bookmarkrelations + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Relation +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Relation +} + +type ListOperationOptions struct { + Filter *string + Orderby *string + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c BookmarkRelationsClient) List(ctx context.Context, id BookmarkId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/relations", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Relation `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c BookmarkRelationsClient) ListComplete(ctx context.Context, id BookmarkId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, RelationOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c BookmarkRelationsClient) ListCompleteMatchingPredicate(ctx context.Context, id BookmarkId, options ListOperationOptions, predicate RelationOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Relation, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/bookmarkrelations/method_list_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/bookmarkrelations/method_list_autorest.go deleted file mode 100644 index df04eb11905..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/bookmarkrelations/method_list_autorest.go +++ /dev/null @@ -1,225 +0,0 @@ -package bookmarkrelations - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]Relation - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []Relation -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ListOperationOptions struct { - Filter *string - Orderby *string - Top *int64 -} - -func DefaultListOperationOptions() ListOperationOptions { - return ListOperationOptions{} -} - -func (o ListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Filter != nil { - out["$filter"] = *o.Filter - } - - if o.Orderby != nil { - out["$orderby"] = *o.Orderby - } - - if o.Top != nil { - out["$top"] = *o.Top - } - - return out -} - -// List ... -func (c BookmarkRelationsClient) List(ctx context.Context, id BookmarkId, options ListOperationOptions) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarkrelations.BookmarkRelationsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarkrelations.BookmarkRelationsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarkrelations.BookmarkRelationsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c BookmarkRelationsClient) preparerForList(ctx context.Context, id BookmarkId, options ListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/relations", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c BookmarkRelationsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c BookmarkRelationsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []Relation `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarkrelations.BookmarkRelationsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarkrelations.BookmarkRelationsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarkrelations.BookmarkRelationsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c BookmarkRelationsClient) ListComplete(ctx context.Context, id BookmarkId, options ListOperationOptions) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, options, RelationOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c BookmarkRelationsClient) ListCompleteMatchingPredicate(ctx context.Context, id BookmarkId, options ListOperationOptions, predicate RelationOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]Relation, 0) - - page, err := c.List(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/bookmarks/client.go b/resource-manager/securityinsights/2022-07-01-preview/bookmarks/client.go index ee8ca229e2d..22469155649 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/bookmarks/client.go +++ b/resource-manager/securityinsights/2022-07-01-preview/bookmarks/client.go @@ -1,18 +1,26 @@ package bookmarks -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type BookmarksClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewBookmarksClientWithBaseURI(endpoint string) BookmarksClient { - return BookmarksClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewBookmarksClientWithBaseURI(sdkApi sdkEnv.Api) (*BookmarksClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "bookmarks", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating BookmarksClient: %+v", err) } + + return &BookmarksClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-07-01-preview/bookmarks/constants.go b/resource-manager/securityinsights/2022-07-01-preview/bookmarks/constants.go index f8d553d0e55..9ec53ffa34f 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/bookmarks/constants.go +++ b/resource-manager/securityinsights/2022-07-01-preview/bookmarks/constants.go @@ -1,6 +1,10 @@ package bookmarks -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -49,6 +53,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -96,6 +113,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, diff --git a/resource-manager/securityinsights/2022-07-01-preview/bookmarks/method_createorupdate.go b/resource-manager/securityinsights/2022-07-01-preview/bookmarks/method_createorupdate.go new file mode 100644 index 00000000000..72b6987ce5b --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/bookmarks/method_createorupdate.go @@ -0,0 +1,56 @@ +package bookmarks + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Bookmark +} + +// CreateOrUpdate ... +func (c BookmarksClient) CreateOrUpdate(ctx context.Context, id BookmarkId, input Bookmark) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/bookmarks/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/bookmarks/method_createorupdate_autorest.go deleted file mode 100644 index 6bae46884df..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/bookmarks/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package bookmarks - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *Bookmark -} - -// CreateOrUpdate ... -func (c BookmarksClient) CreateOrUpdate(ctx context.Context, id BookmarkId, input Bookmark) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c BookmarksClient) preparerForCreateOrUpdate(ctx context.Context, id BookmarkId, input Bookmark) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c BookmarksClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/bookmarks/method_delete.go b/resource-manager/securityinsights/2022-07-01-preview/bookmarks/method_delete.go new file mode 100644 index 00000000000..75eef715a7c --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/bookmarks/method_delete.go @@ -0,0 +1,47 @@ +package bookmarks + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c BookmarksClient) Delete(ctx context.Context, id BookmarkId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/bookmarks/method_delete_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/bookmarks/method_delete_autorest.go deleted file mode 100644 index aa1033f513c..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/bookmarks/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package bookmarks - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c BookmarksClient) Delete(ctx context.Context, id BookmarkId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c BookmarksClient) preparerForDelete(ctx context.Context, id BookmarkId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c BookmarksClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/bookmarks/method_get.go b/resource-manager/securityinsights/2022-07-01-preview/bookmarks/method_get.go new file mode 100644 index 00000000000..b8db3d1b69f --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/bookmarks/method_get.go @@ -0,0 +1,51 @@ +package bookmarks + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Bookmark +} + +// Get ... +func (c BookmarksClient) Get(ctx context.Context, id BookmarkId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/bookmarks/method_get_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/bookmarks/method_get_autorest.go deleted file mode 100644 index c76a6c0c211..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/bookmarks/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package bookmarks - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *Bookmark -} - -// Get ... -func (c BookmarksClient) Get(ctx context.Context, id BookmarkId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c BookmarksClient) preparerForGet(ctx context.Context, id BookmarkId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c BookmarksClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/bookmarks/method_list.go b/resource-manager/securityinsights/2022-07-01-preview/bookmarks/method_list.go new file mode 100644 index 00000000000..432b04c413a --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/bookmarks/method_list.go @@ -0,0 +1,91 @@ +package bookmarks + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Bookmark +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Bookmark +} + +// List ... +func (c BookmarksClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/bookmarks", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Bookmark `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c BookmarksClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, BookmarkOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c BookmarksClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate BookmarkOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Bookmark, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/bookmarks/method_list_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/bookmarks/method_list_autorest.go deleted file mode 100644 index 7c4a69eacea..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/bookmarks/method_list_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package bookmarks - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]Bookmark - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []Bookmark -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c BookmarksClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c BookmarksClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/bookmarks", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c BookmarksClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c BookmarksClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []Bookmark `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c BookmarksClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, BookmarkOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c BookmarksClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate BookmarkOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]Bookmark, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/checkdataconnectorrequirements/client.go b/resource-manager/securityinsights/2022-07-01-preview/checkdataconnectorrequirements/client.go index 1eef55a1676..c01575bd213 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/checkdataconnectorrequirements/client.go +++ b/resource-manager/securityinsights/2022-07-01-preview/checkdataconnectorrequirements/client.go @@ -1,18 +1,26 @@ package checkdataconnectorrequirements -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type CheckDataConnectorRequirementsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewCheckDataConnectorRequirementsClientWithBaseURI(endpoint string) CheckDataConnectorRequirementsClient { - return CheckDataConnectorRequirementsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewCheckDataConnectorRequirementsClientWithBaseURI(sdkApi sdkEnv.Api) (*CheckDataConnectorRequirementsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "checkdataconnectorrequirements", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating CheckDataConnectorRequirementsClient: %+v", err) } + + return &CheckDataConnectorRequirementsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-07-01-preview/checkdataconnectorrequirements/constants.go b/resource-manager/securityinsights/2022-07-01-preview/checkdataconnectorrequirements/constants.go index 5884c4d9c6a..c2cb4a1623a 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/checkdataconnectorrequirements/constants.go +++ b/resource-manager/securityinsights/2022-07-01-preview/checkdataconnectorrequirements/constants.go @@ -1,6 +1,10 @@ package checkdataconnectorrequirements -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -19,6 +23,19 @@ func PossibleValuesForDataConnectorAuthorizationState() []string { } } +func (s *DataConnectorAuthorizationState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataConnectorAuthorizationState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDataConnectorAuthorizationState(input string) (*DataConnectorAuthorizationState, error) { vals := map[string]DataConnectorAuthorizationState{ "invalid": DataConnectorAuthorizationStateInvalid, @@ -83,6 +100,19 @@ func PossibleValuesForDataConnectorKind() []string { } } +func (s *DataConnectorKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataConnectorKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDataConnectorKind(input string) (*DataConnectorKind, error) { vals := map[string]DataConnectorKind{ "apipolling": DataConnectorKindAPIPolling, @@ -131,6 +161,19 @@ func PossibleValuesForDataConnectorLicenseState() []string { } } +func (s *DataConnectorLicenseState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataConnectorLicenseState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDataConnectorLicenseState(input string) (*DataConnectorLicenseState, error) { vals := map[string]DataConnectorLicenseState{ "invalid": DataConnectorLicenseStateInvalid, diff --git a/resource-manager/securityinsights/2022-07-01-preview/checkdataconnectorrequirements/method_dataconnectorscheckrequirementspost.go b/resource-manager/securityinsights/2022-07-01-preview/checkdataconnectorrequirements/method_dataconnectorscheckrequirementspost.go new file mode 100644 index 00000000000..91c387f6a09 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/checkdataconnectorrequirements/method_dataconnectorscheckrequirementspost.go @@ -0,0 +1,56 @@ +package checkdataconnectorrequirements + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataConnectorsCheckRequirementsPostOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DataConnectorRequirementsState +} + +// DataConnectorsCheckRequirementsPost ... +func (c CheckDataConnectorRequirementsClient) DataConnectorsCheckRequirementsPost(ctx context.Context, id WorkspaceId, input DataConnectorsCheckRequirements) (result DataConnectorsCheckRequirementsPostOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/dataConnectorsCheckRequirements", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/checkdataconnectorrequirements/method_dataconnectorscheckrequirementspost_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/checkdataconnectorrequirements/method_dataconnectorscheckrequirementspost_autorest.go deleted file mode 100644 index 596830a1ab4..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/checkdataconnectorrequirements/method_dataconnectorscheckrequirementspost_autorest.go +++ /dev/null @@ -1,70 +0,0 @@ -package checkdataconnectorrequirements - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DataConnectorsCheckRequirementsPostOperationResponse struct { - HttpResponse *http.Response - Model *DataConnectorRequirementsState -} - -// DataConnectorsCheckRequirementsPost ... -func (c CheckDataConnectorRequirementsClient) DataConnectorsCheckRequirementsPost(ctx context.Context, id WorkspaceId, input DataConnectorsCheckRequirements) (result DataConnectorsCheckRequirementsPostOperationResponse, err error) { - req, err := c.preparerForDataConnectorsCheckRequirementsPost(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "checkdataconnectorrequirements.CheckDataConnectorRequirementsClient", "DataConnectorsCheckRequirementsPost", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "checkdataconnectorrequirements.CheckDataConnectorRequirementsClient", "DataConnectorsCheckRequirementsPost", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDataConnectorsCheckRequirementsPost(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "checkdataconnectorrequirements.CheckDataConnectorRequirementsClient", "DataConnectorsCheckRequirementsPost", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDataConnectorsCheckRequirementsPost prepares the DataConnectorsCheckRequirementsPost request. -func (c CheckDataConnectorRequirementsClient) preparerForDataConnectorsCheckRequirementsPost(ctx context.Context, id WorkspaceId, input DataConnectorsCheckRequirements) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/dataConnectorsCheckRequirements", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDataConnectorsCheckRequirementsPost handles the response to the DataConnectorsCheckRequirementsPost request. The method always -// closes the http.Response Body. -func (c CheckDataConnectorRequirementsClient) responderForDataConnectorsCheckRequirementsPost(resp *http.Response) (result DataConnectorsCheckRequirementsPostOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/client.go b/resource-manager/securityinsights/2022-07-01-preview/client.go index 105128364e4..8474198bcea 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/client.go +++ b/resource-manager/securityinsights/2022-07-01-preview/client.go @@ -4,7 +4,8 @@ package v2022_07_01_preview // Licensed under the MIT License. See NOTICE.txt in the project root for license information. import ( - "github.com/Azure/go-autorest/autorest" + "fmt" + "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-07-01-preview/actions" "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-07-01-preview/alertrules" "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-07-01-preview/alertruletemplates" @@ -39,6 +40,8 @@ import ( "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-07-01-preview/threatintelligence" "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-07-01-preview/watchlistitems" "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-07-01-preview/watchlists" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" ) type Client struct { @@ -78,144 +81,245 @@ type Client struct { Watchlists *watchlists.WatchlistsClient } -func NewClientWithBaseURI(endpoint string, configureAuthFunc func(c *autorest.Client)) Client { - - actionsClient := actions.NewActionsClientWithBaseURI(endpoint) - configureAuthFunc(&actionsClient.Client) - - alertRuleTemplatesClient := alertruletemplates.NewAlertRuleTemplatesClientWithBaseURI(endpoint) - configureAuthFunc(&alertRuleTemplatesClient.Client) +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + actionsClient, err := actions.NewActionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Actions client: %+v", err) + } + configureFunc(actionsClient.Client) - alertRulesClient := alertrules.NewAlertRulesClientWithBaseURI(endpoint) - configureAuthFunc(&alertRulesClient.Client) + alertRuleTemplatesClient, err := alertruletemplates.NewAlertRuleTemplatesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AlertRuleTemplates client: %+v", err) + } + configureFunc(alertRuleTemplatesClient.Client) - automationRulesClient := automationrules.NewAutomationRulesClientWithBaseURI(endpoint) - configureAuthFunc(&automationRulesClient.Client) + alertRulesClient, err := alertrules.NewAlertRulesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AlertRules client: %+v", err) + } + configureFunc(alertRulesClient.Client) - bookmarkClient := bookmark.NewBookmarkClientWithBaseURI(endpoint) - configureAuthFunc(&bookmarkClient.Client) + automationRulesClient, err := automationrules.NewAutomationRulesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AutomationRules client: %+v", err) + } + configureFunc(automationRulesClient.Client) - bookmarkRelationsClient := bookmarkrelations.NewBookmarkRelationsClientWithBaseURI(endpoint) - configureAuthFunc(&bookmarkRelationsClient.Client) + bookmarkClient, err := bookmark.NewBookmarkClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Bookmark client: %+v", err) + } + configureFunc(bookmarkClient.Client) - bookmarksClient := bookmarks.NewBookmarksClientWithBaseURI(endpoint) - configureAuthFunc(&bookmarksClient.Client) + bookmarkRelationsClient, err := bookmarkrelations.NewBookmarkRelationsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building BookmarkRelations client: %+v", err) + } + configureFunc(bookmarkRelationsClient.Client) - checkDataConnectorRequirementsClient := checkdataconnectorrequirements.NewCheckDataConnectorRequirementsClientWithBaseURI(endpoint) - configureAuthFunc(&checkDataConnectorRequirementsClient.Client) + bookmarksClient, err := bookmarks.NewBookmarksClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Bookmarks client: %+v", err) + } + configureFunc(bookmarksClient.Client) - dataConnectorsClient := dataconnectors.NewDataConnectorsClientWithBaseURI(endpoint) - configureAuthFunc(&dataConnectorsClient.Client) + checkDataConnectorRequirementsClient, err := checkdataconnectorrequirements.NewCheckDataConnectorRequirementsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building CheckDataConnectorRequirements client: %+v", err) + } + configureFunc(checkDataConnectorRequirementsClient.Client) - dataConnectorsConnectClient := dataconnectorsconnect.NewDataConnectorsConnectClientWithBaseURI(endpoint) - configureAuthFunc(&dataConnectorsConnectClient.Client) + dataConnectorsClient, err := dataconnectors.NewDataConnectorsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DataConnectors client: %+v", err) + } + configureFunc(dataConnectorsClient.Client) - dataConnectorsDisconnectClient := dataconnectorsdisconnect.NewDataConnectorsDisconnectClientWithBaseURI(endpoint) - configureAuthFunc(&dataConnectorsDisconnectClient.Client) + dataConnectorsConnectClient, err := dataconnectorsconnect.NewDataConnectorsConnectClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DataConnectorsConnect client: %+v", err) + } + configureFunc(dataConnectorsConnectClient.Client) - enrichmentClient := enrichment.NewEnrichmentClientWithBaseURI(endpoint) - configureAuthFunc(&enrichmentClient.Client) + dataConnectorsDisconnectClient, err := dataconnectorsdisconnect.NewDataConnectorsDisconnectClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DataConnectorsDisconnect client: %+v", err) + } + configureFunc(dataConnectorsDisconnectClient.Client) - entitiesClient := entities.NewEntitiesClientWithBaseURI(endpoint) - configureAuthFunc(&entitiesClient.Client) + enrichmentClient, err := enrichment.NewEnrichmentClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Enrichment client: %+v", err) + } + configureFunc(enrichmentClient.Client) - entityQueriesClient := entityqueries.NewEntityQueriesClientWithBaseURI(endpoint) - configureAuthFunc(&entityQueriesClient.Client) + entitiesClient, err := entities.NewEntitiesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Entities client: %+v", err) + } + configureFunc(entitiesClient.Client) - entityRelationsClient := entityrelations.NewEntityRelationsClientWithBaseURI(endpoint) - configureAuthFunc(&entityRelationsClient.Client) + entityQueriesClient, err := entityqueries.NewEntityQueriesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building EntityQueries client: %+v", err) + } + configureFunc(entityQueriesClient.Client) - entityTypesClient := entitytypes.NewEntityTypesClientWithBaseURI(endpoint) - configureAuthFunc(&entityTypesClient.Client) + entityRelationsClient, err := entityrelations.NewEntityRelationsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building EntityRelations client: %+v", err) + } + configureFunc(entityRelationsClient.Client) - incidentAlertsClient := incidentalerts.NewIncidentAlertsClientWithBaseURI(endpoint) - configureAuthFunc(&incidentAlertsClient.Client) + entityTypesClient, err := entitytypes.NewEntityTypesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building EntityTypes client: %+v", err) + } + configureFunc(entityTypesClient.Client) - incidentBookmarksClient := incidentbookmarks.NewIncidentBookmarksClientWithBaseURI(endpoint) - configureAuthFunc(&incidentBookmarksClient.Client) + incidentAlertsClient, err := incidentalerts.NewIncidentAlertsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IncidentAlerts client: %+v", err) + } + configureFunc(incidentAlertsClient.Client) - incidentCommentsClient := incidentcomments.NewIncidentCommentsClientWithBaseURI(endpoint) - configureAuthFunc(&incidentCommentsClient.Client) + incidentBookmarksClient, err := incidentbookmarks.NewIncidentBookmarksClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IncidentBookmarks client: %+v", err) + } + configureFunc(incidentBookmarksClient.Client) - incidentEntitiesClient := incidententities.NewIncidentEntitiesClientWithBaseURI(endpoint) - configureAuthFunc(&incidentEntitiesClient.Client) + incidentCommentsClient, err := incidentcomments.NewIncidentCommentsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IncidentComments client: %+v", err) + } + configureFunc(incidentCommentsClient.Client) - incidentRelationsClient := incidentrelations.NewIncidentRelationsClientWithBaseURI(endpoint) - configureAuthFunc(&incidentRelationsClient.Client) + incidentEntitiesClient, err := incidententities.NewIncidentEntitiesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IncidentEntities client: %+v", err) + } + configureFunc(incidentEntitiesClient.Client) - incidentTeamClient := incidentteam.NewIncidentTeamClientWithBaseURI(endpoint) - configureAuthFunc(&incidentTeamClient.Client) + incidentRelationsClient, err := incidentrelations.NewIncidentRelationsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IncidentRelations client: %+v", err) + } + configureFunc(incidentRelationsClient.Client) - incidentsClient := incidents.NewIncidentsClientWithBaseURI(endpoint) - configureAuthFunc(&incidentsClient.Client) + incidentTeamClient, err := incidentteam.NewIncidentTeamClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IncidentTeam client: %+v", err) + } + configureFunc(incidentTeamClient.Client) - manualTriggerClient := manualtrigger.NewManualTriggerClientWithBaseURI(endpoint) - configureAuthFunc(&manualTriggerClient.Client) + incidentsClient, err := incidents.NewIncidentsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Incidents client: %+v", err) + } + configureFunc(incidentsClient.Client) - metadataClient := metadata.NewMetadataClientWithBaseURI(endpoint) - configureAuthFunc(&metadataClient.Client) + manualTriggerClient, err := manualtrigger.NewManualTriggerClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ManualTrigger client: %+v", err) + } + configureFunc(manualTriggerClient.Client) - officeConsentsClient := officeconsents.NewOfficeConsentsClientWithBaseURI(endpoint) - configureAuthFunc(&officeConsentsClient.Client) + metadataClient, err := metadata.NewMetadataClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Metadata client: %+v", err) + } + configureFunc(metadataClient.Client) - repositoriesClient := repositories.NewRepositoriesClientWithBaseURI(endpoint) - configureAuthFunc(&repositoriesClient.Client) + officeConsentsClient, err := officeconsents.NewOfficeConsentsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building OfficeConsents client: %+v", err) + } + configureFunc(officeConsentsClient.Client) - securityMLAnalyticsSettingsClient := securitymlanalyticssettings.NewSecurityMLAnalyticsSettingsClientWithBaseURI(endpoint) - configureAuthFunc(&securityMLAnalyticsSettingsClient.Client) + repositoriesClient, err := repositories.NewRepositoriesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Repositories client: %+v", err) + } + configureFunc(repositoriesClient.Client) - sentinelOnboardingStatesClient := sentinelonboardingstates.NewSentinelOnboardingStatesClientWithBaseURI(endpoint) - configureAuthFunc(&sentinelOnboardingStatesClient.Client) + securityMLAnalyticsSettingsClient, err := securitymlanalyticssettings.NewSecurityMLAnalyticsSettingsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SecurityMLAnalyticsSettings client: %+v", err) + } + configureFunc(securityMLAnalyticsSettingsClient.Client) - settingsClient := settings.NewSettingsClientWithBaseURI(endpoint) - configureAuthFunc(&settingsClient.Client) + sentinelOnboardingStatesClient, err := sentinelonboardingstates.NewSentinelOnboardingStatesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SentinelOnboardingStates client: %+v", err) + } + configureFunc(sentinelOnboardingStatesClient.Client) - sourceControlsClient := sourcecontrols.NewSourceControlsClientWithBaseURI(endpoint) - configureAuthFunc(&sourceControlsClient.Client) + settingsClient, err := settings.NewSettingsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Settings client: %+v", err) + } + configureFunc(settingsClient.Client) - threatIntelligenceClient := threatintelligence.NewThreatIntelligenceClientWithBaseURI(endpoint) - configureAuthFunc(&threatIntelligenceClient.Client) + sourceControlsClient, err := sourcecontrols.NewSourceControlsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SourceControls client: %+v", err) + } + configureFunc(sourceControlsClient.Client) - watchlistItemsClient := watchlistitems.NewWatchlistItemsClientWithBaseURI(endpoint) - configureAuthFunc(&watchlistItemsClient.Client) + threatIntelligenceClient, err := threatintelligence.NewThreatIntelligenceClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ThreatIntelligence client: %+v", err) + } + configureFunc(threatIntelligenceClient.Client) - watchlistsClient := watchlists.NewWatchlistsClientWithBaseURI(endpoint) - configureAuthFunc(&watchlistsClient.Client) + watchlistItemsClient, err := watchlistitems.NewWatchlistItemsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building WatchlistItems client: %+v", err) + } + configureFunc(watchlistItemsClient.Client) - return Client{ - Actions: &actionsClient, - AlertRuleTemplates: &alertRuleTemplatesClient, - AlertRules: &alertRulesClient, - AutomationRules: &automationRulesClient, - Bookmark: &bookmarkClient, - BookmarkRelations: &bookmarkRelationsClient, - Bookmarks: &bookmarksClient, - CheckDataConnectorRequirements: &checkDataConnectorRequirementsClient, - DataConnectors: &dataConnectorsClient, - DataConnectorsConnect: &dataConnectorsConnectClient, - DataConnectorsDisconnect: &dataConnectorsDisconnectClient, - Enrichment: &enrichmentClient, - Entities: &entitiesClient, - EntityQueries: &entityQueriesClient, - EntityRelations: &entityRelationsClient, - EntityTypes: &entityTypesClient, - IncidentAlerts: &incidentAlertsClient, - IncidentBookmarks: &incidentBookmarksClient, - IncidentComments: &incidentCommentsClient, - IncidentEntities: &incidentEntitiesClient, - IncidentRelations: &incidentRelationsClient, - IncidentTeam: &incidentTeamClient, - Incidents: &incidentsClient, - ManualTrigger: &manualTriggerClient, - Metadata: &metadataClient, - OfficeConsents: &officeConsentsClient, - Repositories: &repositoriesClient, - SecurityMLAnalyticsSettings: &securityMLAnalyticsSettingsClient, - SentinelOnboardingStates: &sentinelOnboardingStatesClient, - Settings: &settingsClient, - SourceControls: &sourceControlsClient, - ThreatIntelligence: &threatIntelligenceClient, - WatchlistItems: &watchlistItemsClient, - Watchlists: &watchlistsClient, + watchlistsClient, err := watchlists.NewWatchlistsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Watchlists client: %+v", err) } + configureFunc(watchlistsClient.Client) + + return &Client{ + Actions: actionsClient, + AlertRuleTemplates: alertRuleTemplatesClient, + AlertRules: alertRulesClient, + AutomationRules: automationRulesClient, + Bookmark: bookmarkClient, + BookmarkRelations: bookmarkRelationsClient, + Bookmarks: bookmarksClient, + CheckDataConnectorRequirements: checkDataConnectorRequirementsClient, + DataConnectors: dataConnectorsClient, + DataConnectorsConnect: dataConnectorsConnectClient, + DataConnectorsDisconnect: dataConnectorsDisconnectClient, + Enrichment: enrichmentClient, + Entities: entitiesClient, + EntityQueries: entityQueriesClient, + EntityRelations: entityRelationsClient, + EntityTypes: entityTypesClient, + IncidentAlerts: incidentAlertsClient, + IncidentBookmarks: incidentBookmarksClient, + IncidentComments: incidentCommentsClient, + IncidentEntities: incidentEntitiesClient, + IncidentRelations: incidentRelationsClient, + IncidentTeam: incidentTeamClient, + Incidents: incidentsClient, + ManualTrigger: manualTriggerClient, + Metadata: metadataClient, + OfficeConsents: officeConsentsClient, + Repositories: repositoriesClient, + SecurityMLAnalyticsSettings: securityMLAnalyticsSettingsClient, + SentinelOnboardingStates: sentinelOnboardingStatesClient, + Settings: settingsClient, + SourceControls: sourceControlsClient, + ThreatIntelligence: threatIntelligenceClient, + WatchlistItems: watchlistItemsClient, + Watchlists: watchlistsClient, + }, nil } diff --git a/resource-manager/securityinsights/2022-07-01-preview/dataconnectors/client.go b/resource-manager/securityinsights/2022-07-01-preview/dataconnectors/client.go index cf334b72568..8ed0120c79a 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/dataconnectors/client.go +++ b/resource-manager/securityinsights/2022-07-01-preview/dataconnectors/client.go @@ -1,18 +1,26 @@ package dataconnectors -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type DataConnectorsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewDataConnectorsClientWithBaseURI(endpoint string) DataConnectorsClient { - return DataConnectorsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewDataConnectorsClientWithBaseURI(sdkApi sdkEnv.Api) (*DataConnectorsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "dataconnectors", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DataConnectorsClient: %+v", err) } + + return &DataConnectorsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-07-01-preview/dataconnectors/constants.go b/resource-manager/securityinsights/2022-07-01-preview/dataconnectors/constants.go index 1a556e835bb..ae527d22647 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/dataconnectors/constants.go +++ b/resource-manager/securityinsights/2022-07-01-preview/dataconnectors/constants.go @@ -1,6 +1,10 @@ package dataconnectors -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -29,6 +33,19 @@ func PossibleValuesForConnectivityType() []string { } } +func (s *ConnectivityType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConnectivityType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConnectivityType(input string) (*ConnectivityType, error) { vals := map[string]ConnectivityType{ "isconnectedquery": ConnectivityTypeIsConnectedQuery, @@ -92,6 +109,19 @@ func PossibleValuesForDataConnectorKind() []string { } } +func (s *DataConnectorKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataConnectorKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDataConnectorKind(input string) (*DataConnectorKind, error) { vals := map[string]DataConnectorKind{ "apipolling": DataConnectorKindAPIPolling, @@ -138,6 +168,19 @@ func PossibleValuesForDataTypeState() []string { } } +func (s *DataTypeState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataTypeState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDataTypeState(input string) (*DataTypeState, error) { vals := map[string]DataTypeState{ "disabled": DataTypeStateDisabled, @@ -168,6 +211,19 @@ func PossibleValuesForPermissionProviderScope() []string { } } +func (s *PermissionProviderScope) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePermissionProviderScope(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parsePermissionProviderScope(input string) (*PermissionProviderScope, error) { vals := map[string]PermissionProviderScope{ "resourcegroup": PermissionProviderScopeResourceGroup, @@ -199,6 +255,19 @@ func PossibleValuesForPollingFrequency() []string { } } +func (s *PollingFrequency) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePollingFrequency(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parsePollingFrequency(input string) (*PollingFrequency, error) { vals := map[string]PollingFrequency{ "onceaday": PollingFrequencyOnceADay, @@ -236,6 +305,19 @@ func PossibleValuesForProviderName() []string { } } +func (s *ProviderName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProviderName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseProviderName(input string) (*ProviderName, error) { vals := map[string]ProviderName{ "microsoft.authorization/policyassignments": ProviderNameMicrosoftPointAuthorizationPolicyAssignments, @@ -270,6 +352,19 @@ func PossibleValuesForSettingType() []string { } } +func (s *SettingType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSettingType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSettingType(input string) (*SettingType, error) { vals := map[string]SettingType{ "copyablelabel": SettingTypeCopyableLabel, diff --git a/resource-manager/securityinsights/2022-07-01-preview/dataconnectors/method_createorupdate.go b/resource-manager/securityinsights/2022-07-01-preview/dataconnectors/method_createorupdate.go new file mode 100644 index 00000000000..c5f6e5d1503 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/dataconnectors/method_createorupdate.go @@ -0,0 +1,63 @@ +package dataconnectors + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DataConnector +} + +// CreateOrUpdate ... +func (c DataConnectorsClient) CreateOrUpdate(ctx context.Context, id DataConnectorId, input DataConnector) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalDataConnectorImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/dataconnectors/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/dataconnectors/method_createorupdate_autorest.go deleted file mode 100644 index 1f259eca36c..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/dataconnectors/method_createorupdate_autorest.go +++ /dev/null @@ -1,78 +0,0 @@ -package dataconnectors - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *DataConnector -} - -// CreateOrUpdate ... -func (c DataConnectorsClient) CreateOrUpdate(ctx context.Context, id DataConnectorId, input DataConnector) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c DataConnectorsClient) preparerForCreateOrUpdate(ctx context.Context, id DataConnectorId, input DataConnector) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c DataConnectorsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalDataConnectorImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/dataconnectors/method_delete.go b/resource-manager/securityinsights/2022-07-01-preview/dataconnectors/method_delete.go new file mode 100644 index 00000000000..8461ec6d8a1 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/dataconnectors/method_delete.go @@ -0,0 +1,47 @@ +package dataconnectors + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c DataConnectorsClient) Delete(ctx context.Context, id DataConnectorId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/dataconnectors/method_delete_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/dataconnectors/method_delete_autorest.go deleted file mode 100644 index ac4ddf57441..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/dataconnectors/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package dataconnectors - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c DataConnectorsClient) Delete(ctx context.Context, id DataConnectorId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c DataConnectorsClient) preparerForDelete(ctx context.Context, id DataConnectorId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c DataConnectorsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/dataconnectors/method_get.go b/resource-manager/securityinsights/2022-07-01-preview/dataconnectors/method_get.go new file mode 100644 index 00000000000..3511ba85477 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/dataconnectors/method_get.go @@ -0,0 +1,58 @@ +package dataconnectors + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DataConnector +} + +// Get ... +func (c DataConnectorsClient) Get(ctx context.Context, id DataConnectorId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalDataConnectorImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/dataconnectors/method_get_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/dataconnectors/method_get_autorest.go deleted file mode 100644 index af56be19c9c..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/dataconnectors/method_get_autorest.go +++ /dev/null @@ -1,77 +0,0 @@ -package dataconnectors - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *DataConnector -} - -// Get ... -func (c DataConnectorsClient) Get(ctx context.Context, id DataConnectorId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c DataConnectorsClient) preparerForGet(ctx context.Context, id DataConnectorId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c DataConnectorsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalDataConnectorImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/dataconnectors/method_list.go b/resource-manager/securityinsights/2022-07-01-preview/dataconnectors/method_list.go new file mode 100644 index 00000000000..6975384fdee --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/dataconnectors/method_list.go @@ -0,0 +1,103 @@ +package dataconnectors + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DataConnector +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []DataConnector +} + +// List ... +func (c DataConnectorsClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/dataConnectors", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]DataConnector, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalDataConnectorImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for DataConnector (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// ListComplete retrieves all the results into a single object +func (c DataConnectorsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, DataConnectorOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DataConnectorsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate DataConnectorOperationPredicate) (result ListCompleteResult, err error) { + items := make([]DataConnector, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/dataconnectors/method_list_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/dataconnectors/method_list_autorest.go deleted file mode 100644 index e08d153a6eb..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/dataconnectors/method_list_autorest.go +++ /dev/null @@ -1,196 +0,0 @@ -package dataconnectors - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]DataConnector - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []DataConnector -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c DataConnectorsClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c DataConnectorsClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/dataConnectors", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c DataConnectorsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c DataConnectorsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]DataConnector, 0) - for i, v := range respObj.Values { - val, err := unmarshalDataConnectorImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for DataConnector (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c DataConnectorsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, DataConnectorOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c DataConnectorsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate DataConnectorOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]DataConnector, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/dataconnectorsconnect/client.go b/resource-manager/securityinsights/2022-07-01-preview/dataconnectorsconnect/client.go index dd44f929cc5..f4ed6b1fb50 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/dataconnectorsconnect/client.go +++ b/resource-manager/securityinsights/2022-07-01-preview/dataconnectorsconnect/client.go @@ -1,18 +1,26 @@ package dataconnectorsconnect -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type DataConnectorsConnectClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewDataConnectorsConnectClientWithBaseURI(endpoint string) DataConnectorsConnectClient { - return DataConnectorsConnectClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewDataConnectorsConnectClientWithBaseURI(sdkApi sdkEnv.Api) (*DataConnectorsConnectClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "dataconnectorsconnect", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DataConnectorsConnectClient: %+v", err) } + + return &DataConnectorsConnectClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-07-01-preview/dataconnectorsconnect/constants.go b/resource-manager/securityinsights/2022-07-01-preview/dataconnectorsconnect/constants.go index 04ec07ac553..a5b7f1713ca 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/dataconnectorsconnect/constants.go +++ b/resource-manager/securityinsights/2022-07-01-preview/dataconnectorsconnect/constants.go @@ -1,6 +1,10 @@ package dataconnectorsconnect -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -21,6 +25,19 @@ func PossibleValuesForConnectAuthKind() []string { } } +func (s *ConnectAuthKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConnectAuthKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConnectAuthKind(input string) (*ConnectAuthKind, error) { vals := map[string]ConnectAuthKind{ "apikey": ConnectAuthKindAPIKey, diff --git a/resource-manager/securityinsights/2022-07-01-preview/dataconnectorsconnect/method_dataconnectorsconnect.go b/resource-manager/securityinsights/2022-07-01-preview/dataconnectorsconnect/method_dataconnectorsconnect.go new file mode 100644 index 00000000000..50018e5b900 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/dataconnectorsconnect/method_dataconnectorsconnect.go @@ -0,0 +1,51 @@ +package dataconnectorsconnect + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataConnectorsConnectOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// DataConnectorsConnect ... +func (c DataConnectorsConnectClient) DataConnectorsConnect(ctx context.Context, id DataConnectorId, input DataConnectorConnectBody) (result DataConnectorsConnectOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/connect", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/dataconnectorsconnect/method_dataconnectorsconnect_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/dataconnectorsconnect/method_dataconnectorsconnect_autorest.go deleted file mode 100644 index 191360dda4c..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/dataconnectorsconnect/method_dataconnectorsconnect_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package dataconnectorsconnect - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DataConnectorsConnectOperationResponse struct { - HttpResponse *http.Response -} - -// DataConnectorsConnect ... -func (c DataConnectorsConnectClient) DataConnectorsConnect(ctx context.Context, id DataConnectorId, input DataConnectorConnectBody) (result DataConnectorsConnectOperationResponse, err error) { - req, err := c.preparerForDataConnectorsConnect(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectorsconnect.DataConnectorsConnectClient", "DataConnectorsConnect", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectorsconnect.DataConnectorsConnectClient", "DataConnectorsConnect", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDataConnectorsConnect(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectorsconnect.DataConnectorsConnectClient", "DataConnectorsConnect", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDataConnectorsConnect prepares the DataConnectorsConnect request. -func (c DataConnectorsConnectClient) preparerForDataConnectorsConnect(ctx context.Context, id DataConnectorId, input DataConnectorConnectBody) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/connect", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDataConnectorsConnect handles the response to the DataConnectorsConnect request. The method always -// closes the http.Response Body. -func (c DataConnectorsConnectClient) responderForDataConnectorsConnect(resp *http.Response) (result DataConnectorsConnectOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/dataconnectorsdisconnect/client.go b/resource-manager/securityinsights/2022-07-01-preview/dataconnectorsdisconnect/client.go index cd8304c370a..57ec64abb3c 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/dataconnectorsdisconnect/client.go +++ b/resource-manager/securityinsights/2022-07-01-preview/dataconnectorsdisconnect/client.go @@ -1,18 +1,26 @@ package dataconnectorsdisconnect -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type DataConnectorsDisconnectClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewDataConnectorsDisconnectClientWithBaseURI(endpoint string) DataConnectorsDisconnectClient { - return DataConnectorsDisconnectClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewDataConnectorsDisconnectClientWithBaseURI(sdkApi sdkEnv.Api) (*DataConnectorsDisconnectClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "dataconnectorsdisconnect", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DataConnectorsDisconnectClient: %+v", err) } + + return &DataConnectorsDisconnectClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-07-01-preview/dataconnectorsdisconnect/method_dataconnectorsdisconnect.go b/resource-manager/securityinsights/2022-07-01-preview/dataconnectorsdisconnect/method_dataconnectorsdisconnect.go new file mode 100644 index 00000000000..2a883a2c958 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/dataconnectorsdisconnect/method_dataconnectorsdisconnect.go @@ -0,0 +1,47 @@ +package dataconnectorsdisconnect + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataConnectorsDisconnectOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// DataConnectorsDisconnect ... +func (c DataConnectorsDisconnectClient) DataConnectorsDisconnect(ctx context.Context, id DataConnectorId) (result DataConnectorsDisconnectOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/disconnect", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/dataconnectorsdisconnect/method_dataconnectorsdisconnect_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/dataconnectorsdisconnect/method_dataconnectorsdisconnect_autorest.go deleted file mode 100644 index 61c1f036044..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/dataconnectorsdisconnect/method_dataconnectorsdisconnect_autorest.go +++ /dev/null @@ -1,67 +0,0 @@ -package dataconnectorsdisconnect - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DataConnectorsDisconnectOperationResponse struct { - HttpResponse *http.Response -} - -// DataConnectorsDisconnect ... -func (c DataConnectorsDisconnectClient) DataConnectorsDisconnect(ctx context.Context, id DataConnectorId) (result DataConnectorsDisconnectOperationResponse, err error) { - req, err := c.preparerForDataConnectorsDisconnect(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectorsdisconnect.DataConnectorsDisconnectClient", "DataConnectorsDisconnect", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectorsdisconnect.DataConnectorsDisconnectClient", "DataConnectorsDisconnect", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDataConnectorsDisconnect(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectorsdisconnect.DataConnectorsDisconnectClient", "DataConnectorsDisconnect", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDataConnectorsDisconnect prepares the DataConnectorsDisconnect request. -func (c DataConnectorsDisconnectClient) preparerForDataConnectorsDisconnect(ctx context.Context, id DataConnectorId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/disconnect", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDataConnectorsDisconnect handles the response to the DataConnectorsDisconnect request. The method always -// closes the http.Response Body. -func (c DataConnectorsDisconnectClient) responderForDataConnectorsDisconnect(resp *http.Response) (result DataConnectorsDisconnectOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/enrichment/client.go b/resource-manager/securityinsights/2022-07-01-preview/enrichment/client.go index 86c852a64d4..f60a3bef882 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/enrichment/client.go +++ b/resource-manager/securityinsights/2022-07-01-preview/enrichment/client.go @@ -1,18 +1,26 @@ package enrichment -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type EnrichmentClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewEnrichmentClientWithBaseURI(endpoint string) EnrichmentClient { - return EnrichmentClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewEnrichmentClientWithBaseURI(sdkApi sdkEnv.Api) (*EnrichmentClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "enrichment", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating EnrichmentClient: %+v", err) } + + return &EnrichmentClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-07-01-preview/enrichment/method_domainwhoisget.go b/resource-manager/securityinsights/2022-07-01-preview/enrichment/method_domainwhoisget.go new file mode 100644 index 00000000000..5598e43044b --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/enrichment/method_domainwhoisget.go @@ -0,0 +1,81 @@ +package enrichment + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DomainWhoisGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EnrichmentDomainWhois +} + +type DomainWhoisGetOperationOptions struct { + Domain *string +} + +func DefaultDomainWhoisGetOperationOptions() DomainWhoisGetOperationOptions { + return DomainWhoisGetOperationOptions{} +} + +func (o DomainWhoisGetOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o DomainWhoisGetOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DomainWhoisGetOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Domain != nil { + out.Append("domain", fmt.Sprintf("%v", *o.Domain)) + } + return &out +} + +// DomainWhoisGet ... +func (c EnrichmentClient) DomainWhoisGet(ctx context.Context, id commonids.ResourceGroupId, options DomainWhoisGetOperationOptions) (result DomainWhoisGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/enrichment/domain/whois", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/enrichment/method_domainwhoisget_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/enrichment/method_domainwhoisget_autorest.go deleted file mode 100644 index 1e0a9800903..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/enrichment/method_domainwhoisget_autorest.go +++ /dev/null @@ -1,99 +0,0 @@ -package enrichment - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DomainWhoisGetOperationResponse struct { - HttpResponse *http.Response - Model *EnrichmentDomainWhois -} - -type DomainWhoisGetOperationOptions struct { - Domain *string -} - -func DefaultDomainWhoisGetOperationOptions() DomainWhoisGetOperationOptions { - return DomainWhoisGetOperationOptions{} -} - -func (o DomainWhoisGetOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o DomainWhoisGetOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Domain != nil { - out["domain"] = *o.Domain - } - - return out -} - -// DomainWhoisGet ... -func (c EnrichmentClient) DomainWhoisGet(ctx context.Context, id commonids.ResourceGroupId, options DomainWhoisGetOperationOptions) (result DomainWhoisGetOperationResponse, err error) { - req, err := c.preparerForDomainWhoisGet(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "enrichment.EnrichmentClient", "DomainWhoisGet", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "enrichment.EnrichmentClient", "DomainWhoisGet", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDomainWhoisGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "enrichment.EnrichmentClient", "DomainWhoisGet", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDomainWhoisGet prepares the DomainWhoisGet request. -func (c EnrichmentClient) preparerForDomainWhoisGet(ctx context.Context, id commonids.ResourceGroupId, options DomainWhoisGetOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/enrichment/domain/whois", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDomainWhoisGet handles the response to the DomainWhoisGet request. The method always -// closes the http.Response Body. -func (c EnrichmentClient) responderForDomainWhoisGet(resp *http.Response) (result DomainWhoisGetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/enrichment/method_ipgeodataget.go b/resource-manager/securityinsights/2022-07-01-preview/enrichment/method_ipgeodataget.go new file mode 100644 index 00000000000..05e73d79b5c --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/enrichment/method_ipgeodataget.go @@ -0,0 +1,81 @@ +package enrichment + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IPGeodataGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EnrichmentIPGeodata +} + +type IPGeodataGetOperationOptions struct { + IPAddress *string +} + +func DefaultIPGeodataGetOperationOptions() IPGeodataGetOperationOptions { + return IPGeodataGetOperationOptions{} +} + +func (o IPGeodataGetOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o IPGeodataGetOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o IPGeodataGetOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.IPAddress != nil { + out.Append("ipAddress", fmt.Sprintf("%v", *o.IPAddress)) + } + return &out +} + +// IPGeodataGet ... +func (c EnrichmentClient) IPGeodataGet(ctx context.Context, id commonids.ResourceGroupId, options IPGeodataGetOperationOptions) (result IPGeodataGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/enrichment/ip/geodata", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/enrichment/method_ipgeodataget_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/enrichment/method_ipgeodataget_autorest.go deleted file mode 100644 index 8c489e6da71..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/enrichment/method_ipgeodataget_autorest.go +++ /dev/null @@ -1,99 +0,0 @@ -package enrichment - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IPGeodataGetOperationResponse struct { - HttpResponse *http.Response - Model *EnrichmentIPGeodata -} - -type IPGeodataGetOperationOptions struct { - IPAddress *string -} - -func DefaultIPGeodataGetOperationOptions() IPGeodataGetOperationOptions { - return IPGeodataGetOperationOptions{} -} - -func (o IPGeodataGetOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o IPGeodataGetOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.IPAddress != nil { - out["ipAddress"] = *o.IPAddress - } - - return out -} - -// IPGeodataGet ... -func (c EnrichmentClient) IPGeodataGet(ctx context.Context, id commonids.ResourceGroupId, options IPGeodataGetOperationOptions) (result IPGeodataGetOperationResponse, err error) { - req, err := c.preparerForIPGeodataGet(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "enrichment.EnrichmentClient", "IPGeodataGet", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "enrichment.EnrichmentClient", "IPGeodataGet", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIPGeodataGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "enrichment.EnrichmentClient", "IPGeodataGet", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIPGeodataGet prepares the IPGeodataGet request. -func (c EnrichmentClient) preparerForIPGeodataGet(ctx context.Context, id commonids.ResourceGroupId, options IPGeodataGetOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/enrichment/ip/geodata", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIPGeodataGet handles the response to the IPGeodataGet request. The method always -// closes the http.Response Body. -func (c EnrichmentClient) responderForIPGeodataGet(resp *http.Response) (result IPGeodataGetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/entities/client.go b/resource-manager/securityinsights/2022-07-01-preview/entities/client.go index c9a2f082154..69f26c8d7e5 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/entities/client.go +++ b/resource-manager/securityinsights/2022-07-01-preview/entities/client.go @@ -1,18 +1,26 @@ package entities -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type EntitiesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewEntitiesClientWithBaseURI(endpoint string) EntitiesClient { - return EntitiesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewEntitiesClientWithBaseURI(sdkApi sdkEnv.Api) (*EntitiesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "entities", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating EntitiesClient: %+v", err) } + + return &EntitiesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-07-01-preview/entities/constants.go b/resource-manager/securityinsights/2022-07-01-preview/entities/constants.go index 5ff9aef6a17..40b7dae6f30 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/entities/constants.go +++ b/resource-manager/securityinsights/2022-07-01-preview/entities/constants.go @@ -1,6 +1,10 @@ package entities -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -23,6 +27,19 @@ func PossibleValuesForAlertSeverity() []string { } } +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertSeverity(input string) (*AlertSeverity, error) { vals := map[string]AlertSeverity{ "high": AlertSeverityHigh, @@ -51,6 +68,19 @@ func PossibleValuesForEntityItemQueryKind() []string { } } +func (s *EntityItemQueryKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityItemQueryKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityItemQueryKind(input string) (*EntityItemQueryKind, error) { vals := map[string]EntityItemQueryKind{ "insight": EntityItemQueryKindInsight, @@ -118,6 +148,19 @@ func PossibleValuesForEntityKind() []string { } } +func (s *EntityKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityKind(input string) (*EntityKind, error) { vals := map[string]EntityKind{ "account": EntityKindAccount, @@ -168,6 +211,19 @@ func PossibleValuesForEntityQueryKind() []string { } } +func (s *EntityQueryKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityQueryKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityQueryKind(input string) (*EntityQueryKind, error) { vals := map[string]EntityQueryKind{ "activity": EntityQueryKindActivity, @@ -201,6 +257,19 @@ func PossibleValuesForEntityTimelineKind() []string { } } +func (s *EntityTimelineKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityTimelineKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityTimelineKind(input string) (*EntityTimelineKind, error) { vals := map[string]EntityTimelineKind{ "activity": EntityTimelineKindActivity, @@ -271,6 +340,19 @@ func PossibleValuesForEntityType() []string { } } +func (s *EntityType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityType(input string) (*EntityType, error) { vals := map[string]EntityType{ "account": EntityTypeAccount, @@ -317,6 +399,19 @@ func PossibleValuesForGetInsightsError() []string { } } +func (s *GetInsightsError) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseGetInsightsError(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseGetInsightsError(input string) (*GetInsightsError, error) { vals := map[string]GetInsightsError{ "insight": GetInsightsErrorInsight, @@ -348,6 +443,19 @@ func PossibleValuesForOutputType() []string { } } +func (s *OutputType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOutputType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseOutputType(input string) (*OutputType, error) { vals := map[string]OutputType{ "date": OutputTypeDate, diff --git a/resource-manager/securityinsights/2022-07-01-preview/entities/method_expand.go b/resource-manager/securityinsights/2022-07-01-preview/entities/method_expand.go new file mode 100644 index 00000000000..4a41d4bd23a --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/entities/method_expand.go @@ -0,0 +1,56 @@ +package entities + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExpandOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EntityExpandResponse +} + +// Expand ... +func (c EntitiesClient) Expand(ctx context.Context, id EntityId, input EntityExpandParameters) (result ExpandOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/expand", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/entities/method_expand_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/entities/method_expand_autorest.go deleted file mode 100644 index 3b993d594dc..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/entities/method_expand_autorest.go +++ /dev/null @@ -1,70 +0,0 @@ -package entities - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ExpandOperationResponse struct { - HttpResponse *http.Response - Model *EntityExpandResponse -} - -// Expand ... -func (c EntitiesClient) Expand(ctx context.Context, id EntityId, input EntityExpandParameters) (result ExpandOperationResponse, err error) { - req, err := c.preparerForExpand(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "Expand", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "Expand", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForExpand(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "Expand", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForExpand prepares the Expand request. -func (c EntitiesClient) preparerForExpand(ctx context.Context, id EntityId, input EntityExpandParameters) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/expand", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForExpand handles the response to the Expand request. The method always -// closes the http.Response Body. -func (c EntitiesClient) responderForExpand(resp *http.Response) (result ExpandOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/entities/method_get.go b/resource-manager/securityinsights/2022-07-01-preview/entities/method_get.go new file mode 100644 index 00000000000..e3ea4abfc78 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/entities/method_get.go @@ -0,0 +1,51 @@ +package entities + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Entity +} + +// Get ... +func (c EntitiesClient) Get(ctx context.Context, id EntityId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/entities/method_get_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/entities/method_get_autorest.go deleted file mode 100644 index d77e86bbcb4..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/entities/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package entities - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *Entity -} - -// Get ... -func (c EntitiesClient) Get(ctx context.Context, id EntityId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c EntitiesClient) preparerForGet(ctx context.Context, id EntityId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c EntitiesClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/entities/method_getinsights.go b/resource-manager/securityinsights/2022-07-01-preview/entities/method_getinsights.go new file mode 100644 index 00000000000..d1422bda1ec --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/entities/method_getinsights.go @@ -0,0 +1,56 @@ +package entities + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetInsightsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EntityGetInsightsResponse +} + +// GetInsights ... +func (c EntitiesClient) GetInsights(ctx context.Context, id EntityId, input EntityGetInsightsParameters) (result GetInsightsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/getInsights", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/entities/method_getinsights_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/entities/method_getinsights_autorest.go deleted file mode 100644 index c3ae3a1ab75..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/entities/method_getinsights_autorest.go +++ /dev/null @@ -1,70 +0,0 @@ -package entities - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetInsightsOperationResponse struct { - HttpResponse *http.Response - Model *EntityGetInsightsResponse -} - -// GetInsights ... -func (c EntitiesClient) GetInsights(ctx context.Context, id EntityId, input EntityGetInsightsParameters) (result GetInsightsOperationResponse, err error) { - req, err := c.preparerForGetInsights(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "GetInsights", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "GetInsights", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGetInsights(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "GetInsights", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGetInsights prepares the GetInsights request. -func (c EntitiesClient) preparerForGetInsights(ctx context.Context, id EntityId, input EntityGetInsightsParameters) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/getInsights", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGetInsights handles the response to the GetInsights request. The method always -// closes the http.Response Body. -func (c EntitiesClient) responderForGetInsights(resp *http.Response) (result GetInsightsOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/entities/method_gettimelinelist.go b/resource-manager/securityinsights/2022-07-01-preview/entities/method_gettimelinelist.go new file mode 100644 index 00000000000..46c6b6cba26 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/entities/method_gettimelinelist.go @@ -0,0 +1,56 @@ +package entities + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetTimelinelistOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EntityTimelineResponse +} + +// GetTimelinelist ... +func (c EntitiesClient) GetTimelinelist(ctx context.Context, id EntityId, input EntityTimelineParameters) (result GetTimelinelistOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/getTimeline", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/entities/method_gettimelinelist_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/entities/method_gettimelinelist_autorest.go deleted file mode 100644 index e04da4a2b55..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/entities/method_gettimelinelist_autorest.go +++ /dev/null @@ -1,70 +0,0 @@ -package entities - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetTimelinelistOperationResponse struct { - HttpResponse *http.Response - Model *EntityTimelineResponse -} - -// GetTimelinelist ... -func (c EntitiesClient) GetTimelinelist(ctx context.Context, id EntityId, input EntityTimelineParameters) (result GetTimelinelistOperationResponse, err error) { - req, err := c.preparerForGetTimelinelist(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "GetTimelinelist", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "GetTimelinelist", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGetTimelinelist(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "GetTimelinelist", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGetTimelinelist prepares the GetTimelinelist request. -func (c EntitiesClient) preparerForGetTimelinelist(ctx context.Context, id EntityId, input EntityTimelineParameters) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/getTimeline", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGetTimelinelist handles the response to the GetTimelinelist request. The method always -// closes the http.Response Body. -func (c EntitiesClient) responderForGetTimelinelist(resp *http.Response) (result GetTimelinelistOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/entities/method_list.go b/resource-manager/securityinsights/2022-07-01-preview/entities/method_list.go new file mode 100644 index 00000000000..7bd410bbfb5 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/entities/method_list.go @@ -0,0 +1,91 @@ +package entities + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Entity +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Entity +} + +// List ... +func (c EntitiesClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/entities", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Entity `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c EntitiesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, EntityOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c EntitiesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate EntityOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Entity, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/entities/method_list_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/entities/method_list_autorest.go deleted file mode 100644 index 198d6f95594..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/entities/method_list_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package entities - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]Entity - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []Entity -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c EntitiesClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c EntitiesClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/entities", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c EntitiesClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c EntitiesClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []Entity `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c EntitiesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, EntityOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c EntitiesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate EntityOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]Entity, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/entities/method_queries.go b/resource-manager/securityinsights/2022-07-01-preview/entities/method_queries.go new file mode 100644 index 00000000000..ec05d3bd90a --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/entities/method_queries.go @@ -0,0 +1,80 @@ +package entities + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QueriesOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *GetQueriesResponse +} + +type QueriesOperationOptions struct { + Kind *EntityItemQueryKind +} + +func DefaultQueriesOperationOptions() QueriesOperationOptions { + return QueriesOperationOptions{} +} + +func (o QueriesOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o QueriesOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o QueriesOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Kind != nil { + out.Append("kind", fmt.Sprintf("%v", *o.Kind)) + } + return &out +} + +// Queries ... +func (c EntitiesClient) Queries(ctx context.Context, id EntityId, options QueriesOperationOptions) (result QueriesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/queries", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/entities/method_queries_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/entities/method_queries_autorest.go deleted file mode 100644 index 44f69f71e09..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/entities/method_queries_autorest.go +++ /dev/null @@ -1,98 +0,0 @@ -package entities - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type QueriesOperationResponse struct { - HttpResponse *http.Response - Model *GetQueriesResponse -} - -type QueriesOperationOptions struct { - Kind *EntityItemQueryKind -} - -func DefaultQueriesOperationOptions() QueriesOperationOptions { - return QueriesOperationOptions{} -} - -func (o QueriesOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o QueriesOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Kind != nil { - out["kind"] = *o.Kind - } - - return out -} - -// Queries ... -func (c EntitiesClient) Queries(ctx context.Context, id EntityId, options QueriesOperationOptions) (result QueriesOperationResponse, err error) { - req, err := c.preparerForQueries(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "Queries", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "Queries", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForQueries(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "Queries", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForQueries prepares the Queries request. -func (c EntitiesClient) preparerForQueries(ctx context.Context, id EntityId, options QueriesOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/queries", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForQueries handles the response to the Queries request. The method always -// closes the http.Response Body. -func (c EntitiesClient) responderForQueries(resp *http.Response) (result QueriesOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/entityqueries/client.go b/resource-manager/securityinsights/2022-07-01-preview/entityqueries/client.go index a85c205dbc4..4a7620bff39 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/entityqueries/client.go +++ b/resource-manager/securityinsights/2022-07-01-preview/entityqueries/client.go @@ -1,18 +1,26 @@ package entityqueries -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type EntityQueriesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewEntityQueriesClientWithBaseURI(endpoint string) EntityQueriesClient { - return EntityQueriesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewEntityQueriesClientWithBaseURI(sdkApi sdkEnv.Api) (*EntityQueriesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "entityqueries", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating EntityQueriesClient: %+v", err) } + + return &EntityQueriesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-07-01-preview/entityqueries/constants.go b/resource-manager/securityinsights/2022-07-01-preview/entityqueries/constants.go index f1f3bac7251..9693ed3f519 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/entityqueries/constants.go +++ b/resource-manager/securityinsights/2022-07-01-preview/entityqueries/constants.go @@ -1,6 +1,10 @@ package entityqueries -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -17,6 +21,19 @@ func PossibleValuesForCustomEntityQueryKind() []string { } } +func (s *CustomEntityQueryKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCustomEntityQueryKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseCustomEntityQueryKind(input string) (*CustomEntityQueryKind, error) { vals := map[string]CustomEntityQueryKind{ "activity": CustomEntityQueryKindActivity, @@ -46,6 +63,19 @@ func PossibleValuesForEntityQueryKind() []string { } } +func (s *EntityQueryKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityQueryKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityQueryKind(input string) (*EntityQueryKind, error) { vals := map[string]EntityQueryKind{ "activity": EntityQueryKindActivity, @@ -73,6 +103,19 @@ func PossibleValuesForEntityQueryTemplateKind() []string { } } +func (s *EntityQueryTemplateKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityQueryTemplateKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityQueryTemplateKind(input string) (*EntityQueryTemplateKind, error) { vals := map[string]EntityQueryTemplateKind{ "activity": EntityQueryTemplateKindActivity, @@ -140,6 +183,19 @@ func PossibleValuesForEntityType() []string { } } +func (s *EntityType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityType(input string) (*EntityType, error) { vals := map[string]EntityType{ "account": EntityTypeAccount, @@ -188,6 +244,19 @@ func PossibleValuesForKind() []string { } } +func (s *Kind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseKind(input string) (*Kind, error) { vals := map[string]Kind{ "activity": KindActivity, diff --git a/resource-manager/securityinsights/2022-07-01-preview/entityqueries/method_createorupdate.go b/resource-manager/securityinsights/2022-07-01-preview/entityqueries/method_createorupdate.go new file mode 100644 index 00000000000..b9ecc82c257 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/entityqueries/method_createorupdate.go @@ -0,0 +1,63 @@ +package entityqueries + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EntityQuery +} + +// CreateOrUpdate ... +func (c EntityQueriesClient) CreateOrUpdate(ctx context.Context, id EntityQueryId, input CustomEntityQuery) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalEntityQueryImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/entityqueries/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/entityqueries/method_createorupdate_autorest.go deleted file mode 100644 index eeec49d03b4..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/entityqueries/method_createorupdate_autorest.go +++ /dev/null @@ -1,78 +0,0 @@ -package entityqueries - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *EntityQuery -} - -// CreateOrUpdate ... -func (c EntityQueriesClient) CreateOrUpdate(ctx context.Context, id EntityQueryId, input CustomEntityQuery) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c EntityQueriesClient) preparerForCreateOrUpdate(ctx context.Context, id EntityQueryId, input CustomEntityQuery) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c EntityQueriesClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalEntityQueryImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/entityqueries/method_delete.go b/resource-manager/securityinsights/2022-07-01-preview/entityqueries/method_delete.go new file mode 100644 index 00000000000..b413ad04691 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/entityqueries/method_delete.go @@ -0,0 +1,47 @@ +package entityqueries + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c EntityQueriesClient) Delete(ctx context.Context, id EntityQueryId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/entityqueries/method_delete_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/entityqueries/method_delete_autorest.go deleted file mode 100644 index 3ad079474b1..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/entityqueries/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package entityqueries - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c EntityQueriesClient) Delete(ctx context.Context, id EntityQueryId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c EntityQueriesClient) preparerForDelete(ctx context.Context, id EntityQueryId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c EntityQueriesClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/entityqueries/method_entityquerytemplatesget.go b/resource-manager/securityinsights/2022-07-01-preview/entityqueries/method_entityquerytemplatesget.go new file mode 100644 index 00000000000..2e55614c8f0 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/entityqueries/method_entityquerytemplatesget.go @@ -0,0 +1,58 @@ +package entityqueries + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EntityQueryTemplatesGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EntityQueryTemplate +} + +// EntityQueryTemplatesGet ... +func (c EntityQueriesClient) EntityQueryTemplatesGet(ctx context.Context, id EntityQueryTemplateId) (result EntityQueryTemplatesGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalEntityQueryTemplateImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/entityqueries/method_entityquerytemplatesget_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/entityqueries/method_entityquerytemplatesget_autorest.go deleted file mode 100644 index e5058178ba0..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/entityqueries/method_entityquerytemplatesget_autorest.go +++ /dev/null @@ -1,77 +0,0 @@ -package entityqueries - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type EntityQueryTemplatesGetOperationResponse struct { - HttpResponse *http.Response - Model *EntityQueryTemplate -} - -// EntityQueryTemplatesGet ... -func (c EntityQueriesClient) EntityQueryTemplatesGet(ctx context.Context, id EntityQueryTemplateId) (result EntityQueryTemplatesGetOperationResponse, err error) { - req, err := c.preparerForEntityQueryTemplatesGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "EntityQueryTemplatesGet", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "EntityQueryTemplatesGet", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForEntityQueryTemplatesGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "EntityQueryTemplatesGet", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForEntityQueryTemplatesGet prepares the EntityQueryTemplatesGet request. -func (c EntityQueriesClient) preparerForEntityQueryTemplatesGet(ctx context.Context, id EntityQueryTemplateId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForEntityQueryTemplatesGet handles the response to the EntityQueryTemplatesGet request. The method always -// closes the http.Response Body. -func (c EntityQueriesClient) responderForEntityQueryTemplatesGet(resp *http.Response) (result EntityQueryTemplatesGetOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalEntityQueryTemplateImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/entityqueries/method_entityquerytemplateslist.go b/resource-manager/securityinsights/2022-07-01-preview/entityqueries/method_entityquerytemplateslist.go new file mode 100644 index 00000000000..80a1a6ce617 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/entityqueries/method_entityquerytemplateslist.go @@ -0,0 +1,131 @@ +package entityqueries + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EntityQueryTemplatesListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]EntityQueryTemplate +} + +type EntityQueryTemplatesListCompleteResult struct { + LatestHttpResponse *http.Response + Items []EntityQueryTemplate +} + +type EntityQueryTemplatesListOperationOptions struct { + Kind *Kind +} + +func DefaultEntityQueryTemplatesListOperationOptions() EntityQueryTemplatesListOperationOptions { + return EntityQueryTemplatesListOperationOptions{} +} + +func (o EntityQueryTemplatesListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o EntityQueryTemplatesListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o EntityQueryTemplatesListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Kind != nil { + out.Append("kind", fmt.Sprintf("%v", *o.Kind)) + } + return &out +} + +// EntityQueryTemplatesList ... +func (c EntityQueriesClient) EntityQueryTemplatesList(ctx context.Context, id WorkspaceId, options EntityQueryTemplatesListOperationOptions) (result EntityQueryTemplatesListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/entityQueryTemplates", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]EntityQueryTemplate, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalEntityQueryTemplateImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for EntityQueryTemplate (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// EntityQueryTemplatesListComplete retrieves all the results into a single object +func (c EntityQueriesClient) EntityQueryTemplatesListComplete(ctx context.Context, id WorkspaceId, options EntityQueryTemplatesListOperationOptions) (EntityQueryTemplatesListCompleteResult, error) { + return c.EntityQueryTemplatesListCompleteMatchingPredicate(ctx, id, options, EntityQueryTemplateOperationPredicate{}) +} + +// EntityQueryTemplatesListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c EntityQueriesClient) EntityQueryTemplatesListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options EntityQueryTemplatesListOperationOptions, predicate EntityQueryTemplateOperationPredicate) (result EntityQueryTemplatesListCompleteResult, err error) { + items := make([]EntityQueryTemplate, 0) + + resp, err := c.EntityQueryTemplatesList(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = EntityQueryTemplatesListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/entityqueries/method_entityquerytemplateslist_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/entityqueries/method_entityquerytemplateslist_autorest.go deleted file mode 100644 index 251984e8d83..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/entityqueries/method_entityquerytemplateslist_autorest.go +++ /dev/null @@ -1,225 +0,0 @@ -package entityqueries - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type EntityQueryTemplatesListOperationResponse struct { - HttpResponse *http.Response - Model *[]EntityQueryTemplate - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (EntityQueryTemplatesListOperationResponse, error) -} - -type EntityQueryTemplatesListCompleteResult struct { - Items []EntityQueryTemplate -} - -func (r EntityQueryTemplatesListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r EntityQueryTemplatesListOperationResponse) LoadMore(ctx context.Context) (resp EntityQueryTemplatesListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type EntityQueryTemplatesListOperationOptions struct { - Kind *Kind -} - -func DefaultEntityQueryTemplatesListOperationOptions() EntityQueryTemplatesListOperationOptions { - return EntityQueryTemplatesListOperationOptions{} -} - -func (o EntityQueryTemplatesListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o EntityQueryTemplatesListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Kind != nil { - out["kind"] = *o.Kind - } - - return out -} - -// EntityQueryTemplatesList ... -func (c EntityQueriesClient) EntityQueryTemplatesList(ctx context.Context, id WorkspaceId, options EntityQueryTemplatesListOperationOptions) (resp EntityQueryTemplatesListOperationResponse, err error) { - req, err := c.preparerForEntityQueryTemplatesList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "EntityQueryTemplatesList", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "EntityQueryTemplatesList", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForEntityQueryTemplatesList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "EntityQueryTemplatesList", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForEntityQueryTemplatesList prepares the EntityQueryTemplatesList request. -func (c EntityQueriesClient) preparerForEntityQueryTemplatesList(ctx context.Context, id WorkspaceId, options EntityQueryTemplatesListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/entityQueryTemplates", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForEntityQueryTemplatesListWithNextLink prepares the EntityQueryTemplatesList request with the given nextLink token. -func (c EntityQueriesClient) preparerForEntityQueryTemplatesListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForEntityQueryTemplatesList handles the response to the EntityQueryTemplatesList request. The method always -// closes the http.Response Body. -func (c EntityQueriesClient) responderForEntityQueryTemplatesList(resp *http.Response) (result EntityQueryTemplatesListOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]EntityQueryTemplate, 0) - for i, v := range respObj.Values { - val, err := unmarshalEntityQueryTemplateImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for EntityQueryTemplate (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result EntityQueryTemplatesListOperationResponse, err error) { - req, err := c.preparerForEntityQueryTemplatesListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "EntityQueryTemplatesList", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "EntityQueryTemplatesList", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForEntityQueryTemplatesList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "EntityQueryTemplatesList", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// EntityQueryTemplatesListComplete retrieves all of the results into a single object -func (c EntityQueriesClient) EntityQueryTemplatesListComplete(ctx context.Context, id WorkspaceId, options EntityQueryTemplatesListOperationOptions) (EntityQueryTemplatesListCompleteResult, error) { - return c.EntityQueryTemplatesListCompleteMatchingPredicate(ctx, id, options, EntityQueryTemplateOperationPredicate{}) -} - -// EntityQueryTemplatesListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c EntityQueriesClient) EntityQueryTemplatesListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options EntityQueryTemplatesListOperationOptions, predicate EntityQueryTemplateOperationPredicate) (resp EntityQueryTemplatesListCompleteResult, err error) { - items := make([]EntityQueryTemplate, 0) - - page, err := c.EntityQueryTemplatesList(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := EntityQueryTemplatesListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/entityqueries/method_get.go b/resource-manager/securityinsights/2022-07-01-preview/entityqueries/method_get.go new file mode 100644 index 00000000000..4a7022fa713 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/entityqueries/method_get.go @@ -0,0 +1,58 @@ +package entityqueries + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EntityQuery +} + +// Get ... +func (c EntityQueriesClient) Get(ctx context.Context, id EntityQueryId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalEntityQueryImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/entityqueries/method_get_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/entityqueries/method_get_autorest.go deleted file mode 100644 index ad9e794be03..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/entityqueries/method_get_autorest.go +++ /dev/null @@ -1,77 +0,0 @@ -package entityqueries - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *EntityQuery -} - -// Get ... -func (c EntityQueriesClient) Get(ctx context.Context, id EntityQueryId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c EntityQueriesClient) preparerForGet(ctx context.Context, id EntityQueryId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c EntityQueriesClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalEntityQueryImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/entityqueries/method_list.go b/resource-manager/securityinsights/2022-07-01-preview/entityqueries/method_list.go new file mode 100644 index 00000000000..5cf5f6c7631 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/entityqueries/method_list.go @@ -0,0 +1,131 @@ +package entityqueries + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]EntityQuery +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []EntityQuery +} + +type ListOperationOptions struct { + Kind *Kind +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Kind != nil { + out.Append("kind", fmt.Sprintf("%v", *o.Kind)) + } + return &out +} + +// List ... +func (c EntityQueriesClient) List(ctx context.Context, id WorkspaceId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/entityQueries", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]EntityQuery, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalEntityQueryImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for EntityQuery (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// ListComplete retrieves all the results into a single object +func (c EntityQueriesClient) ListComplete(ctx context.Context, id WorkspaceId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, EntityQueryOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c EntityQueriesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ListOperationOptions, predicate EntityQueryOperationPredicate) (result ListCompleteResult, err error) { + items := make([]EntityQuery, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/entityqueries/method_list_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/entityqueries/method_list_autorest.go deleted file mode 100644 index be9cadd1c8f..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/entityqueries/method_list_autorest.go +++ /dev/null @@ -1,225 +0,0 @@ -package entityqueries - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]EntityQuery - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []EntityQuery -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ListOperationOptions struct { - Kind *Kind -} - -func DefaultListOperationOptions() ListOperationOptions { - return ListOperationOptions{} -} - -func (o ListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Kind != nil { - out["kind"] = *o.Kind - } - - return out -} - -// List ... -func (c EntityQueriesClient) List(ctx context.Context, id WorkspaceId, options ListOperationOptions) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c EntityQueriesClient) preparerForList(ctx context.Context, id WorkspaceId, options ListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/entityQueries", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c EntityQueriesClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c EntityQueriesClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]EntityQuery, 0) - for i, v := range respObj.Values { - val, err := unmarshalEntityQueryImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for EntityQuery (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c EntityQueriesClient) ListComplete(ctx context.Context, id WorkspaceId, options ListOperationOptions) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, options, EntityQueryOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c EntityQueriesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ListOperationOptions, predicate EntityQueryOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]EntityQuery, 0) - - page, err := c.List(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/entityrelations/client.go b/resource-manager/securityinsights/2022-07-01-preview/entityrelations/client.go index ac243fa003e..85b6978e574 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/entityrelations/client.go +++ b/resource-manager/securityinsights/2022-07-01-preview/entityrelations/client.go @@ -1,18 +1,26 @@ package entityrelations -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type EntityRelationsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewEntityRelationsClientWithBaseURI(endpoint string) EntityRelationsClient { - return EntityRelationsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewEntityRelationsClientWithBaseURI(sdkApi sdkEnv.Api) (*EntityRelationsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "entityrelations", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating EntityRelationsClient: %+v", err) } + + return &EntityRelationsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-07-01-preview/entityrelations/method_entitiesrelationslist.go b/resource-manager/securityinsights/2022-07-01-preview/entityrelations/method_entitiesrelationslist.go new file mode 100644 index 00000000000..ffe62e84ee3 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/entityrelations/method_entitiesrelationslist.go @@ -0,0 +1,127 @@ +package entityrelations + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EntitiesRelationsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Relation +} + +type EntitiesRelationsListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Relation +} + +type EntitiesRelationsListOperationOptions struct { + Filter *string + Orderby *string + Top *int64 +} + +func DefaultEntitiesRelationsListOperationOptions() EntitiesRelationsListOperationOptions { + return EntitiesRelationsListOperationOptions{} +} + +func (o EntitiesRelationsListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o EntitiesRelationsListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o EntitiesRelationsListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// EntitiesRelationsList ... +func (c EntityRelationsClient) EntitiesRelationsList(ctx context.Context, id EntityId, options EntitiesRelationsListOperationOptions) (result EntitiesRelationsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/relations", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Relation `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// EntitiesRelationsListComplete retrieves all the results into a single object +func (c EntityRelationsClient) EntitiesRelationsListComplete(ctx context.Context, id EntityId, options EntitiesRelationsListOperationOptions) (EntitiesRelationsListCompleteResult, error) { + return c.EntitiesRelationsListCompleteMatchingPredicate(ctx, id, options, RelationOperationPredicate{}) +} + +// EntitiesRelationsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c EntityRelationsClient) EntitiesRelationsListCompleteMatchingPredicate(ctx context.Context, id EntityId, options EntitiesRelationsListOperationOptions, predicate RelationOperationPredicate) (result EntitiesRelationsListCompleteResult, err error) { + items := make([]Relation, 0) + + resp, err := c.EntitiesRelationsList(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = EntitiesRelationsListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/entityrelations/method_entitiesrelationslist_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/entityrelations/method_entitiesrelationslist_autorest.go deleted file mode 100644 index 7cb48eb2ac6..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/entityrelations/method_entitiesrelationslist_autorest.go +++ /dev/null @@ -1,225 +0,0 @@ -package entityrelations - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type EntitiesRelationsListOperationResponse struct { - HttpResponse *http.Response - Model *[]Relation - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (EntitiesRelationsListOperationResponse, error) -} - -type EntitiesRelationsListCompleteResult struct { - Items []Relation -} - -func (r EntitiesRelationsListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r EntitiesRelationsListOperationResponse) LoadMore(ctx context.Context) (resp EntitiesRelationsListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type EntitiesRelationsListOperationOptions struct { - Filter *string - Orderby *string - Top *int64 -} - -func DefaultEntitiesRelationsListOperationOptions() EntitiesRelationsListOperationOptions { - return EntitiesRelationsListOperationOptions{} -} - -func (o EntitiesRelationsListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o EntitiesRelationsListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Filter != nil { - out["$filter"] = *o.Filter - } - - if o.Orderby != nil { - out["$orderby"] = *o.Orderby - } - - if o.Top != nil { - out["$top"] = *o.Top - } - - return out -} - -// EntitiesRelationsList ... -func (c EntityRelationsClient) EntitiesRelationsList(ctx context.Context, id EntityId, options EntitiesRelationsListOperationOptions) (resp EntitiesRelationsListOperationResponse, err error) { - req, err := c.preparerForEntitiesRelationsList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "entityrelations.EntityRelationsClient", "EntitiesRelationsList", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entityrelations.EntityRelationsClient", "EntitiesRelationsList", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForEntitiesRelationsList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entityrelations.EntityRelationsClient", "EntitiesRelationsList", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForEntitiesRelationsList prepares the EntitiesRelationsList request. -func (c EntityRelationsClient) preparerForEntitiesRelationsList(ctx context.Context, id EntityId, options EntitiesRelationsListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/relations", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForEntitiesRelationsListWithNextLink prepares the EntitiesRelationsList request with the given nextLink token. -func (c EntityRelationsClient) preparerForEntitiesRelationsListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForEntitiesRelationsList handles the response to the EntitiesRelationsList request. The method always -// closes the http.Response Body. -func (c EntityRelationsClient) responderForEntitiesRelationsList(resp *http.Response) (result EntitiesRelationsListOperationResponse, err error) { - type page struct { - Values []Relation `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result EntitiesRelationsListOperationResponse, err error) { - req, err := c.preparerForEntitiesRelationsListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "entityrelations.EntityRelationsClient", "EntitiesRelationsList", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entityrelations.EntityRelationsClient", "EntitiesRelationsList", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForEntitiesRelationsList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entityrelations.EntityRelationsClient", "EntitiesRelationsList", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// EntitiesRelationsListComplete retrieves all of the results into a single object -func (c EntityRelationsClient) EntitiesRelationsListComplete(ctx context.Context, id EntityId, options EntitiesRelationsListOperationOptions) (EntitiesRelationsListCompleteResult, error) { - return c.EntitiesRelationsListCompleteMatchingPredicate(ctx, id, options, RelationOperationPredicate{}) -} - -// EntitiesRelationsListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c EntityRelationsClient) EntitiesRelationsListCompleteMatchingPredicate(ctx context.Context, id EntityId, options EntitiesRelationsListOperationOptions, predicate RelationOperationPredicate) (resp EntitiesRelationsListCompleteResult, err error) { - items := make([]Relation, 0) - - page, err := c.EntitiesRelationsList(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := EntitiesRelationsListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/entityrelations/method_getrelation.go b/resource-manager/securityinsights/2022-07-01-preview/entityrelations/method_getrelation.go new file mode 100644 index 00000000000..e81337d733b --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/entityrelations/method_getrelation.go @@ -0,0 +1,51 @@ +package entityrelations + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetRelationOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Relation +} + +// GetRelation ... +func (c EntityRelationsClient) GetRelation(ctx context.Context, id RelationId) (result GetRelationOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/entityrelations/method_getrelation_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/entityrelations/method_getrelation_autorest.go deleted file mode 100644 index d400c162968..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/entityrelations/method_getrelation_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package entityrelations - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetRelationOperationResponse struct { - HttpResponse *http.Response - Model *Relation -} - -// GetRelation ... -func (c EntityRelationsClient) GetRelation(ctx context.Context, id RelationId) (result GetRelationOperationResponse, err error) { - req, err := c.preparerForGetRelation(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "entityrelations.EntityRelationsClient", "GetRelation", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entityrelations.EntityRelationsClient", "GetRelation", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGetRelation(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entityrelations.EntityRelationsClient", "GetRelation", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGetRelation prepares the GetRelation request. -func (c EntityRelationsClient) preparerForGetRelation(ctx context.Context, id RelationId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGetRelation handles the response to the GetRelation request. The method always -// closes the http.Response Body. -func (c EntityRelationsClient) responderForGetRelation(resp *http.Response) (result GetRelationOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/entitytypes/client.go b/resource-manager/securityinsights/2022-07-01-preview/entitytypes/client.go index 60583ea834f..bcdd09e4029 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/entitytypes/client.go +++ b/resource-manager/securityinsights/2022-07-01-preview/entitytypes/client.go @@ -1,18 +1,26 @@ package entitytypes -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type EntityTypesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewEntityTypesClientWithBaseURI(endpoint string) EntityTypesClient { - return EntityTypesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewEntityTypesClientWithBaseURI(sdkApi sdkEnv.Api) (*EntityTypesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "entitytypes", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating EntityTypesClient: %+v", err) } + + return &EntityTypesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-07-01-preview/entitytypes/constants.go b/resource-manager/securityinsights/2022-07-01-preview/entitytypes/constants.go index 92df052e0f7..83bedfbe6a8 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/entitytypes/constants.go +++ b/resource-manager/securityinsights/2022-07-01-preview/entitytypes/constants.go @@ -1,6 +1,10 @@ package entitytypes -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -23,6 +27,19 @@ func PossibleValuesForAlertSeverity() []string { } } +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertSeverity(input string) (*AlertSeverity, error) { vals := map[string]AlertSeverity{ "high": AlertSeverityHigh, @@ -59,6 +76,19 @@ func PossibleValuesForAlertStatus() []string { } } +func (s *AlertStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertStatus(input string) (*AlertStatus, error) { vals := map[string]AlertStatus{ "dismissed": AlertStatusDismissed, @@ -94,6 +124,19 @@ func PossibleValuesForAntispamMailDirection() []string { } } +func (s *AntispamMailDirection) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAntispamMailDirection(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAntispamMailDirection(input string) (*AntispamMailDirection, error) { vals := map[string]AntispamMailDirection{ "inbound": AntispamMailDirectionInbound, @@ -154,6 +197,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -199,6 +255,19 @@ func PossibleValuesForConfidenceLevel() []string { } } +func (s *ConfidenceLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceLevel(input string) (*ConfidenceLevel, error) { vals := map[string]ConfidenceLevel{ "high": ConfidenceLevelHigh, @@ -232,6 +301,19 @@ func PossibleValuesForConfidenceScoreStatus() []string { } } +func (s *ConfidenceScoreStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceScoreStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceScoreStatus(input string) (*ConfidenceScoreStatus, error) { vals := map[string]ConfidenceScoreStatus{ "final": ConfidenceScoreStatusFinal, @@ -266,6 +348,19 @@ func PossibleValuesForCreatedByType() []string { } } +func (s *CreatedByType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCreatedByType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseCreatedByType(input string) (*CreatedByType, error) { vals := map[string]CreatedByType{ "application": CreatedByTypeApplication, @@ -302,6 +397,19 @@ func PossibleValuesForDeliveryAction() []string { } } +func (s *DeliveryAction) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeliveryAction(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDeliveryAction(input string) (*DeliveryAction, error) { vals := map[string]DeliveryAction{ "blocked": DeliveryActionBlocked, @@ -347,6 +455,19 @@ func PossibleValuesForDeliveryLocation() []string { } } +func (s *DeliveryLocation) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeliveryLocation(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDeliveryLocation(input string) (*DeliveryLocation, error) { vals := map[string]DeliveryLocation{ "deletedfolder": DeliveryLocationDeletedFolder, @@ -386,6 +507,19 @@ func PossibleValuesForDeviceImportance() []string { } } +func (s *DeviceImportance) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeviceImportance(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDeviceImportance(input string) (*DeviceImportance, error) { vals := map[string]DeviceImportance{ "high": DeviceImportanceHigh, @@ -418,6 +552,19 @@ func PossibleValuesForElevationToken() []string { } } +func (s *ElevationToken) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseElevationToken(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseElevationToken(input string) (*ElevationToken, error) { vals := map[string]ElevationToken{ "default": ElevationTokenDefault, @@ -487,6 +634,19 @@ func PossibleValuesForEntityKind() []string { } } +func (s *EntityKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityKind(input string) (*EntityKind, error) { vals := map[string]EntityKind{ "account": EntityKindAccount, @@ -541,6 +701,19 @@ func PossibleValuesForFileHashAlgorithm() []string { } } +func (s *FileHashAlgorithm) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseFileHashAlgorithm(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseFileHashAlgorithm(input string) (*FileHashAlgorithm, error) { vals := map[string]FileHashAlgorithm{ "md5": FileHashAlgorithmMDFive, @@ -576,6 +749,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, @@ -630,6 +816,19 @@ func PossibleValuesForKillChainIntent() []string { } } +func (s *KillChainIntent) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKillChainIntent(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseKillChainIntent(input string) (*KillChainIntent, error) { vals := map[string]KillChainIntent{ "collection": KillChainIntentCollection, @@ -676,6 +875,19 @@ func PossibleValuesForOSFamily() []string { } } +func (s *OSFamily) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOSFamily(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseOSFamily(input string) (*OSFamily, error) { vals := map[string]OSFamily{ "android": OSFamilyAndroid, @@ -723,6 +935,19 @@ func PossibleValuesForRegistryHive() []string { } } +func (s *RegistryHive) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRegistryHive(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseRegistryHive(input string) (*RegistryHive, error) { vals := map[string]RegistryHive{ "hkey_a": RegistryHiveHKEYA, @@ -771,6 +996,19 @@ func PossibleValuesForRegistryValueKind() []string { } } +func (s *RegistryValueKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRegistryValueKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseRegistryValueKind(input string) (*RegistryValueKind, error) { vals := map[string]RegistryValueKind{ "binary": RegistryValueKindBinary, diff --git a/resource-manager/securityinsights/2022-07-01-preview/incidentalerts/client.go b/resource-manager/securityinsights/2022-07-01-preview/incidentalerts/client.go index ae19637d473..53dc2b4cd4e 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/incidentalerts/client.go +++ b/resource-manager/securityinsights/2022-07-01-preview/incidentalerts/client.go @@ -1,18 +1,26 @@ package incidentalerts -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type IncidentAlertsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewIncidentAlertsClientWithBaseURI(endpoint string) IncidentAlertsClient { - return IncidentAlertsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewIncidentAlertsClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentAlertsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidentalerts", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentAlertsClient: %+v", err) } + + return &IncidentAlertsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-07-01-preview/incidentalerts/constants.go b/resource-manager/securityinsights/2022-07-01-preview/incidentalerts/constants.go index 9f5d1a09992..5d286095967 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/incidentalerts/constants.go +++ b/resource-manager/securityinsights/2022-07-01-preview/incidentalerts/constants.go @@ -1,6 +1,10 @@ package incidentalerts -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -23,6 +27,19 @@ func PossibleValuesForAlertSeverity() []string { } } +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertSeverity(input string) (*AlertSeverity, error) { vals := map[string]AlertSeverity{ "high": AlertSeverityHigh, @@ -59,6 +76,19 @@ func PossibleValuesForAlertStatus() []string { } } +func (s *AlertStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertStatus(input string) (*AlertStatus, error) { vals := map[string]AlertStatus{ "dismissed": AlertStatusDismissed, @@ -120,6 +150,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -165,6 +208,19 @@ func PossibleValuesForConfidenceLevel() []string { } } +func (s *ConfidenceLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceLevel(input string) (*ConfidenceLevel, error) { vals := map[string]ConfidenceLevel{ "high": ConfidenceLevelHigh, @@ -198,6 +254,19 @@ func PossibleValuesForConfidenceScoreStatus() []string { } } +func (s *ConfidenceScoreStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceScoreStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceScoreStatus(input string) (*ConfidenceScoreStatus, error) { vals := map[string]ConfidenceScoreStatus{ "final": ConfidenceScoreStatusFinal, @@ -268,6 +337,19 @@ func PossibleValuesForEntityKind() []string { } } +func (s *EntityKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityKind(input string) (*EntityKind, error) { vals := map[string]EntityKind{ "account": EntityKindAccount, @@ -320,6 +402,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, @@ -374,6 +469,19 @@ func PossibleValuesForKillChainIntent() []string { } } +func (s *KillChainIntent) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKillChainIntent(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseKillChainIntent(input string) (*KillChainIntent, error) { vals := map[string]KillChainIntent{ "collection": KillChainIntentCollection, diff --git a/resource-manager/securityinsights/2022-07-01-preview/incidentalerts/method_incidentslistalerts.go b/resource-manager/securityinsights/2022-07-01-preview/incidentalerts/method_incidentslistalerts.go new file mode 100644 index 00000000000..fe83693eae2 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/incidentalerts/method_incidentslistalerts.go @@ -0,0 +1,52 @@ +package incidentalerts + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentsListAlertsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IncidentAlertList +} + +// IncidentsListAlerts ... +func (c IncidentAlertsClient) IncidentsListAlerts(ctx context.Context, id IncidentId) (result IncidentsListAlertsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/alerts", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/incidentalerts/method_incidentslistalerts_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/incidentalerts/method_incidentslistalerts_autorest.go deleted file mode 100644 index de6c08e09a2..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/incidentalerts/method_incidentslistalerts_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package incidentalerts - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IncidentsListAlertsOperationResponse struct { - HttpResponse *http.Response - Model *IncidentAlertList -} - -// IncidentsListAlerts ... -func (c IncidentAlertsClient) IncidentsListAlerts(ctx context.Context, id IncidentId) (result IncidentsListAlertsOperationResponse, err error) { - req, err := c.preparerForIncidentsListAlerts(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentalerts.IncidentAlertsClient", "IncidentsListAlerts", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentalerts.IncidentAlertsClient", "IncidentsListAlerts", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIncidentsListAlerts(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentalerts.IncidentAlertsClient", "IncidentsListAlerts", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIncidentsListAlerts prepares the IncidentsListAlerts request. -func (c IncidentAlertsClient) preparerForIncidentsListAlerts(ctx context.Context, id IncidentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/alerts", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIncidentsListAlerts handles the response to the IncidentsListAlerts request. The method always -// closes the http.Response Body. -func (c IncidentAlertsClient) responderForIncidentsListAlerts(resp *http.Response) (result IncidentsListAlertsOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/incidentbookmarks/client.go b/resource-manager/securityinsights/2022-07-01-preview/incidentbookmarks/client.go index e2fcca6728b..e6a60ede52d 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/incidentbookmarks/client.go +++ b/resource-manager/securityinsights/2022-07-01-preview/incidentbookmarks/client.go @@ -1,18 +1,26 @@ package incidentbookmarks -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type IncidentBookmarksClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewIncidentBookmarksClientWithBaseURI(endpoint string) IncidentBookmarksClient { - return IncidentBookmarksClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewIncidentBookmarksClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentBookmarksClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidentbookmarks", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentBookmarksClient: %+v", err) } + + return &IncidentBookmarksClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-07-01-preview/incidentbookmarks/constants.go b/resource-manager/securityinsights/2022-07-01-preview/incidentbookmarks/constants.go index 4f910b4f6bc..1731dc01ffe 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/incidentbookmarks/constants.go +++ b/resource-manager/securityinsights/2022-07-01-preview/incidentbookmarks/constants.go @@ -1,6 +1,10 @@ package incidentbookmarks -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -23,6 +27,19 @@ func PossibleValuesForAlertSeverity() []string { } } +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertSeverity(input string) (*AlertSeverity, error) { vals := map[string]AlertSeverity{ "high": AlertSeverityHigh, @@ -59,6 +76,19 @@ func PossibleValuesForAlertStatus() []string { } } +func (s *AlertStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertStatus(input string) (*AlertStatus, error) { vals := map[string]AlertStatus{ "dismissed": AlertStatusDismissed, @@ -120,6 +150,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -165,6 +208,19 @@ func PossibleValuesForConfidenceLevel() []string { } } +func (s *ConfidenceLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceLevel(input string) (*ConfidenceLevel, error) { vals := map[string]ConfidenceLevel{ "high": ConfidenceLevelHigh, @@ -198,6 +254,19 @@ func PossibleValuesForConfidenceScoreStatus() []string { } } +func (s *ConfidenceScoreStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceScoreStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceScoreStatus(input string) (*ConfidenceScoreStatus, error) { vals := map[string]ConfidenceScoreStatus{ "final": ConfidenceScoreStatusFinal, @@ -268,6 +337,19 @@ func PossibleValuesForEntityKind() []string { } } +func (s *EntityKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityKind(input string) (*EntityKind, error) { vals := map[string]EntityKind{ "account": EntityKindAccount, @@ -320,6 +402,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, @@ -374,6 +469,19 @@ func PossibleValuesForKillChainIntent() []string { } } +func (s *KillChainIntent) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKillChainIntent(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseKillChainIntent(input string) (*KillChainIntent, error) { vals := map[string]KillChainIntent{ "collection": KillChainIntentCollection, diff --git a/resource-manager/securityinsights/2022-07-01-preview/incidentbookmarks/method_incidentslistbookmarks.go b/resource-manager/securityinsights/2022-07-01-preview/incidentbookmarks/method_incidentslistbookmarks.go new file mode 100644 index 00000000000..3ac7b9e8b2e --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/incidentbookmarks/method_incidentslistbookmarks.go @@ -0,0 +1,52 @@ +package incidentbookmarks + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentsListBookmarksOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IncidentBookmarkList +} + +// IncidentsListBookmarks ... +func (c IncidentBookmarksClient) IncidentsListBookmarks(ctx context.Context, id IncidentId) (result IncidentsListBookmarksOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/bookmarks", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/incidentbookmarks/method_incidentslistbookmarks_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/incidentbookmarks/method_incidentslistbookmarks_autorest.go deleted file mode 100644 index a5c3a89a09c..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/incidentbookmarks/method_incidentslistbookmarks_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package incidentbookmarks - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IncidentsListBookmarksOperationResponse struct { - HttpResponse *http.Response - Model *IncidentBookmarkList -} - -// IncidentsListBookmarks ... -func (c IncidentBookmarksClient) IncidentsListBookmarks(ctx context.Context, id IncidentId) (result IncidentsListBookmarksOperationResponse, err error) { - req, err := c.preparerForIncidentsListBookmarks(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentbookmarks.IncidentBookmarksClient", "IncidentsListBookmarks", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentbookmarks.IncidentBookmarksClient", "IncidentsListBookmarks", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIncidentsListBookmarks(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentbookmarks.IncidentBookmarksClient", "IncidentsListBookmarks", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIncidentsListBookmarks prepares the IncidentsListBookmarks request. -func (c IncidentBookmarksClient) preparerForIncidentsListBookmarks(ctx context.Context, id IncidentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/bookmarks", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIncidentsListBookmarks handles the response to the IncidentsListBookmarks request. The method always -// closes the http.Response Body. -func (c IncidentBookmarksClient) responderForIncidentsListBookmarks(resp *http.Response) (result IncidentsListBookmarksOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/incidentcomments/client.go b/resource-manager/securityinsights/2022-07-01-preview/incidentcomments/client.go index 4006779247d..981e6f75216 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/incidentcomments/client.go +++ b/resource-manager/securityinsights/2022-07-01-preview/incidentcomments/client.go @@ -1,18 +1,26 @@ package incidentcomments -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type IncidentCommentsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewIncidentCommentsClientWithBaseURI(endpoint string) IncidentCommentsClient { - return IncidentCommentsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewIncidentCommentsClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentCommentsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidentcomments", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentCommentsClient: %+v", err) } + + return &IncidentCommentsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-07-01-preview/incidentcomments/method_createorupdate.go b/resource-manager/securityinsights/2022-07-01-preview/incidentcomments/method_createorupdate.go new file mode 100644 index 00000000000..5c59b2be8d3 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/incidentcomments/method_createorupdate.go @@ -0,0 +1,56 @@ +package incidentcomments + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IncidentComment +} + +// CreateOrUpdate ... +func (c IncidentCommentsClient) CreateOrUpdate(ctx context.Context, id CommentId, input IncidentComment) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/incidentcomments/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/incidentcomments/method_createorupdate_autorest.go deleted file mode 100644 index b27777aad2c..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/incidentcomments/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package incidentcomments - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *IncidentComment -} - -// CreateOrUpdate ... -func (c IncidentCommentsClient) CreateOrUpdate(ctx context.Context, id CommentId, input IncidentComment) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c IncidentCommentsClient) preparerForCreateOrUpdate(ctx context.Context, id CommentId, input IncidentComment) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c IncidentCommentsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/incidentcomments/method_delete.go b/resource-manager/securityinsights/2022-07-01-preview/incidentcomments/method_delete.go new file mode 100644 index 00000000000..78412a13e76 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/incidentcomments/method_delete.go @@ -0,0 +1,47 @@ +package incidentcomments + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c IncidentCommentsClient) Delete(ctx context.Context, id CommentId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/incidentcomments/method_delete_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/incidentcomments/method_delete_autorest.go deleted file mode 100644 index 6bbb4c92cbf..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/incidentcomments/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package incidentcomments - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c IncidentCommentsClient) Delete(ctx context.Context, id CommentId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c IncidentCommentsClient) preparerForDelete(ctx context.Context, id CommentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c IncidentCommentsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/incidentcomments/method_get.go b/resource-manager/securityinsights/2022-07-01-preview/incidentcomments/method_get.go new file mode 100644 index 00000000000..e8d11306ddb --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/incidentcomments/method_get.go @@ -0,0 +1,51 @@ +package incidentcomments + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IncidentComment +} + +// Get ... +func (c IncidentCommentsClient) Get(ctx context.Context, id CommentId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/incidentcomments/method_get_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/incidentcomments/method_get_autorest.go deleted file mode 100644 index 8402ed77e94..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/incidentcomments/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package incidentcomments - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *IncidentComment -} - -// Get ... -func (c IncidentCommentsClient) Get(ctx context.Context, id CommentId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c IncidentCommentsClient) preparerForGet(ctx context.Context, id CommentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c IncidentCommentsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/incidentcomments/method_list.go b/resource-manager/securityinsights/2022-07-01-preview/incidentcomments/method_list.go new file mode 100644 index 00000000000..b4c16058b38 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/incidentcomments/method_list.go @@ -0,0 +1,127 @@ +package incidentcomments + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]IncidentComment +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []IncidentComment +} + +type ListOperationOptions struct { + Filter *string + Orderby *string + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c IncidentCommentsClient) List(ctx context.Context, id IncidentId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/comments", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]IncidentComment `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c IncidentCommentsClient) ListComplete(ctx context.Context, id IncidentId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, IncidentCommentOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c IncidentCommentsClient) ListCompleteMatchingPredicate(ctx context.Context, id IncidentId, options ListOperationOptions, predicate IncidentCommentOperationPredicate) (result ListCompleteResult, err error) { + items := make([]IncidentComment, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/incidentcomments/method_list_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/incidentcomments/method_list_autorest.go deleted file mode 100644 index 24fb8d1d7e7..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/incidentcomments/method_list_autorest.go +++ /dev/null @@ -1,225 +0,0 @@ -package incidentcomments - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]IncidentComment - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []IncidentComment -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ListOperationOptions struct { - Filter *string - Orderby *string - Top *int64 -} - -func DefaultListOperationOptions() ListOperationOptions { - return ListOperationOptions{} -} - -func (o ListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Filter != nil { - out["$filter"] = *o.Filter - } - - if o.Orderby != nil { - out["$orderby"] = *o.Orderby - } - - if o.Top != nil { - out["$top"] = *o.Top - } - - return out -} - -// List ... -func (c IncidentCommentsClient) List(ctx context.Context, id IncidentId, options ListOperationOptions) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c IncidentCommentsClient) preparerForList(ctx context.Context, id IncidentId, options ListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/comments", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c IncidentCommentsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c IncidentCommentsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []IncidentComment `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c IncidentCommentsClient) ListComplete(ctx context.Context, id IncidentId, options ListOperationOptions) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, options, IncidentCommentOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c IncidentCommentsClient) ListCompleteMatchingPredicate(ctx context.Context, id IncidentId, options ListOperationOptions, predicate IncidentCommentOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]IncidentComment, 0) - - page, err := c.List(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/incidententities/client.go b/resource-manager/securityinsights/2022-07-01-preview/incidententities/client.go index 5f0eaf07782..740e7b81755 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/incidententities/client.go +++ b/resource-manager/securityinsights/2022-07-01-preview/incidententities/client.go @@ -1,18 +1,26 @@ package incidententities -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type IncidentEntitiesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewIncidentEntitiesClientWithBaseURI(endpoint string) IncidentEntitiesClient { - return IncidentEntitiesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewIncidentEntitiesClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentEntitiesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidententities", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentEntitiesClient: %+v", err) } + + return &IncidentEntitiesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-07-01-preview/incidententities/constants.go b/resource-manager/securityinsights/2022-07-01-preview/incidententities/constants.go index 53a786bdda5..996bca7e8dc 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/incidententities/constants.go +++ b/resource-manager/securityinsights/2022-07-01-preview/incidententities/constants.go @@ -1,6 +1,10 @@ package incidententities -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -23,6 +27,19 @@ func PossibleValuesForAlertSeverity() []string { } } +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertSeverity(input string) (*AlertSeverity, error) { vals := map[string]AlertSeverity{ "high": AlertSeverityHigh, @@ -59,6 +76,19 @@ func PossibleValuesForAlertStatus() []string { } } +func (s *AlertStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertStatus(input string) (*AlertStatus, error) { vals := map[string]AlertStatus{ "dismissed": AlertStatusDismissed, @@ -120,6 +150,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -165,6 +208,19 @@ func PossibleValuesForConfidenceLevel() []string { } } +func (s *ConfidenceLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceLevel(input string) (*ConfidenceLevel, error) { vals := map[string]ConfidenceLevel{ "high": ConfidenceLevelHigh, @@ -198,6 +254,19 @@ func PossibleValuesForConfidenceScoreStatus() []string { } } +func (s *ConfidenceScoreStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceScoreStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceScoreStatus(input string) (*ConfidenceScoreStatus, error) { vals := map[string]ConfidenceScoreStatus{ "final": ConfidenceScoreStatusFinal, @@ -268,6 +337,19 @@ func PossibleValuesForEntityKind() []string { } } +func (s *EntityKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityKind(input string) (*EntityKind, error) { vals := map[string]EntityKind{ "account": EntityKindAccount, @@ -320,6 +402,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, @@ -374,6 +469,19 @@ func PossibleValuesForKillChainIntent() []string { } } +func (s *KillChainIntent) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKillChainIntent(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseKillChainIntent(input string) (*KillChainIntent, error) { vals := map[string]KillChainIntent{ "collection": KillChainIntentCollection, diff --git a/resource-manager/securityinsights/2022-07-01-preview/incidententities/method_incidentslistentities.go b/resource-manager/securityinsights/2022-07-01-preview/incidententities/method_incidentslistentities.go new file mode 100644 index 00000000000..36ec8f0c75b --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/incidententities/method_incidentslistentities.go @@ -0,0 +1,52 @@ +package incidententities + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentsListEntitiesOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IncidentEntitiesResponse +} + +// IncidentsListEntities ... +func (c IncidentEntitiesClient) IncidentsListEntities(ctx context.Context, id IncidentId) (result IncidentsListEntitiesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/entities", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/incidententities/method_incidentslistentities_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/incidententities/method_incidentslistentities_autorest.go deleted file mode 100644 index 9d796d431cb..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/incidententities/method_incidentslistentities_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package incidententities - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IncidentsListEntitiesOperationResponse struct { - HttpResponse *http.Response - Model *IncidentEntitiesResponse -} - -// IncidentsListEntities ... -func (c IncidentEntitiesClient) IncidentsListEntities(ctx context.Context, id IncidentId) (result IncidentsListEntitiesOperationResponse, err error) { - req, err := c.preparerForIncidentsListEntities(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidententities.IncidentEntitiesClient", "IncidentsListEntities", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidententities.IncidentEntitiesClient", "IncidentsListEntities", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIncidentsListEntities(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidententities.IncidentEntitiesClient", "IncidentsListEntities", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIncidentsListEntities prepares the IncidentsListEntities request. -func (c IncidentEntitiesClient) preparerForIncidentsListEntities(ctx context.Context, id IncidentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/entities", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIncidentsListEntities handles the response to the IncidentsListEntities request. The method always -// closes the http.Response Body. -func (c IncidentEntitiesClient) responderForIncidentsListEntities(resp *http.Response) (result IncidentsListEntitiesOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/incidentrelations/client.go b/resource-manager/securityinsights/2022-07-01-preview/incidentrelations/client.go index 58aa27c43e8..4e8fbfeb71d 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/incidentrelations/client.go +++ b/resource-manager/securityinsights/2022-07-01-preview/incidentrelations/client.go @@ -1,18 +1,26 @@ package incidentrelations -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type IncidentRelationsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewIncidentRelationsClientWithBaseURI(endpoint string) IncidentRelationsClient { - return IncidentRelationsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewIncidentRelationsClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentRelationsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidentrelations", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentRelationsClient: %+v", err) } + + return &IncidentRelationsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-07-01-preview/incidentrelations/method_createorupdate.go b/resource-manager/securityinsights/2022-07-01-preview/incidentrelations/method_createorupdate.go new file mode 100644 index 00000000000..e87f1b4b752 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/incidentrelations/method_createorupdate.go @@ -0,0 +1,56 @@ +package incidentrelations + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Relation +} + +// CreateOrUpdate ... +func (c IncidentRelationsClient) CreateOrUpdate(ctx context.Context, id IncidentRelationId, input Relation) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/incidentrelations/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/incidentrelations/method_createorupdate_autorest.go deleted file mode 100644 index 26334017af9..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/incidentrelations/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package incidentrelations - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *Relation -} - -// CreateOrUpdate ... -func (c IncidentRelationsClient) CreateOrUpdate(ctx context.Context, id IncidentRelationId, input Relation) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c IncidentRelationsClient) preparerForCreateOrUpdate(ctx context.Context, id IncidentRelationId, input Relation) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c IncidentRelationsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/incidentrelations/method_delete.go b/resource-manager/securityinsights/2022-07-01-preview/incidentrelations/method_delete.go new file mode 100644 index 00000000000..7206ac26d08 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/incidentrelations/method_delete.go @@ -0,0 +1,47 @@ +package incidentrelations + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c IncidentRelationsClient) Delete(ctx context.Context, id IncidentRelationId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/incidentrelations/method_delete_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/incidentrelations/method_delete_autorest.go deleted file mode 100644 index d288fdf5e60..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/incidentrelations/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package incidentrelations - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c IncidentRelationsClient) Delete(ctx context.Context, id IncidentRelationId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c IncidentRelationsClient) preparerForDelete(ctx context.Context, id IncidentRelationId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c IncidentRelationsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/incidentrelations/method_get.go b/resource-manager/securityinsights/2022-07-01-preview/incidentrelations/method_get.go new file mode 100644 index 00000000000..a6e7333f2e6 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/incidentrelations/method_get.go @@ -0,0 +1,51 @@ +package incidentrelations + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Relation +} + +// Get ... +func (c IncidentRelationsClient) Get(ctx context.Context, id IncidentRelationId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/incidentrelations/method_get_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/incidentrelations/method_get_autorest.go deleted file mode 100644 index 4cb22a2ba53..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/incidentrelations/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package incidentrelations - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *Relation -} - -// Get ... -func (c IncidentRelationsClient) Get(ctx context.Context, id IncidentRelationId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c IncidentRelationsClient) preparerForGet(ctx context.Context, id IncidentRelationId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c IncidentRelationsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/incidentrelations/method_list.go b/resource-manager/securityinsights/2022-07-01-preview/incidentrelations/method_list.go new file mode 100644 index 00000000000..80873d441b4 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/incidentrelations/method_list.go @@ -0,0 +1,127 @@ +package incidentrelations + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Relation +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Relation +} + +type ListOperationOptions struct { + Filter *string + Orderby *string + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c IncidentRelationsClient) List(ctx context.Context, id IncidentId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/relations", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Relation `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c IncidentRelationsClient) ListComplete(ctx context.Context, id IncidentId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, RelationOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c IncidentRelationsClient) ListCompleteMatchingPredicate(ctx context.Context, id IncidentId, options ListOperationOptions, predicate RelationOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Relation, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/incidentrelations/method_list_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/incidentrelations/method_list_autorest.go deleted file mode 100644 index a270a442886..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/incidentrelations/method_list_autorest.go +++ /dev/null @@ -1,225 +0,0 @@ -package incidentrelations - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]Relation - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []Relation -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ListOperationOptions struct { - Filter *string - Orderby *string - Top *int64 -} - -func DefaultListOperationOptions() ListOperationOptions { - return ListOperationOptions{} -} - -func (o ListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Filter != nil { - out["$filter"] = *o.Filter - } - - if o.Orderby != nil { - out["$orderby"] = *o.Orderby - } - - if o.Top != nil { - out["$top"] = *o.Top - } - - return out -} - -// List ... -func (c IncidentRelationsClient) List(ctx context.Context, id IncidentId, options ListOperationOptions) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c IncidentRelationsClient) preparerForList(ctx context.Context, id IncidentId, options ListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/relations", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c IncidentRelationsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c IncidentRelationsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []Relation `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c IncidentRelationsClient) ListComplete(ctx context.Context, id IncidentId, options ListOperationOptions) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, options, RelationOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c IncidentRelationsClient) ListCompleteMatchingPredicate(ctx context.Context, id IncidentId, options ListOperationOptions, predicate RelationOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]Relation, 0) - - page, err := c.List(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/incidents/client.go b/resource-manager/securityinsights/2022-07-01-preview/incidents/client.go index 659897d18d7..aaf38071c39 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/incidents/client.go +++ b/resource-manager/securityinsights/2022-07-01-preview/incidents/client.go @@ -1,18 +1,26 @@ package incidents -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type IncidentsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewIncidentsClientWithBaseURI(endpoint string) IncidentsClient { - return IncidentsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewIncidentsClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidents", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentsClient: %+v", err) } + + return &IncidentsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-07-01-preview/incidents/constants.go b/resource-manager/securityinsights/2022-07-01-preview/incidents/constants.go index 82782d4107f..ce046b9edba 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/incidents/constants.go +++ b/resource-manager/securityinsights/2022-07-01-preview/incidents/constants.go @@ -1,6 +1,10 @@ package incidents -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -49,6 +53,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -96,6 +113,19 @@ func PossibleValuesForIncidentClassification() []string { } } +func (s *IncidentClassification) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentClassification(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentClassification(input string) (*IncidentClassification, error) { vals := map[string]IncidentClassification{ "benignpositive": IncidentClassificationBenignPositive, @@ -130,6 +160,19 @@ func PossibleValuesForIncidentClassificationReason() []string { } } +func (s *IncidentClassificationReason) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentClassificationReason(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentClassificationReason(input string) (*IncidentClassificationReason, error) { vals := map[string]IncidentClassificationReason{ "inaccuratedata": IncidentClassificationReasonInaccurateData, @@ -160,6 +203,19 @@ func PossibleValuesForIncidentLabelType() []string { } } +func (s *IncidentLabelType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentLabelType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentLabelType(input string) (*IncidentLabelType, error) { vals := map[string]IncidentLabelType{ "autoassigned": IncidentLabelTypeAutoAssigned, @@ -192,6 +248,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, @@ -224,6 +293,19 @@ func PossibleValuesForIncidentStatus() []string { } } +func (s *IncidentStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentStatus(input string) (*IncidentStatus, error) { vals := map[string]IncidentStatus{ "active": IncidentStatusActive, @@ -255,6 +337,19 @@ func PossibleValuesForOwnerType() []string { } } +func (s *OwnerType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOwnerType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseOwnerType(input string) (*OwnerType, error) { vals := map[string]OwnerType{ "group": OwnerTypeGroup, diff --git a/resource-manager/securityinsights/2022-07-01-preview/incidents/method_createorupdate.go b/resource-manager/securityinsights/2022-07-01-preview/incidents/method_createorupdate.go new file mode 100644 index 00000000000..3fcc110ed02 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/incidents/method_createorupdate.go @@ -0,0 +1,56 @@ +package incidents + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Incident +} + +// CreateOrUpdate ... +func (c IncidentsClient) CreateOrUpdate(ctx context.Context, id IncidentId, input Incident) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/incidents/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/incidents/method_createorupdate_autorest.go deleted file mode 100644 index 837aa7c92a0..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/incidents/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package incidents - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *Incident -} - -// CreateOrUpdate ... -func (c IncidentsClient) CreateOrUpdate(ctx context.Context, id IncidentId, input Incident) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c IncidentsClient) preparerForCreateOrUpdate(ctx context.Context, id IncidentId, input Incident) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c IncidentsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/incidents/method_delete.go b/resource-manager/securityinsights/2022-07-01-preview/incidents/method_delete.go new file mode 100644 index 00000000000..9b3205af5fc --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/incidents/method_delete.go @@ -0,0 +1,47 @@ +package incidents + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c IncidentsClient) Delete(ctx context.Context, id IncidentId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/incidents/method_delete_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/incidents/method_delete_autorest.go deleted file mode 100644 index 280832422f8..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/incidents/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package incidents - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c IncidentsClient) Delete(ctx context.Context, id IncidentId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c IncidentsClient) preparerForDelete(ctx context.Context, id IncidentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c IncidentsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/incidents/method_get.go b/resource-manager/securityinsights/2022-07-01-preview/incidents/method_get.go new file mode 100644 index 00000000000..e6d4e9e933b --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/incidents/method_get.go @@ -0,0 +1,51 @@ +package incidents + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Incident +} + +// Get ... +func (c IncidentsClient) Get(ctx context.Context, id IncidentId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/incidents/method_get_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/incidents/method_get_autorest.go deleted file mode 100644 index d8d2b7debeb..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/incidents/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package incidents - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *Incident -} - -// Get ... -func (c IncidentsClient) Get(ctx context.Context, id IncidentId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c IncidentsClient) preparerForGet(ctx context.Context, id IncidentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c IncidentsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/incidents/method_list.go b/resource-manager/securityinsights/2022-07-01-preview/incidents/method_list.go new file mode 100644 index 00000000000..fe19cd4d9ff --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/incidents/method_list.go @@ -0,0 +1,127 @@ +package incidents + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Incident +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Incident +} + +type ListOperationOptions struct { + Filter *string + Orderby *string + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c IncidentsClient) List(ctx context.Context, id WorkspaceId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/incidents", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Incident `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c IncidentsClient) ListComplete(ctx context.Context, id WorkspaceId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, IncidentOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c IncidentsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ListOperationOptions, predicate IncidentOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Incident, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/incidents/method_list_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/incidents/method_list_autorest.go deleted file mode 100644 index 8d2f5acc547..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/incidents/method_list_autorest.go +++ /dev/null @@ -1,225 +0,0 @@ -package incidents - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]Incident - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []Incident -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ListOperationOptions struct { - Filter *string - Orderby *string - Top *int64 -} - -func DefaultListOperationOptions() ListOperationOptions { - return ListOperationOptions{} -} - -func (o ListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Filter != nil { - out["$filter"] = *o.Filter - } - - if o.Orderby != nil { - out["$orderby"] = *o.Orderby - } - - if o.Top != nil { - out["$top"] = *o.Top - } - - return out -} - -// List ... -func (c IncidentsClient) List(ctx context.Context, id WorkspaceId, options ListOperationOptions) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c IncidentsClient) preparerForList(ctx context.Context, id WorkspaceId, options ListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/incidents", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c IncidentsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c IncidentsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []Incident `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c IncidentsClient) ListComplete(ctx context.Context, id WorkspaceId, options ListOperationOptions) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, options, IncidentOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c IncidentsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ListOperationOptions, predicate IncidentOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]Incident, 0) - - page, err := c.List(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/incidentteam/client.go b/resource-manager/securityinsights/2022-07-01-preview/incidentteam/client.go index c48730b50ab..75ab2cfb3b1 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/incidentteam/client.go +++ b/resource-manager/securityinsights/2022-07-01-preview/incidentteam/client.go @@ -1,18 +1,26 @@ package incidentteam -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type IncidentTeamClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewIncidentTeamClientWithBaseURI(endpoint string) IncidentTeamClient { - return IncidentTeamClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewIncidentTeamClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentTeamClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidentteam", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentTeamClient: %+v", err) } + + return &IncidentTeamClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-07-01-preview/incidentteam/method_incidentscreateteam.go b/resource-manager/securityinsights/2022-07-01-preview/incidentteam/method_incidentscreateteam.go new file mode 100644 index 00000000000..934052e83a4 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/incidentteam/method_incidentscreateteam.go @@ -0,0 +1,56 @@ +package incidentteam + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentsCreateTeamOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *TeamInformation +} + +// IncidentsCreateTeam ... +func (c IncidentTeamClient) IncidentsCreateTeam(ctx context.Context, id IncidentId, input TeamProperties) (result IncidentsCreateTeamOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/createTeam", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/incidentteam/method_incidentscreateteam_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/incidentteam/method_incidentscreateteam_autorest.go deleted file mode 100644 index 028fc51c6a2..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/incidentteam/method_incidentscreateteam_autorest.go +++ /dev/null @@ -1,70 +0,0 @@ -package incidentteam - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IncidentsCreateTeamOperationResponse struct { - HttpResponse *http.Response - Model *TeamInformation -} - -// IncidentsCreateTeam ... -func (c IncidentTeamClient) IncidentsCreateTeam(ctx context.Context, id IncidentId, input TeamProperties) (result IncidentsCreateTeamOperationResponse, err error) { - req, err := c.preparerForIncidentsCreateTeam(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentteam.IncidentTeamClient", "IncidentsCreateTeam", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentteam.IncidentTeamClient", "IncidentsCreateTeam", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIncidentsCreateTeam(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentteam.IncidentTeamClient", "IncidentsCreateTeam", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIncidentsCreateTeam prepares the IncidentsCreateTeam request. -func (c IncidentTeamClient) preparerForIncidentsCreateTeam(ctx context.Context, id IncidentId, input TeamProperties) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/createTeam", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIncidentsCreateTeam handles the response to the IncidentsCreateTeam request. The method always -// closes the http.Response Body. -func (c IncidentTeamClient) responderForIncidentsCreateTeam(resp *http.Response) (result IncidentsCreateTeamOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/manualtrigger/client.go b/resource-manager/securityinsights/2022-07-01-preview/manualtrigger/client.go index e34b6854084..da5817ede95 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/manualtrigger/client.go +++ b/resource-manager/securityinsights/2022-07-01-preview/manualtrigger/client.go @@ -1,18 +1,26 @@ package manualtrigger -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type ManualTriggerClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewManualTriggerClientWithBaseURI(endpoint string) ManualTriggerClient { - return ManualTriggerClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewManualTriggerClientWithBaseURI(sdkApi sdkEnv.Api) (*ManualTriggerClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "manualtrigger", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ManualTriggerClient: %+v", err) } + + return &ManualTriggerClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-07-01-preview/manualtrigger/method_incidentsrunplaybook.go b/resource-manager/securityinsights/2022-07-01-preview/manualtrigger/method_incidentsrunplaybook.go new file mode 100644 index 00000000000..5c95680f507 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/manualtrigger/method_incidentsrunplaybook.go @@ -0,0 +1,56 @@ +package manualtrigger + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentsRunPlaybookOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *interface{} +} + +// IncidentsRunPlaybook ... +func (c ManualTriggerClient) IncidentsRunPlaybook(ctx context.Context, id IncidentId, input ManualTriggerRequestBody) (result IncidentsRunPlaybookOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/runPlaybook", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/manualtrigger/method_incidentsrunplaybook_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/manualtrigger/method_incidentsrunplaybook_autorest.go deleted file mode 100644 index 2c7b4d5c710..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/manualtrigger/method_incidentsrunplaybook_autorest.go +++ /dev/null @@ -1,70 +0,0 @@ -package manualtrigger - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IncidentsRunPlaybookOperationResponse struct { - HttpResponse *http.Response - Model *interface{} -} - -// IncidentsRunPlaybook ... -func (c ManualTriggerClient) IncidentsRunPlaybook(ctx context.Context, id IncidentId, input ManualTriggerRequestBody) (result IncidentsRunPlaybookOperationResponse, err error) { - req, err := c.preparerForIncidentsRunPlaybook(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "manualtrigger.ManualTriggerClient", "IncidentsRunPlaybook", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "manualtrigger.ManualTriggerClient", "IncidentsRunPlaybook", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIncidentsRunPlaybook(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "manualtrigger.ManualTriggerClient", "IncidentsRunPlaybook", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIncidentsRunPlaybook prepares the IncidentsRunPlaybook request. -func (c ManualTriggerClient) preparerForIncidentsRunPlaybook(ctx context.Context, id IncidentId, input ManualTriggerRequestBody) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/runPlaybook", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIncidentsRunPlaybook handles the response to the IncidentsRunPlaybook request. The method always -// closes the http.Response Body. -func (c ManualTriggerClient) responderForIncidentsRunPlaybook(resp *http.Response) (result IncidentsRunPlaybookOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/metadata/client.go b/resource-manager/securityinsights/2022-07-01-preview/metadata/client.go index 05f0e7940c0..59e4192159f 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/metadata/client.go +++ b/resource-manager/securityinsights/2022-07-01-preview/metadata/client.go @@ -1,18 +1,26 @@ package metadata -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type MetadataClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewMetadataClientWithBaseURI(endpoint string) MetadataClient { - return MetadataClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewMetadataClientWithBaseURI(sdkApi sdkEnv.Api) (*MetadataClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "metadata", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating MetadataClient: %+v", err) } + + return &MetadataClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-07-01-preview/metadata/constants.go b/resource-manager/securityinsights/2022-07-01-preview/metadata/constants.go index d64c8db1b25..e1a5d1b92ff 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/metadata/constants.go +++ b/resource-manager/securityinsights/2022-07-01-preview/metadata/constants.go @@ -1,6 +1,10 @@ package metadata -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -49,6 +53,19 @@ func PossibleValuesForKind() []string { } } +func (s *Kind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseKind(input string) (*Kind, error) { vals := map[string]Kind{ "analyticsrule": KindAnalyticsRule, @@ -92,6 +109,19 @@ func PossibleValuesForOperator() []string { } } +func (s *Operator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseOperator(input string) (*Operator, error) { vals := map[string]Operator{ "and": OperatorAND, @@ -124,6 +154,19 @@ func PossibleValuesForSourceKind() []string { } } +func (s *SourceKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSourceKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSourceKind(input string) (*SourceKind, error) { vals := map[string]SourceKind{ "community": SourceKindCommunity, @@ -156,6 +199,19 @@ func PossibleValuesForSupportTier() []string { } } +func (s *SupportTier) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSupportTier(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSupportTier(input string) (*SupportTier, error) { vals := map[string]SupportTier{ "community": SupportTierCommunity, diff --git a/resource-manager/securityinsights/2022-07-01-preview/metadata/method_create.go b/resource-manager/securityinsights/2022-07-01-preview/metadata/method_create.go new file mode 100644 index 00000000000..36522e6397c --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/metadata/method_create.go @@ -0,0 +1,56 @@ +package metadata + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *MetadataModel +} + +// Create ... +func (c MetadataClient) Create(ctx context.Context, id MetadataId, input MetadataModel) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/metadata/method_create_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/metadata/method_create_autorest.go deleted file mode 100644 index 1ae47584687..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/metadata/method_create_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package metadata - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOperationResponse struct { - HttpResponse *http.Response - Model *MetadataModel -} - -// Create ... -func (c MetadataClient) Create(ctx context.Context, id MetadataId, input MetadataModel) (result CreateOperationResponse, err error) { - req, err := c.preparerForCreate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Create", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Create", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Create", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreate prepares the Create request. -func (c MetadataClient) preparerForCreate(ctx context.Context, id MetadataId, input MetadataModel) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreate handles the response to the Create request. The method always -// closes the http.Response Body. -func (c MetadataClient) responderForCreate(resp *http.Response) (result CreateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/metadata/method_delete.go b/resource-manager/securityinsights/2022-07-01-preview/metadata/method_delete.go new file mode 100644 index 00000000000..559f479cb03 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/metadata/method_delete.go @@ -0,0 +1,47 @@ +package metadata + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c MetadataClient) Delete(ctx context.Context, id MetadataId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/metadata/method_delete_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/metadata/method_delete_autorest.go deleted file mode 100644 index 3a151eefd21..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/metadata/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package metadata - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c MetadataClient) Delete(ctx context.Context, id MetadataId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c MetadataClient) preparerForDelete(ctx context.Context, id MetadataId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c MetadataClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/metadata/method_get.go b/resource-manager/securityinsights/2022-07-01-preview/metadata/method_get.go new file mode 100644 index 00000000000..a687bafec62 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/metadata/method_get.go @@ -0,0 +1,51 @@ +package metadata + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *MetadataModel +} + +// Get ... +func (c MetadataClient) Get(ctx context.Context, id MetadataId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/metadata/method_get_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/metadata/method_get_autorest.go deleted file mode 100644 index 25827d74702..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/metadata/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package metadata - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *MetadataModel -} - -// Get ... -func (c MetadataClient) Get(ctx context.Context, id MetadataId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c MetadataClient) preparerForGet(ctx context.Context, id MetadataId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c MetadataClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/metadata/method_list.go b/resource-manager/securityinsights/2022-07-01-preview/metadata/method_list.go new file mode 100644 index 00000000000..58267143629 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/metadata/method_list.go @@ -0,0 +1,131 @@ +package metadata + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]MetadataModel +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []MetadataModel +} + +type ListOperationOptions struct { + Filter *string + Orderby *string + Skip *int64 + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c MetadataClient) List(ctx context.Context, id WorkspaceId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/metadata", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]MetadataModel `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c MetadataClient) ListComplete(ctx context.Context, id WorkspaceId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, MetadataModelOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c MetadataClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ListOperationOptions, predicate MetadataModelOperationPredicate) (result ListCompleteResult, err error) { + items := make([]MetadataModel, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/metadata/method_list_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/metadata/method_list_autorest.go deleted file mode 100644 index e5f025d62ee..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/metadata/method_list_autorest.go +++ /dev/null @@ -1,230 +0,0 @@ -package metadata - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]MetadataModel - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []MetadataModel -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ListOperationOptions struct { - Filter *string - Orderby *string - Skip *int64 - Top *int64 -} - -func DefaultListOperationOptions() ListOperationOptions { - return ListOperationOptions{} -} - -func (o ListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Filter != nil { - out["$filter"] = *o.Filter - } - - if o.Orderby != nil { - out["$orderby"] = *o.Orderby - } - - if o.Skip != nil { - out["$skip"] = *o.Skip - } - - if o.Top != nil { - out["$top"] = *o.Top - } - - return out -} - -// List ... -func (c MetadataClient) List(ctx context.Context, id WorkspaceId, options ListOperationOptions) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c MetadataClient) preparerForList(ctx context.Context, id WorkspaceId, options ListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/metadata", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c MetadataClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c MetadataClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []MetadataModel `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c MetadataClient) ListComplete(ctx context.Context, id WorkspaceId, options ListOperationOptions) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, options, MetadataModelOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c MetadataClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ListOperationOptions, predicate MetadataModelOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]MetadataModel, 0) - - page, err := c.List(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/metadata/method_update.go b/resource-manager/securityinsights/2022-07-01-preview/metadata/method_update.go new file mode 100644 index 00000000000..47f777cee27 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/metadata/method_update.go @@ -0,0 +1,55 @@ +package metadata + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *MetadataModel +} + +// Update ... +func (c MetadataClient) Update(ctx context.Context, id MetadataId, input MetadataPatch) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/metadata/method_update_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/metadata/method_update_autorest.go deleted file mode 100644 index a4bd18d08d6..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/metadata/method_update_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package metadata - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type UpdateOperationResponse struct { - HttpResponse *http.Response - Model *MetadataModel -} - -// Update ... -func (c MetadataClient) Update(ctx context.Context, id MetadataId, input MetadataPatch) (result UpdateOperationResponse, err error) { - req, err := c.preparerForUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Update", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Update", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Update", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForUpdate prepares the Update request. -func (c MetadataClient) preparerForUpdate(ctx context.Context, id MetadataId, input MetadataPatch) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPatch(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForUpdate handles the response to the Update request. The method always -// closes the http.Response Body. -func (c MetadataClient) responderForUpdate(resp *http.Response) (result UpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/officeconsents/client.go b/resource-manager/securityinsights/2022-07-01-preview/officeconsents/client.go index 7f0466f7160..2c2efc37d3d 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/officeconsents/client.go +++ b/resource-manager/securityinsights/2022-07-01-preview/officeconsents/client.go @@ -1,18 +1,26 @@ package officeconsents -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type OfficeConsentsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewOfficeConsentsClientWithBaseURI(endpoint string) OfficeConsentsClient { - return OfficeConsentsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewOfficeConsentsClientWithBaseURI(sdkApi sdkEnv.Api) (*OfficeConsentsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "officeconsents", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating OfficeConsentsClient: %+v", err) } + + return &OfficeConsentsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-07-01-preview/officeconsents/method_delete.go b/resource-manager/securityinsights/2022-07-01-preview/officeconsents/method_delete.go new file mode 100644 index 00000000000..3c098e73784 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/officeconsents/method_delete.go @@ -0,0 +1,47 @@ +package officeconsents + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c OfficeConsentsClient) Delete(ctx context.Context, id OfficeConsentId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/officeconsents/method_delete_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/officeconsents/method_delete_autorest.go deleted file mode 100644 index 231f4a35afd..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/officeconsents/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package officeconsents - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c OfficeConsentsClient) Delete(ctx context.Context, id OfficeConsentId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "officeconsents.OfficeConsentsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "officeconsents.OfficeConsentsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "officeconsents.OfficeConsentsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c OfficeConsentsClient) preparerForDelete(ctx context.Context, id OfficeConsentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c OfficeConsentsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/officeconsents/method_get.go b/resource-manager/securityinsights/2022-07-01-preview/officeconsents/method_get.go new file mode 100644 index 00000000000..4d81ae6bf20 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/officeconsents/method_get.go @@ -0,0 +1,51 @@ +package officeconsents + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *OfficeConsent +} + +// Get ... +func (c OfficeConsentsClient) Get(ctx context.Context, id OfficeConsentId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/officeconsents/method_get_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/officeconsents/method_get_autorest.go deleted file mode 100644 index bb10097614d..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/officeconsents/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package officeconsents - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *OfficeConsent -} - -// Get ... -func (c OfficeConsentsClient) Get(ctx context.Context, id OfficeConsentId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "officeconsents.OfficeConsentsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "officeconsents.OfficeConsentsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "officeconsents.OfficeConsentsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c OfficeConsentsClient) preparerForGet(ctx context.Context, id OfficeConsentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c OfficeConsentsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/officeconsents/method_list.go b/resource-manager/securityinsights/2022-07-01-preview/officeconsents/method_list.go new file mode 100644 index 00000000000..e23bd7dddfb --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/officeconsents/method_list.go @@ -0,0 +1,91 @@ +package officeconsents + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]OfficeConsent +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []OfficeConsent +} + +// List ... +func (c OfficeConsentsClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/officeConsents", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]OfficeConsent `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c OfficeConsentsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, OfficeConsentOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c OfficeConsentsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate OfficeConsentOperationPredicate) (result ListCompleteResult, err error) { + items := make([]OfficeConsent, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/officeconsents/method_list_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/officeconsents/method_list_autorest.go deleted file mode 100644 index d306e76d443..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/officeconsents/method_list_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package officeconsents - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]OfficeConsent - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []OfficeConsent -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c OfficeConsentsClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "officeconsents.OfficeConsentsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "officeconsents.OfficeConsentsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "officeconsents.OfficeConsentsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c OfficeConsentsClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/officeConsents", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c OfficeConsentsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c OfficeConsentsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []OfficeConsent `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "officeconsents.OfficeConsentsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "officeconsents.OfficeConsentsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "officeconsents.OfficeConsentsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c OfficeConsentsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, OfficeConsentOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c OfficeConsentsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate OfficeConsentOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]OfficeConsent, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/repositories/client.go b/resource-manager/securityinsights/2022-07-01-preview/repositories/client.go index 562953712b0..62b7be88387 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/repositories/client.go +++ b/resource-manager/securityinsights/2022-07-01-preview/repositories/client.go @@ -1,18 +1,26 @@ package repositories -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type RepositoriesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewRepositoriesClientWithBaseURI(endpoint string) RepositoriesClient { - return RepositoriesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewRepositoriesClientWithBaseURI(sdkApi sdkEnv.Api) (*RepositoriesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "repositories", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating RepositoriesClient: %+v", err) } + + return &RepositoriesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-07-01-preview/repositories/constants.go b/resource-manager/securityinsights/2022-07-01-preview/repositories/constants.go index b8d5b729aae..828121b73be 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/repositories/constants.go +++ b/resource-manager/securityinsights/2022-07-01-preview/repositories/constants.go @@ -1,6 +1,10 @@ package repositories -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -19,6 +23,19 @@ func PossibleValuesForRepoType() []string { } } +func (s *RepoType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRepoType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseRepoType(input string) (*RepoType, error) { vals := map[string]RepoType{ "devops": RepoTypeDevOps, diff --git a/resource-manager/securityinsights/2022-07-01-preview/repositories/method_sourcecontrollistrepositories.go b/resource-manager/securityinsights/2022-07-01-preview/repositories/method_sourcecontrollistrepositories.go new file mode 100644 index 00000000000..3a007266273 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/repositories/method_sourcecontrollistrepositories.go @@ -0,0 +1,91 @@ +package repositories + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SourceControllistRepositoriesOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Repo +} + +type SourceControllistRepositoriesCompleteResult struct { + LatestHttpResponse *http.Response + Items []Repo +} + +// SourceControllistRepositories ... +func (c RepositoriesClient) SourceControllistRepositories(ctx context.Context, id WorkspaceId, input RepoType) (result SourceControllistRepositoriesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/listRepositories", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Repo `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// SourceControllistRepositoriesComplete retrieves all the results into a single object +func (c RepositoriesClient) SourceControllistRepositoriesComplete(ctx context.Context, id WorkspaceId, input RepoType) (SourceControllistRepositoriesCompleteResult, error) { + return c.SourceControllistRepositoriesCompleteMatchingPredicate(ctx, id, input, RepoOperationPredicate{}) +} + +// SourceControllistRepositoriesCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c RepositoriesClient) SourceControllistRepositoriesCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, input RepoType, predicate RepoOperationPredicate) (result SourceControllistRepositoriesCompleteResult, err error) { + items := make([]Repo, 0) + + resp, err := c.SourceControllistRepositories(ctx, id, input) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = SourceControllistRepositoriesCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/repositories/method_sourcecontrollistrepositories_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/repositories/method_sourcecontrollistrepositories_autorest.go deleted file mode 100644 index 1bbe7743728..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/repositories/method_sourcecontrollistrepositories_autorest.go +++ /dev/null @@ -1,187 +0,0 @@ -package repositories - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type SourceControllistRepositoriesOperationResponse struct { - HttpResponse *http.Response - Model *[]Repo - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (SourceControllistRepositoriesOperationResponse, error) -} - -type SourceControllistRepositoriesCompleteResult struct { - Items []Repo -} - -func (r SourceControllistRepositoriesOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r SourceControllistRepositoriesOperationResponse) LoadMore(ctx context.Context) (resp SourceControllistRepositoriesOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// SourceControllistRepositories ... -func (c RepositoriesClient) SourceControllistRepositories(ctx context.Context, id WorkspaceId, input RepoType) (resp SourceControllistRepositoriesOperationResponse, err error) { - req, err := c.preparerForSourceControllistRepositories(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "repositories.RepositoriesClient", "SourceControllistRepositories", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "repositories.RepositoriesClient", "SourceControllistRepositories", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForSourceControllistRepositories(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "repositories.RepositoriesClient", "SourceControllistRepositories", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForSourceControllistRepositories prepares the SourceControllistRepositories request. -func (c RepositoriesClient) preparerForSourceControllistRepositories(ctx context.Context, id WorkspaceId, input RepoType) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/listRepositories", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForSourceControllistRepositoriesWithNextLink prepares the SourceControllistRepositories request with the given nextLink token. -func (c RepositoriesClient) preparerForSourceControllistRepositoriesWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForSourceControllistRepositories handles the response to the SourceControllistRepositories request. The method always -// closes the http.Response Body. -func (c RepositoriesClient) responderForSourceControllistRepositories(resp *http.Response) (result SourceControllistRepositoriesOperationResponse, err error) { - type page struct { - Values []Repo `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result SourceControllistRepositoriesOperationResponse, err error) { - req, err := c.preparerForSourceControllistRepositoriesWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "repositories.RepositoriesClient", "SourceControllistRepositories", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "repositories.RepositoriesClient", "SourceControllistRepositories", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForSourceControllistRepositories(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "repositories.RepositoriesClient", "SourceControllistRepositories", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// SourceControllistRepositoriesComplete retrieves all of the results into a single object -func (c RepositoriesClient) SourceControllistRepositoriesComplete(ctx context.Context, id WorkspaceId, input RepoType) (SourceControllistRepositoriesCompleteResult, error) { - return c.SourceControllistRepositoriesCompleteMatchingPredicate(ctx, id, input, RepoOperationPredicate{}) -} - -// SourceControllistRepositoriesCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c RepositoriesClient) SourceControllistRepositoriesCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, input RepoType, predicate RepoOperationPredicate) (resp SourceControllistRepositoriesCompleteResult, err error) { - items := make([]Repo, 0) - - page, err := c.SourceControllistRepositories(ctx, id, input) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := SourceControllistRepositoriesCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/securitymlanalyticssettings/client.go b/resource-manager/securityinsights/2022-07-01-preview/securitymlanalyticssettings/client.go index 50d64fb429c..65b248a41f5 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/securitymlanalyticssettings/client.go +++ b/resource-manager/securityinsights/2022-07-01-preview/securitymlanalyticssettings/client.go @@ -1,18 +1,26 @@ package securitymlanalyticssettings -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type SecurityMLAnalyticsSettingsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewSecurityMLAnalyticsSettingsClientWithBaseURI(endpoint string) SecurityMLAnalyticsSettingsClient { - return SecurityMLAnalyticsSettingsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewSecurityMLAnalyticsSettingsClientWithBaseURI(sdkApi sdkEnv.Api) (*SecurityMLAnalyticsSettingsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "securitymlanalyticssettings", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SecurityMLAnalyticsSettingsClient: %+v", err) } + + return &SecurityMLAnalyticsSettingsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-07-01-preview/securitymlanalyticssettings/constants.go b/resource-manager/securityinsights/2022-07-01-preview/securitymlanalyticssettings/constants.go index 47b13b875e2..e32d4d9875f 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/securitymlanalyticssettings/constants.go +++ b/resource-manager/securityinsights/2022-07-01-preview/securitymlanalyticssettings/constants.go @@ -1,6 +1,10 @@ package securitymlanalyticssettings -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -49,6 +53,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -90,6 +107,19 @@ func PossibleValuesForSecurityMLAnalyticsSettingsKind() []string { } } +func (s *SecurityMLAnalyticsSettingsKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSecurityMLAnalyticsSettingsKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSecurityMLAnalyticsSettingsKind(input string) (*SecurityMLAnalyticsSettingsKind, error) { vals := map[string]SecurityMLAnalyticsSettingsKind{ "anomaly": SecurityMLAnalyticsSettingsKindAnomaly, @@ -117,6 +147,19 @@ func PossibleValuesForSettingsStatus() []string { } } +func (s *SettingsStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSettingsStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSettingsStatus(input string) (*SettingsStatus, error) { vals := map[string]SettingsStatus{ "flighting": SettingsStatusFlighting, diff --git a/resource-manager/securityinsights/2022-07-01-preview/securitymlanalyticssettings/method_createorupdate.go b/resource-manager/securityinsights/2022-07-01-preview/securitymlanalyticssettings/method_createorupdate.go new file mode 100644 index 00000000000..f08267b7fac --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/securitymlanalyticssettings/method_createorupdate.go @@ -0,0 +1,63 @@ +package securitymlanalyticssettings + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SecurityMLAnalyticsSetting +} + +// CreateOrUpdate ... +func (c SecurityMLAnalyticsSettingsClient) CreateOrUpdate(ctx context.Context, id SecurityMLAnalyticsSettingId, input SecurityMLAnalyticsSetting) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalSecurityMLAnalyticsSettingImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/securitymlanalyticssettings/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/securitymlanalyticssettings/method_createorupdate_autorest.go deleted file mode 100644 index e72d9bcb79b..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/securitymlanalyticssettings/method_createorupdate_autorest.go +++ /dev/null @@ -1,78 +0,0 @@ -package securitymlanalyticssettings - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *SecurityMLAnalyticsSetting -} - -// CreateOrUpdate ... -func (c SecurityMLAnalyticsSettingsClient) CreateOrUpdate(ctx context.Context, id SecurityMLAnalyticsSettingId, input SecurityMLAnalyticsSetting) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c SecurityMLAnalyticsSettingsClient) preparerForCreateOrUpdate(ctx context.Context, id SecurityMLAnalyticsSettingId, input SecurityMLAnalyticsSetting) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c SecurityMLAnalyticsSettingsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalSecurityMLAnalyticsSettingImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/securitymlanalyticssettings/method_delete.go b/resource-manager/securityinsights/2022-07-01-preview/securitymlanalyticssettings/method_delete.go new file mode 100644 index 00000000000..36309ecb138 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/securitymlanalyticssettings/method_delete.go @@ -0,0 +1,47 @@ +package securitymlanalyticssettings + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c SecurityMLAnalyticsSettingsClient) Delete(ctx context.Context, id SecurityMLAnalyticsSettingId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/securitymlanalyticssettings/method_delete_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/securitymlanalyticssettings/method_delete_autorest.go deleted file mode 100644 index a2b0d18f72f..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/securitymlanalyticssettings/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package securitymlanalyticssettings - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c SecurityMLAnalyticsSettingsClient) Delete(ctx context.Context, id SecurityMLAnalyticsSettingId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c SecurityMLAnalyticsSettingsClient) preparerForDelete(ctx context.Context, id SecurityMLAnalyticsSettingId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c SecurityMLAnalyticsSettingsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/securitymlanalyticssettings/method_get.go b/resource-manager/securityinsights/2022-07-01-preview/securitymlanalyticssettings/method_get.go new file mode 100644 index 00000000000..9be89fdf974 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/securitymlanalyticssettings/method_get.go @@ -0,0 +1,58 @@ +package securitymlanalyticssettings + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SecurityMLAnalyticsSetting +} + +// Get ... +func (c SecurityMLAnalyticsSettingsClient) Get(ctx context.Context, id SecurityMLAnalyticsSettingId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalSecurityMLAnalyticsSettingImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/securitymlanalyticssettings/method_get_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/securitymlanalyticssettings/method_get_autorest.go deleted file mode 100644 index 0157220a0eb..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/securitymlanalyticssettings/method_get_autorest.go +++ /dev/null @@ -1,77 +0,0 @@ -package securitymlanalyticssettings - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *SecurityMLAnalyticsSetting -} - -// Get ... -func (c SecurityMLAnalyticsSettingsClient) Get(ctx context.Context, id SecurityMLAnalyticsSettingId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c SecurityMLAnalyticsSettingsClient) preparerForGet(ctx context.Context, id SecurityMLAnalyticsSettingId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c SecurityMLAnalyticsSettingsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalSecurityMLAnalyticsSettingImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/securitymlanalyticssettings/method_list.go b/resource-manager/securityinsights/2022-07-01-preview/securitymlanalyticssettings/method_list.go new file mode 100644 index 00000000000..49878345af3 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/securitymlanalyticssettings/method_list.go @@ -0,0 +1,103 @@ +package securitymlanalyticssettings + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SecurityMLAnalyticsSetting +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []SecurityMLAnalyticsSetting +} + +// List ... +func (c SecurityMLAnalyticsSettingsClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/securityMLAnalyticsSettings", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]SecurityMLAnalyticsSetting, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalSecurityMLAnalyticsSettingImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for SecurityMLAnalyticsSetting (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// ListComplete retrieves all the results into a single object +func (c SecurityMLAnalyticsSettingsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, SecurityMLAnalyticsSettingOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SecurityMLAnalyticsSettingsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate SecurityMLAnalyticsSettingOperationPredicate) (result ListCompleteResult, err error) { + items := make([]SecurityMLAnalyticsSetting, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/securitymlanalyticssettings/method_list_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/securitymlanalyticssettings/method_list_autorest.go deleted file mode 100644 index 127297aa869..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/securitymlanalyticssettings/method_list_autorest.go +++ /dev/null @@ -1,196 +0,0 @@ -package securitymlanalyticssettings - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]SecurityMLAnalyticsSetting - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []SecurityMLAnalyticsSetting -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c SecurityMLAnalyticsSettingsClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c SecurityMLAnalyticsSettingsClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/securityMLAnalyticsSettings", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c SecurityMLAnalyticsSettingsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c SecurityMLAnalyticsSettingsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]SecurityMLAnalyticsSetting, 0) - for i, v := range respObj.Values { - val, err := unmarshalSecurityMLAnalyticsSettingImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for SecurityMLAnalyticsSetting (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c SecurityMLAnalyticsSettingsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, SecurityMLAnalyticsSettingOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c SecurityMLAnalyticsSettingsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate SecurityMLAnalyticsSettingOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]SecurityMLAnalyticsSetting, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/sentinelonboardingstates/client.go b/resource-manager/securityinsights/2022-07-01-preview/sentinelonboardingstates/client.go index 0ae442ba3fa..94701ed853a 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/sentinelonboardingstates/client.go +++ b/resource-manager/securityinsights/2022-07-01-preview/sentinelonboardingstates/client.go @@ -1,18 +1,26 @@ package sentinelonboardingstates -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type SentinelOnboardingStatesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewSentinelOnboardingStatesClientWithBaseURI(endpoint string) SentinelOnboardingStatesClient { - return SentinelOnboardingStatesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewSentinelOnboardingStatesClientWithBaseURI(sdkApi sdkEnv.Api) (*SentinelOnboardingStatesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sentinelonboardingstates", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SentinelOnboardingStatesClient: %+v", err) } + + return &SentinelOnboardingStatesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-07-01-preview/sentinelonboardingstates/method_create.go b/resource-manager/securityinsights/2022-07-01-preview/sentinelonboardingstates/method_create.go new file mode 100644 index 00000000000..af163a9d66b --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/sentinelonboardingstates/method_create.go @@ -0,0 +1,56 @@ +package sentinelonboardingstates + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SentinelOnboardingState +} + +// Create ... +func (c SentinelOnboardingStatesClient) Create(ctx context.Context, id OnboardingStateId, input SentinelOnboardingState) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/sentinelonboardingstates/method_create_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/sentinelonboardingstates/method_create_autorest.go deleted file mode 100644 index 9ad88e95157..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/sentinelonboardingstates/method_create_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package sentinelonboardingstates - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOperationResponse struct { - HttpResponse *http.Response - Model *SentinelOnboardingState -} - -// Create ... -func (c SentinelOnboardingStatesClient) Create(ctx context.Context, id OnboardingStateId, input SentinelOnboardingState) (result CreateOperationResponse, err error) { - req, err := c.preparerForCreate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Create", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Create", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Create", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreate prepares the Create request. -func (c SentinelOnboardingStatesClient) preparerForCreate(ctx context.Context, id OnboardingStateId, input SentinelOnboardingState) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreate handles the response to the Create request. The method always -// closes the http.Response Body. -func (c SentinelOnboardingStatesClient) responderForCreate(resp *http.Response) (result CreateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/sentinelonboardingstates/method_delete.go b/resource-manager/securityinsights/2022-07-01-preview/sentinelonboardingstates/method_delete.go new file mode 100644 index 00000000000..1c6c5e372d7 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/sentinelonboardingstates/method_delete.go @@ -0,0 +1,47 @@ +package sentinelonboardingstates + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c SentinelOnboardingStatesClient) Delete(ctx context.Context, id OnboardingStateId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/sentinelonboardingstates/method_delete_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/sentinelonboardingstates/method_delete_autorest.go deleted file mode 100644 index 65fa74282f7..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/sentinelonboardingstates/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package sentinelonboardingstates - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c SentinelOnboardingStatesClient) Delete(ctx context.Context, id OnboardingStateId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c SentinelOnboardingStatesClient) preparerForDelete(ctx context.Context, id OnboardingStateId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c SentinelOnboardingStatesClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/sentinelonboardingstates/method_get.go b/resource-manager/securityinsights/2022-07-01-preview/sentinelonboardingstates/method_get.go new file mode 100644 index 00000000000..82165662910 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/sentinelonboardingstates/method_get.go @@ -0,0 +1,51 @@ +package sentinelonboardingstates + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SentinelOnboardingState +} + +// Get ... +func (c SentinelOnboardingStatesClient) Get(ctx context.Context, id OnboardingStateId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/sentinelonboardingstates/method_get_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/sentinelonboardingstates/method_get_autorest.go deleted file mode 100644 index d6174a7522a..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/sentinelonboardingstates/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package sentinelonboardingstates - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *SentinelOnboardingState -} - -// Get ... -func (c SentinelOnboardingStatesClient) Get(ctx context.Context, id OnboardingStateId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c SentinelOnboardingStatesClient) preparerForGet(ctx context.Context, id OnboardingStateId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c SentinelOnboardingStatesClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/sentinelonboardingstates/method_list.go b/resource-manager/securityinsights/2022-07-01-preview/sentinelonboardingstates/method_list.go new file mode 100644 index 00000000000..2efd1d41230 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/sentinelonboardingstates/method_list.go @@ -0,0 +1,52 @@ +package sentinelonboardingstates + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SentinelOnboardingStatesList +} + +// List ... +func (c SentinelOnboardingStatesClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/onboardingStates", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/sentinelonboardingstates/method_list_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/sentinelonboardingstates/method_list_autorest.go deleted file mode 100644 index 6a00bb3d3fd..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/sentinelonboardingstates/method_list_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package sentinelonboardingstates - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *SentinelOnboardingStatesList -} - -// List ... -func (c SentinelOnboardingStatesClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForList prepares the List request. -func (c SentinelOnboardingStatesClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/onboardingStates", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c SentinelOnboardingStatesClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/settings/client.go b/resource-manager/securityinsights/2022-07-01-preview/settings/client.go index fe7a909262c..7a9bd9ec8a1 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/settings/client.go +++ b/resource-manager/securityinsights/2022-07-01-preview/settings/client.go @@ -1,18 +1,26 @@ package settings -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type SettingsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewSettingsClientWithBaseURI(endpoint string) SettingsClient { - return SettingsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewSettingsClientWithBaseURI(sdkApi sdkEnv.Api) (*SettingsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "settings", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SettingsClient: %+v", err) } + + return &SettingsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-07-01-preview/settings/constants.go b/resource-manager/securityinsights/2022-07-01-preview/settings/constants.go index c3028cb8436..22f9ec6323d 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/settings/constants.go +++ b/resource-manager/securityinsights/2022-07-01-preview/settings/constants.go @@ -1,6 +1,10 @@ package settings -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -19,6 +23,19 @@ func PossibleValuesForEntityProviders() []string { } } +func (s *EntityProviders) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityProviders(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityProviders(input string) (*EntityProviders, error) { vals := map[string]EntityProviders{ "activedirectory": EntityProvidersActiveDirectory, @@ -51,6 +68,19 @@ func PossibleValuesForSettingKind() []string { } } +func (s *SettingKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSettingKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSettingKind(input string) (*SettingKind, error) { vals := map[string]SettingKind{ "anomalies": SettingKindAnomalies, @@ -85,6 +115,19 @@ func PossibleValuesForUebaDataSources() []string { } } +func (s *UebaDataSources) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseUebaDataSources(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseUebaDataSources(input string) (*UebaDataSources, error) { vals := map[string]UebaDataSources{ "auditlogs": UebaDataSourcesAuditLogs, diff --git a/resource-manager/securityinsights/2022-07-01-preview/settings/method_productsettingsdelete.go b/resource-manager/securityinsights/2022-07-01-preview/settings/method_productsettingsdelete.go new file mode 100644 index 00000000000..3306b03a761 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/settings/method_productsettingsdelete.go @@ -0,0 +1,47 @@ +package settings + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProductSettingsDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// ProductSettingsDelete ... +func (c SettingsClient) ProductSettingsDelete(ctx context.Context, id SettingId) (result ProductSettingsDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/settings/method_productsettingsdelete_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/settings/method_productsettingsdelete_autorest.go deleted file mode 100644 index 820be252b48..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/settings/method_productsettingsdelete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package settings - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ProductSettingsDeleteOperationResponse struct { - HttpResponse *http.Response -} - -// ProductSettingsDelete ... -func (c SettingsClient) ProductSettingsDelete(ctx context.Context, id SettingId) (result ProductSettingsDeleteOperationResponse, err error) { - req, err := c.preparerForProductSettingsDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "settings.SettingsClient", "ProductSettingsDelete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "settings.SettingsClient", "ProductSettingsDelete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForProductSettingsDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "settings.SettingsClient", "ProductSettingsDelete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForProductSettingsDelete prepares the ProductSettingsDelete request. -func (c SettingsClient) preparerForProductSettingsDelete(ctx context.Context, id SettingId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForProductSettingsDelete handles the response to the ProductSettingsDelete request. The method always -// closes the http.Response Body. -func (c SettingsClient) responderForProductSettingsDelete(resp *http.Response) (result ProductSettingsDeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/settings/method_productsettingsget.go b/resource-manager/securityinsights/2022-07-01-preview/settings/method_productsettingsget.go new file mode 100644 index 00000000000..3d546bae766 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/settings/method_productsettingsget.go @@ -0,0 +1,58 @@ +package settings + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProductSettingsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Settings +} + +// ProductSettingsGet ... +func (c SettingsClient) ProductSettingsGet(ctx context.Context, id SettingId) (result ProductSettingsGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalSettingsImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/settings/method_productsettingsget_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/settings/method_productsettingsget_autorest.go deleted file mode 100644 index bcaeab3e1a3..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/settings/method_productsettingsget_autorest.go +++ /dev/null @@ -1,77 +0,0 @@ -package settings - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ProductSettingsGetOperationResponse struct { - HttpResponse *http.Response - Model *Settings -} - -// ProductSettingsGet ... -func (c SettingsClient) ProductSettingsGet(ctx context.Context, id SettingId) (result ProductSettingsGetOperationResponse, err error) { - req, err := c.preparerForProductSettingsGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "settings.SettingsClient", "ProductSettingsGet", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "settings.SettingsClient", "ProductSettingsGet", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForProductSettingsGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "settings.SettingsClient", "ProductSettingsGet", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForProductSettingsGet prepares the ProductSettingsGet request. -func (c SettingsClient) preparerForProductSettingsGet(ctx context.Context, id SettingId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForProductSettingsGet handles the response to the ProductSettingsGet request. The method always -// closes the http.Response Body. -func (c SettingsClient) responderForProductSettingsGet(resp *http.Response) (result ProductSettingsGetOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalSettingsImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/settings/method_productsettingslist.go b/resource-manager/securityinsights/2022-07-01-preview/settings/method_productsettingslist.go new file mode 100644 index 00000000000..55114738bc5 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/settings/method_productsettingslist.go @@ -0,0 +1,52 @@ +package settings + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProductSettingsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SettingList +} + +// ProductSettingsList ... +func (c SettingsClient) ProductSettingsList(ctx context.Context, id WorkspaceId) (result ProductSettingsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/settings", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/settings/method_productsettingslist_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/settings/method_productsettingslist_autorest.go deleted file mode 100644 index 1242ef0a94b..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/settings/method_productsettingslist_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package settings - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ProductSettingsListOperationResponse struct { - HttpResponse *http.Response - Model *SettingList -} - -// ProductSettingsList ... -func (c SettingsClient) ProductSettingsList(ctx context.Context, id WorkspaceId) (result ProductSettingsListOperationResponse, err error) { - req, err := c.preparerForProductSettingsList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "settings.SettingsClient", "ProductSettingsList", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "settings.SettingsClient", "ProductSettingsList", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForProductSettingsList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "settings.SettingsClient", "ProductSettingsList", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForProductSettingsList prepares the ProductSettingsList request. -func (c SettingsClient) preparerForProductSettingsList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/settings", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForProductSettingsList handles the response to the ProductSettingsList request. The method always -// closes the http.Response Body. -func (c SettingsClient) responderForProductSettingsList(resp *http.Response) (result ProductSettingsListOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/settings/method_productsettingsupdate.go b/resource-manager/securityinsights/2022-07-01-preview/settings/method_productsettingsupdate.go new file mode 100644 index 00000000000..1f33013bb47 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/settings/method_productsettingsupdate.go @@ -0,0 +1,62 @@ +package settings + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProductSettingsUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Settings +} + +// ProductSettingsUpdate ... +func (c SettingsClient) ProductSettingsUpdate(ctx context.Context, id SettingId, input Settings) (result ProductSettingsUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalSettingsImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/settings/method_productsettingsupdate_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/settings/method_productsettingsupdate_autorest.go deleted file mode 100644 index 1b7573688b3..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/settings/method_productsettingsupdate_autorest.go +++ /dev/null @@ -1,78 +0,0 @@ -package settings - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ProductSettingsUpdateOperationResponse struct { - HttpResponse *http.Response - Model *Settings -} - -// ProductSettingsUpdate ... -func (c SettingsClient) ProductSettingsUpdate(ctx context.Context, id SettingId, input Settings) (result ProductSettingsUpdateOperationResponse, err error) { - req, err := c.preparerForProductSettingsUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "settings.SettingsClient", "ProductSettingsUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "settings.SettingsClient", "ProductSettingsUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForProductSettingsUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "settings.SettingsClient", "ProductSettingsUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForProductSettingsUpdate prepares the ProductSettingsUpdate request. -func (c SettingsClient) preparerForProductSettingsUpdate(ctx context.Context, id SettingId, input Settings) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForProductSettingsUpdate handles the response to the ProductSettingsUpdate request. The method always -// closes the http.Response Body. -func (c SettingsClient) responderForProductSettingsUpdate(resp *http.Response) (result ProductSettingsUpdateOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalSettingsImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/sourcecontrols/client.go b/resource-manager/securityinsights/2022-07-01-preview/sourcecontrols/client.go index c0d5d5424c2..9bfd651a63a 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/sourcecontrols/client.go +++ b/resource-manager/securityinsights/2022-07-01-preview/sourcecontrols/client.go @@ -1,18 +1,26 @@ package sourcecontrols -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type SourceControlsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewSourceControlsClientWithBaseURI(endpoint string) SourceControlsClient { - return SourceControlsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewSourceControlsClientWithBaseURI(sdkApi sdkEnv.Api) (*SourceControlsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sourcecontrols", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SourceControlsClient: %+v", err) } + + return &SourceControlsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-07-01-preview/sourcecontrols/constants.go b/resource-manager/securityinsights/2022-07-01-preview/sourcecontrols/constants.go index 7b6518175f0..d134677e70c 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/sourcecontrols/constants.go +++ b/resource-manager/securityinsights/2022-07-01-preview/sourcecontrols/constants.go @@ -1,6 +1,10 @@ package sourcecontrols -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -19,6 +23,19 @@ func PossibleValuesForContentType() []string { } } +func (s *ContentType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseContentType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseContentType(input string) (*ContentType, error) { vals := map[string]ContentType{ "analyticrule": ContentTypeAnalyticRule, @@ -49,6 +66,19 @@ func PossibleValuesForDeploymentFetchStatus() []string { } } +func (s *DeploymentFetchStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeploymentFetchStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDeploymentFetchStatus(input string) (*DeploymentFetchStatus, error) { vals := map[string]DeploymentFetchStatus{ "notfound": DeploymentFetchStatusNotFound, @@ -80,6 +110,19 @@ func PossibleValuesForDeploymentResult() []string { } } +func (s *DeploymentResult) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeploymentResult(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDeploymentResult(input string) (*DeploymentResult, error) { vals := map[string]DeploymentResult{ "canceled": DeploymentResultCanceled, @@ -113,6 +156,19 @@ func PossibleValuesForDeploymentState() []string { } } +func (s *DeploymentState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeploymentState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDeploymentState(input string) (*DeploymentState, error) { vals := map[string]DeploymentState{ "canceling": DeploymentStateCanceling, @@ -143,6 +199,19 @@ func PossibleValuesForRepoType() []string { } } +func (s *RepoType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRepoType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseRepoType(input string) (*RepoType, error) { vals := map[string]RepoType{ "devops": RepoTypeDevOps, @@ -171,6 +240,19 @@ func PossibleValuesForVersion() []string { } } +func (s *Version) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVersion(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseVersion(input string) (*Version, error) { vals := map[string]Version{ "v1": VersionVOne, diff --git a/resource-manager/securityinsights/2022-07-01-preview/sourcecontrols/method_create.go b/resource-manager/securityinsights/2022-07-01-preview/sourcecontrols/method_create.go new file mode 100644 index 00000000000..ee70a7cb64f --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/sourcecontrols/method_create.go @@ -0,0 +1,56 @@ +package sourcecontrols + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SourceControl +} + +// Create ... +func (c SourceControlsClient) Create(ctx context.Context, id SourceControlId, input SourceControl) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/sourcecontrols/method_create_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/sourcecontrols/method_create_autorest.go deleted file mode 100644 index fbf91a3cc21..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/sourcecontrols/method_create_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package sourcecontrols - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOperationResponse struct { - HttpResponse *http.Response - Model *SourceControl -} - -// Create ... -func (c SourceControlsClient) Create(ctx context.Context, id SourceControlId, input SourceControl) (result CreateOperationResponse, err error) { - req, err := c.preparerForCreate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "Create", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "Create", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "Create", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreate prepares the Create request. -func (c SourceControlsClient) preparerForCreate(ctx context.Context, id SourceControlId, input SourceControl) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreate handles the response to the Create request. The method always -// closes the http.Response Body. -func (c SourceControlsClient) responderForCreate(resp *http.Response) (result CreateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/sourcecontrols/method_delete.go b/resource-manager/securityinsights/2022-07-01-preview/sourcecontrols/method_delete.go new file mode 100644 index 00000000000..579d919b3df --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/sourcecontrols/method_delete.go @@ -0,0 +1,47 @@ +package sourcecontrols + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c SourceControlsClient) Delete(ctx context.Context, id SourceControlId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/sourcecontrols/method_delete_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/sourcecontrols/method_delete_autorest.go deleted file mode 100644 index 44699d5360d..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/sourcecontrols/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package sourcecontrols - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c SourceControlsClient) Delete(ctx context.Context, id SourceControlId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c SourceControlsClient) preparerForDelete(ctx context.Context, id SourceControlId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c SourceControlsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/sourcecontrols/method_get.go b/resource-manager/securityinsights/2022-07-01-preview/sourcecontrols/method_get.go new file mode 100644 index 00000000000..3a1cb1bf276 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/sourcecontrols/method_get.go @@ -0,0 +1,51 @@ +package sourcecontrols + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SourceControl +} + +// Get ... +func (c SourceControlsClient) Get(ctx context.Context, id SourceControlId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/sourcecontrols/method_get_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/sourcecontrols/method_get_autorest.go deleted file mode 100644 index 80b8d99a662..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/sourcecontrols/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package sourcecontrols - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *SourceControl -} - -// Get ... -func (c SourceControlsClient) Get(ctx context.Context, id SourceControlId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c SourceControlsClient) preparerForGet(ctx context.Context, id SourceControlId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c SourceControlsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/sourcecontrols/method_list.go b/resource-manager/securityinsights/2022-07-01-preview/sourcecontrols/method_list.go new file mode 100644 index 00000000000..f058d0ec61e --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/sourcecontrols/method_list.go @@ -0,0 +1,91 @@ +package sourcecontrols + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SourceControl +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []SourceControl +} + +// List ... +func (c SourceControlsClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/sourceControls", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]SourceControl `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c SourceControlsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, SourceControlOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SourceControlsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate SourceControlOperationPredicate) (result ListCompleteResult, err error) { + items := make([]SourceControl, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/sourcecontrols/method_list_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/sourcecontrols/method_list_autorest.go deleted file mode 100644 index 04f2a205623..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/sourcecontrols/method_list_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package sourcecontrols - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]SourceControl - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []SourceControl -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c SourceControlsClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c SourceControlsClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/sourceControls", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c SourceControlsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c SourceControlsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []SourceControl `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c SourceControlsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, SourceControlOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c SourceControlsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate SourceControlOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]SourceControl, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/client.go b/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/client.go index 35caff31357..edf96c3143f 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/client.go +++ b/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/client.go @@ -1,18 +1,26 @@ package threatintelligence -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type ThreatIntelligenceClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewThreatIntelligenceClientWithBaseURI(endpoint string) ThreatIntelligenceClient { - return ThreatIntelligenceClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewThreatIntelligenceClientWithBaseURI(sdkApi sdkEnv.Api) (*ThreatIntelligenceClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "threatintelligence", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ThreatIntelligenceClient: %+v", err) } + + return &ThreatIntelligenceClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/constants.go b/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/constants.go index 3549cbffe94..3047e7d6d68 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/constants.go +++ b/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/constants.go @@ -1,6 +1,10 @@ package threatintelligence -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -17,6 +21,19 @@ func PossibleValuesForThreatIntelligenceResourceKindEnum() []string { } } +func (s *ThreatIntelligenceResourceKindEnum) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseThreatIntelligenceResourceKindEnum(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseThreatIntelligenceResourceKindEnum(input string) (*ThreatIntelligenceResourceKindEnum, error) { vals := map[string]ThreatIntelligenceResourceKindEnum{ "indicator": ThreatIntelligenceResourceKindEnumIndicator, @@ -46,6 +63,19 @@ func PossibleValuesForThreatIntelligenceSortingCriteriaEnum() []string { } } +func (s *ThreatIntelligenceSortingCriteriaEnum) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseThreatIntelligenceSortingCriteriaEnum(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseThreatIntelligenceSortingCriteriaEnum(input string) (*ThreatIntelligenceSortingCriteriaEnum, error) { vals := map[string]ThreatIntelligenceSortingCriteriaEnum{ "ascending": ThreatIntelligenceSortingCriteriaEnumAscending, diff --git a/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatorappendtags.go b/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatorappendtags.go new file mode 100644 index 00000000000..4384327485d --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatorappendtags.go @@ -0,0 +1,51 @@ +package threatintelligence + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorAppendTagsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// IndicatorAppendTags ... +func (c ThreatIntelligenceClient) IndicatorAppendTags(ctx context.Context, id IndicatorId, input ThreatIntelligenceAppendTags) (result IndicatorAppendTagsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/appendTags", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatorappendtags_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatorappendtags_autorest.go deleted file mode 100644 index 18b86a166fe..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatorappendtags_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package threatintelligence - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorAppendTagsOperationResponse struct { - HttpResponse *http.Response -} - -// IndicatorAppendTags ... -func (c ThreatIntelligenceClient) IndicatorAppendTags(ctx context.Context, id IndicatorId, input ThreatIntelligenceAppendTags) (result IndicatorAppendTagsOperationResponse, err error) { - req, err := c.preparerForIndicatorAppendTags(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorAppendTags", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorAppendTags", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorAppendTags(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorAppendTags", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorAppendTags prepares the IndicatorAppendTags request. -func (c ThreatIntelligenceClient) preparerForIndicatorAppendTags(ctx context.Context, id IndicatorId, input ThreatIntelligenceAppendTags) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/appendTags", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorAppendTags handles the response to the IndicatorAppendTags request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorAppendTags(resp *http.Response) (result IndicatorAppendTagsOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatorcreate.go b/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatorcreate.go new file mode 100644 index 00000000000..3cee598931c --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatorcreate.go @@ -0,0 +1,63 @@ +package threatintelligence + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorCreateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ThreatIntelligenceInformation +} + +// IndicatorCreate ... +func (c ThreatIntelligenceClient) IndicatorCreate(ctx context.Context, id IndicatorId, input ThreatIntelligenceIndicatorModel) (result IndicatorCreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatorcreate_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatorcreate_autorest.go deleted file mode 100644 index 98609062b7f..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatorcreate_autorest.go +++ /dev/null @@ -1,78 +0,0 @@ -package threatintelligence - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorCreateOperationResponse struct { - HttpResponse *http.Response - Model *ThreatIntelligenceInformation -} - -// IndicatorCreate ... -func (c ThreatIntelligenceClient) IndicatorCreate(ctx context.Context, id IndicatorId, input ThreatIntelligenceIndicatorModel) (result IndicatorCreateOperationResponse, err error) { - req, err := c.preparerForIndicatorCreate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorCreate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorCreate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorCreate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorCreate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorCreate prepares the IndicatorCreate request. -func (c ThreatIntelligenceClient) preparerForIndicatorCreate(ctx context.Context, id IndicatorId, input ThreatIntelligenceIndicatorModel) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorCreate handles the response to the IndicatorCreate request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorCreate(resp *http.Response) (result IndicatorCreateOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatorcreateindicator.go b/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatorcreateindicator.go new file mode 100644 index 00000000000..0f3ab94c4f5 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatorcreateindicator.go @@ -0,0 +1,63 @@ +package threatintelligence + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorCreateIndicatorOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ThreatIntelligenceInformation +} + +// IndicatorCreateIndicator ... +func (c ThreatIntelligenceClient) IndicatorCreateIndicator(ctx context.Context, id WorkspaceId, input ThreatIntelligenceIndicatorModel) (result IndicatorCreateIndicatorOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/createIndicator", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatorcreateindicator_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatorcreateindicator_autorest.go deleted file mode 100644 index ecc76b88f5c..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatorcreateindicator_autorest.go +++ /dev/null @@ -1,79 +0,0 @@ -package threatintelligence - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorCreateIndicatorOperationResponse struct { - HttpResponse *http.Response - Model *ThreatIntelligenceInformation -} - -// IndicatorCreateIndicator ... -func (c ThreatIntelligenceClient) IndicatorCreateIndicator(ctx context.Context, id WorkspaceId, input ThreatIntelligenceIndicatorModel) (result IndicatorCreateIndicatorOperationResponse, err error) { - req, err := c.preparerForIndicatorCreateIndicator(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorCreateIndicator", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorCreateIndicator", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorCreateIndicator(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorCreateIndicator", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorCreateIndicator prepares the IndicatorCreateIndicator request. -func (c ThreatIntelligenceClient) preparerForIndicatorCreateIndicator(ctx context.Context, id WorkspaceId, input ThreatIntelligenceIndicatorModel) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/createIndicator", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorCreateIndicator handles the response to the IndicatorCreateIndicator request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorCreateIndicator(resp *http.Response) (result IndicatorCreateIndicatorOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatordelete.go b/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatordelete.go new file mode 100644 index 00000000000..4de264524d5 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatordelete.go @@ -0,0 +1,47 @@ +package threatintelligence + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// IndicatorDelete ... +func (c ThreatIntelligenceClient) IndicatorDelete(ctx context.Context, id IndicatorId) (result IndicatorDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatordelete_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatordelete_autorest.go deleted file mode 100644 index 825d3b911ce..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatordelete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package threatintelligence - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorDeleteOperationResponse struct { - HttpResponse *http.Response -} - -// IndicatorDelete ... -func (c ThreatIntelligenceClient) IndicatorDelete(ctx context.Context, id IndicatorId) (result IndicatorDeleteOperationResponse, err error) { - req, err := c.preparerForIndicatorDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorDelete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorDelete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorDelete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorDelete prepares the IndicatorDelete request. -func (c ThreatIntelligenceClient) preparerForIndicatorDelete(ctx context.Context, id IndicatorId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorDelete handles the response to the IndicatorDelete request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorDelete(resp *http.Response) (result IndicatorDeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatorget.go b/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatorget.go new file mode 100644 index 00000000000..3358363f139 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatorget.go @@ -0,0 +1,58 @@ +package threatintelligence + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ThreatIntelligenceInformation +} + +// IndicatorGet ... +func (c ThreatIntelligenceClient) IndicatorGet(ctx context.Context, id IndicatorId) (result IndicatorGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatorget_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatorget_autorest.go deleted file mode 100644 index ac1187fb285..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatorget_autorest.go +++ /dev/null @@ -1,77 +0,0 @@ -package threatintelligence - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorGetOperationResponse struct { - HttpResponse *http.Response - Model *ThreatIntelligenceInformation -} - -// IndicatorGet ... -func (c ThreatIntelligenceClient) IndicatorGet(ctx context.Context, id IndicatorId) (result IndicatorGetOperationResponse, err error) { - req, err := c.preparerForIndicatorGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorGet", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorGet", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorGet", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorGet prepares the IndicatorGet request. -func (c ThreatIntelligenceClient) preparerForIndicatorGet(ctx context.Context, id IndicatorId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorGet handles the response to the IndicatorGet request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorGet(resp *http.Response) (result IndicatorGetOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatormetricslist.go b/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatormetricslist.go new file mode 100644 index 00000000000..688ff3c16d1 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatormetricslist.go @@ -0,0 +1,52 @@ +package threatintelligence + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorMetricsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ThreatIntelligenceMetricsList +} + +// IndicatorMetricsList ... +func (c ThreatIntelligenceClient) IndicatorMetricsList(ctx context.Context, id WorkspaceId) (result IndicatorMetricsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/metrics", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatormetricslist_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatormetricslist_autorest.go deleted file mode 100644 index 1835c26ed96..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatormetricslist_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package threatintelligence - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorMetricsListOperationResponse struct { - HttpResponse *http.Response - Model *ThreatIntelligenceMetricsList -} - -// IndicatorMetricsList ... -func (c ThreatIntelligenceClient) IndicatorMetricsList(ctx context.Context, id WorkspaceId) (result IndicatorMetricsListOperationResponse, err error) { - req, err := c.preparerForIndicatorMetricsList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorMetricsList", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorMetricsList", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorMetricsList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorMetricsList", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorMetricsList prepares the IndicatorMetricsList request. -func (c ThreatIntelligenceClient) preparerForIndicatorMetricsList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/metrics", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorMetricsList handles the response to the IndicatorMetricsList request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorMetricsList(resp *http.Response) (result IndicatorMetricsListOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatorqueryindicators.go b/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatorqueryindicators.go new file mode 100644 index 00000000000..8ce639f2623 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatorqueryindicators.go @@ -0,0 +1,103 @@ +package threatintelligence + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorQueryIndicatorsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ThreatIntelligenceInformation +} + +type IndicatorQueryIndicatorsCompleteResult struct { + LatestHttpResponse *http.Response + Items []ThreatIntelligenceInformation +} + +// IndicatorQueryIndicators ... +func (c ThreatIntelligenceClient) IndicatorQueryIndicators(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria) (result IndicatorQueryIndicatorsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/queryIndicators", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]ThreatIntelligenceInformation, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalThreatIntelligenceInformationImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for ThreatIntelligenceInformation (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// IndicatorQueryIndicatorsComplete retrieves all the results into a single object +func (c ThreatIntelligenceClient) IndicatorQueryIndicatorsComplete(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria) (IndicatorQueryIndicatorsCompleteResult, error) { + return c.IndicatorQueryIndicatorsCompleteMatchingPredicate(ctx, id, input, ThreatIntelligenceInformationOperationPredicate{}) +} + +// IndicatorQueryIndicatorsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ThreatIntelligenceClient) IndicatorQueryIndicatorsCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria, predicate ThreatIntelligenceInformationOperationPredicate) (result IndicatorQueryIndicatorsCompleteResult, err error) { + items := make([]ThreatIntelligenceInformation, 0) + + resp, err := c.IndicatorQueryIndicators(ctx, id, input) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = IndicatorQueryIndicatorsCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatorqueryindicators_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatorqueryindicators_autorest.go deleted file mode 100644 index fcbe7c74758..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatorqueryindicators_autorest.go +++ /dev/null @@ -1,197 +0,0 @@ -package threatintelligence - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorQueryIndicatorsOperationResponse struct { - HttpResponse *http.Response - Model *[]ThreatIntelligenceInformation - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (IndicatorQueryIndicatorsOperationResponse, error) -} - -type IndicatorQueryIndicatorsCompleteResult struct { - Items []ThreatIntelligenceInformation -} - -func (r IndicatorQueryIndicatorsOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r IndicatorQueryIndicatorsOperationResponse) LoadMore(ctx context.Context) (resp IndicatorQueryIndicatorsOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// IndicatorQueryIndicators ... -func (c ThreatIntelligenceClient) IndicatorQueryIndicators(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria) (resp IndicatorQueryIndicatorsOperationResponse, err error) { - req, err := c.preparerForIndicatorQueryIndicators(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorQueryIndicators", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorQueryIndicators", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForIndicatorQueryIndicators(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorQueryIndicators", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForIndicatorQueryIndicators prepares the IndicatorQueryIndicators request. -func (c ThreatIntelligenceClient) preparerForIndicatorQueryIndicators(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/queryIndicators", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForIndicatorQueryIndicatorsWithNextLink prepares the IndicatorQueryIndicators request with the given nextLink token. -func (c ThreatIntelligenceClient) preparerForIndicatorQueryIndicatorsWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorQueryIndicators handles the response to the IndicatorQueryIndicators request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorQueryIndicators(resp *http.Response) (result IndicatorQueryIndicatorsOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]ThreatIntelligenceInformation, 0) - for i, v := range respObj.Values { - val, err := unmarshalThreatIntelligenceInformationImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for ThreatIntelligenceInformation (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result IndicatorQueryIndicatorsOperationResponse, err error) { - req, err := c.preparerForIndicatorQueryIndicatorsWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorQueryIndicators", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorQueryIndicators", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorQueryIndicators(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorQueryIndicators", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// IndicatorQueryIndicatorsComplete retrieves all of the results into a single object -func (c ThreatIntelligenceClient) IndicatorQueryIndicatorsComplete(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria) (IndicatorQueryIndicatorsCompleteResult, error) { - return c.IndicatorQueryIndicatorsCompleteMatchingPredicate(ctx, id, input, ThreatIntelligenceInformationOperationPredicate{}) -} - -// IndicatorQueryIndicatorsCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c ThreatIntelligenceClient) IndicatorQueryIndicatorsCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria, predicate ThreatIntelligenceInformationOperationPredicate) (resp IndicatorQueryIndicatorsCompleteResult, err error) { - items := make([]ThreatIntelligenceInformation, 0) - - page, err := c.IndicatorQueryIndicators(ctx, id, input) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := IndicatorQueryIndicatorsCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatorreplacetags.go b/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatorreplacetags.go new file mode 100644 index 00000000000..052bbe7b66a --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatorreplacetags.go @@ -0,0 +1,63 @@ +package threatintelligence + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorReplaceTagsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ThreatIntelligenceInformation +} + +// IndicatorReplaceTags ... +func (c ThreatIntelligenceClient) IndicatorReplaceTags(ctx context.Context, id IndicatorId, input ThreatIntelligenceIndicatorModel) (result IndicatorReplaceTagsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/replaceTags", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatorreplacetags_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatorreplacetags_autorest.go deleted file mode 100644 index 01efbe5b778..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatorreplacetags_autorest.go +++ /dev/null @@ -1,79 +0,0 @@ -package threatintelligence - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorReplaceTagsOperationResponse struct { - HttpResponse *http.Response - Model *ThreatIntelligenceInformation -} - -// IndicatorReplaceTags ... -func (c ThreatIntelligenceClient) IndicatorReplaceTags(ctx context.Context, id IndicatorId, input ThreatIntelligenceIndicatorModel) (result IndicatorReplaceTagsOperationResponse, err error) { - req, err := c.preparerForIndicatorReplaceTags(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorReplaceTags", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorReplaceTags", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorReplaceTags(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorReplaceTags", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorReplaceTags prepares the IndicatorReplaceTags request. -func (c ThreatIntelligenceClient) preparerForIndicatorReplaceTags(ctx context.Context, id IndicatorId, input ThreatIntelligenceIndicatorModel) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/replaceTags", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorReplaceTags handles the response to the IndicatorReplaceTags request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorReplaceTags(resp *http.Response) (result IndicatorReplaceTagsOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatorslist.go b/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatorslist.go new file mode 100644 index 00000000000..860ecd26255 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatorslist.go @@ -0,0 +1,139 @@ +package threatintelligence + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ThreatIntelligenceInformation +} + +type IndicatorsListCompleteResult struct { + LatestHttpResponse *http.Response + Items []ThreatIntelligenceInformation +} + +type IndicatorsListOperationOptions struct { + Filter *string + Orderby *string + Top *int64 +} + +func DefaultIndicatorsListOperationOptions() IndicatorsListOperationOptions { + return IndicatorsListOperationOptions{} +} + +func (o IndicatorsListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o IndicatorsListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o IndicatorsListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// IndicatorsList ... +func (c ThreatIntelligenceClient) IndicatorsList(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions) (result IndicatorsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/indicators", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]ThreatIntelligenceInformation, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalThreatIntelligenceInformationImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for ThreatIntelligenceInformation (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// IndicatorsListComplete retrieves all the results into a single object +func (c ThreatIntelligenceClient) IndicatorsListComplete(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions) (IndicatorsListCompleteResult, error) { + return c.IndicatorsListCompleteMatchingPredicate(ctx, id, options, ThreatIntelligenceInformationOperationPredicate{}) +} + +// IndicatorsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ThreatIntelligenceClient) IndicatorsListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions, predicate ThreatIntelligenceInformationOperationPredicate) (result IndicatorsListCompleteResult, err error) { + items := make([]ThreatIntelligenceInformation, 0) + + resp, err := c.IndicatorsList(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = IndicatorsListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatorslist_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatorslist_autorest.go deleted file mode 100644 index 22ef9d7b193..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/threatintelligence/method_indicatorslist_autorest.go +++ /dev/null @@ -1,235 +0,0 @@ -package threatintelligence - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorsListOperationResponse struct { - HttpResponse *http.Response - Model *[]ThreatIntelligenceInformation - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (IndicatorsListOperationResponse, error) -} - -type IndicatorsListCompleteResult struct { - Items []ThreatIntelligenceInformation -} - -func (r IndicatorsListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r IndicatorsListOperationResponse) LoadMore(ctx context.Context) (resp IndicatorsListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type IndicatorsListOperationOptions struct { - Filter *string - Orderby *string - Top *int64 -} - -func DefaultIndicatorsListOperationOptions() IndicatorsListOperationOptions { - return IndicatorsListOperationOptions{} -} - -func (o IndicatorsListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o IndicatorsListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Filter != nil { - out["$filter"] = *o.Filter - } - - if o.Orderby != nil { - out["$orderby"] = *o.Orderby - } - - if o.Top != nil { - out["$top"] = *o.Top - } - - return out -} - -// IndicatorsList ... -func (c ThreatIntelligenceClient) IndicatorsList(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions) (resp IndicatorsListOperationResponse, err error) { - req, err := c.preparerForIndicatorsList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForIndicatorsList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForIndicatorsList prepares the IndicatorsList request. -func (c ThreatIntelligenceClient) preparerForIndicatorsList(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/indicators", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForIndicatorsListWithNextLink prepares the IndicatorsList request with the given nextLink token. -func (c ThreatIntelligenceClient) preparerForIndicatorsListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorsList handles the response to the IndicatorsList request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorsList(resp *http.Response) (result IndicatorsListOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]ThreatIntelligenceInformation, 0) - for i, v := range respObj.Values { - val, err := unmarshalThreatIntelligenceInformationImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for ThreatIntelligenceInformation (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result IndicatorsListOperationResponse, err error) { - req, err := c.preparerForIndicatorsListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorsList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// IndicatorsListComplete retrieves all of the results into a single object -func (c ThreatIntelligenceClient) IndicatorsListComplete(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions) (IndicatorsListCompleteResult, error) { - return c.IndicatorsListCompleteMatchingPredicate(ctx, id, options, ThreatIntelligenceInformationOperationPredicate{}) -} - -// IndicatorsListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c ThreatIntelligenceClient) IndicatorsListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions, predicate ThreatIntelligenceInformationOperationPredicate) (resp IndicatorsListCompleteResult, err error) { - items := make([]ThreatIntelligenceInformation, 0) - - page, err := c.IndicatorsList(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := IndicatorsListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/watchlistitems/client.go b/resource-manager/securityinsights/2022-07-01-preview/watchlistitems/client.go index 9403755456e..d3193694a48 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/watchlistitems/client.go +++ b/resource-manager/securityinsights/2022-07-01-preview/watchlistitems/client.go @@ -1,18 +1,26 @@ package watchlistitems -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type WatchlistItemsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewWatchlistItemsClientWithBaseURI(endpoint string) WatchlistItemsClient { - return WatchlistItemsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewWatchlistItemsClientWithBaseURI(sdkApi sdkEnv.Api) (*WatchlistItemsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "watchlistitems", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating WatchlistItemsClient: %+v", err) } + + return &WatchlistItemsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-07-01-preview/watchlistitems/method_createorupdate.go b/resource-manager/securityinsights/2022-07-01-preview/watchlistitems/method_createorupdate.go new file mode 100644 index 00000000000..d02782f71bc --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/watchlistitems/method_createorupdate.go @@ -0,0 +1,56 @@ +package watchlistitems + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *WatchlistItem +} + +// CreateOrUpdate ... +func (c WatchlistItemsClient) CreateOrUpdate(ctx context.Context, id WatchlistItemId, input WatchlistItem) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/watchlistitems/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/watchlistitems/method_createorupdate_autorest.go deleted file mode 100644 index 15d8fdcc2be..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/watchlistitems/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package watchlistitems - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *WatchlistItem -} - -// CreateOrUpdate ... -func (c WatchlistItemsClient) CreateOrUpdate(ctx context.Context, id WatchlistItemId, input WatchlistItem) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c WatchlistItemsClient) preparerForCreateOrUpdate(ctx context.Context, id WatchlistItemId, input WatchlistItem) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c WatchlistItemsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/watchlistitems/method_delete.go b/resource-manager/securityinsights/2022-07-01-preview/watchlistitems/method_delete.go new file mode 100644 index 00000000000..5565b767fa5 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/watchlistitems/method_delete.go @@ -0,0 +1,47 @@ +package watchlistitems + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c WatchlistItemsClient) Delete(ctx context.Context, id WatchlistItemId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/watchlistitems/method_delete_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/watchlistitems/method_delete_autorest.go deleted file mode 100644 index c9b8c46f9e5..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/watchlistitems/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package watchlistitems - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c WatchlistItemsClient) Delete(ctx context.Context, id WatchlistItemId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c WatchlistItemsClient) preparerForDelete(ctx context.Context, id WatchlistItemId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c WatchlistItemsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/watchlistitems/method_get.go b/resource-manager/securityinsights/2022-07-01-preview/watchlistitems/method_get.go new file mode 100644 index 00000000000..ff9a8e143fa --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/watchlistitems/method_get.go @@ -0,0 +1,51 @@ +package watchlistitems + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *WatchlistItem +} + +// Get ... +func (c WatchlistItemsClient) Get(ctx context.Context, id WatchlistItemId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/watchlistitems/method_get_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/watchlistitems/method_get_autorest.go deleted file mode 100644 index b294f999f64..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/watchlistitems/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package watchlistitems - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *WatchlistItem -} - -// Get ... -func (c WatchlistItemsClient) Get(ctx context.Context, id WatchlistItemId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c WatchlistItemsClient) preparerForGet(ctx context.Context, id WatchlistItemId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c WatchlistItemsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/watchlistitems/method_list.go b/resource-manager/securityinsights/2022-07-01-preview/watchlistitems/method_list.go new file mode 100644 index 00000000000..8a4d418ea0b --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/watchlistitems/method_list.go @@ -0,0 +1,91 @@ +package watchlistitems + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]WatchlistItem +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []WatchlistItem +} + +// List ... +func (c WatchlistItemsClient) List(ctx context.Context, id WatchlistId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/watchlistItems", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]WatchlistItem `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c WatchlistItemsClient) ListComplete(ctx context.Context, id WatchlistId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, WatchlistItemOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c WatchlistItemsClient) ListCompleteMatchingPredicate(ctx context.Context, id WatchlistId, predicate WatchlistItemOperationPredicate) (result ListCompleteResult, err error) { + items := make([]WatchlistItem, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/watchlistitems/method_list_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/watchlistitems/method_list_autorest.go deleted file mode 100644 index d8e4bf85bf1..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/watchlistitems/method_list_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package watchlistitems - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]WatchlistItem - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []WatchlistItem -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c WatchlistItemsClient) List(ctx context.Context, id WatchlistId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c WatchlistItemsClient) preparerForList(ctx context.Context, id WatchlistId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/watchlistItems", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c WatchlistItemsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c WatchlistItemsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []WatchlistItem `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c WatchlistItemsClient) ListComplete(ctx context.Context, id WatchlistId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, WatchlistItemOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c WatchlistItemsClient) ListCompleteMatchingPredicate(ctx context.Context, id WatchlistId, predicate WatchlistItemOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]WatchlistItem, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/watchlists/client.go b/resource-manager/securityinsights/2022-07-01-preview/watchlists/client.go index 61cfa3d0ac3..45211175054 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/watchlists/client.go +++ b/resource-manager/securityinsights/2022-07-01-preview/watchlists/client.go @@ -1,18 +1,26 @@ package watchlists -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type WatchlistsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewWatchlistsClientWithBaseURI(endpoint string) WatchlistsClient { - return WatchlistsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewWatchlistsClientWithBaseURI(sdkApi sdkEnv.Api) (*WatchlistsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "watchlists", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating WatchlistsClient: %+v", err) } + + return &WatchlistsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-07-01-preview/watchlists/constants.go b/resource-manager/securityinsights/2022-07-01-preview/watchlists/constants.go index 21534a9bfa6..6a9873135b3 100644 --- a/resource-manager/securityinsights/2022-07-01-preview/watchlists/constants.go +++ b/resource-manager/securityinsights/2022-07-01-preview/watchlists/constants.go @@ -1,6 +1,10 @@ package watchlists -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -19,6 +23,19 @@ func PossibleValuesForSourceType() []string { } } +func (s *SourceType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSourceType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSourceType(input string) (*SourceType, error) { vals := map[string]SourceType{ "local file": SourceTypeLocalFile, diff --git a/resource-manager/securityinsights/2022-07-01-preview/watchlists/method_createorupdate.go b/resource-manager/securityinsights/2022-07-01-preview/watchlists/method_createorupdate.go new file mode 100644 index 00000000000..cf0dc47e9d7 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/watchlists/method_createorupdate.go @@ -0,0 +1,56 @@ +package watchlists + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Watchlist +} + +// CreateOrUpdate ... +func (c WatchlistsClient) CreateOrUpdate(ctx context.Context, id WatchlistId, input Watchlist) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/watchlists/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/watchlists/method_createorupdate_autorest.go deleted file mode 100644 index e6d8a5976b8..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/watchlists/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package watchlists - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *Watchlist -} - -// CreateOrUpdate ... -func (c WatchlistsClient) CreateOrUpdate(ctx context.Context, id WatchlistId, input Watchlist) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c WatchlistsClient) preparerForCreateOrUpdate(ctx context.Context, id WatchlistId, input Watchlist) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c WatchlistsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/watchlists/method_delete.go b/resource-manager/securityinsights/2022-07-01-preview/watchlists/method_delete.go new file mode 100644 index 00000000000..9d495f99c57 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/watchlists/method_delete.go @@ -0,0 +1,47 @@ +package watchlists + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c WatchlistsClient) Delete(ctx context.Context, id WatchlistId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/watchlists/method_delete_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/watchlists/method_delete_autorest.go deleted file mode 100644 index 56234124b82..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/watchlists/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package watchlists - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c WatchlistsClient) Delete(ctx context.Context, id WatchlistId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c WatchlistsClient) preparerForDelete(ctx context.Context, id WatchlistId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c WatchlistsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/watchlists/method_get.go b/resource-manager/securityinsights/2022-07-01-preview/watchlists/method_get.go new file mode 100644 index 00000000000..39ec92feaeb --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/watchlists/method_get.go @@ -0,0 +1,51 @@ +package watchlists + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Watchlist +} + +// Get ... +func (c WatchlistsClient) Get(ctx context.Context, id WatchlistId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/watchlists/method_get_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/watchlists/method_get_autorest.go deleted file mode 100644 index d7253f62215..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/watchlists/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package watchlists - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *Watchlist -} - -// Get ... -func (c WatchlistsClient) Get(ctx context.Context, id WatchlistId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c WatchlistsClient) preparerForGet(ctx context.Context, id WatchlistId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c WatchlistsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-07-01-preview/watchlists/method_list.go b/resource-manager/securityinsights/2022-07-01-preview/watchlists/method_list.go new file mode 100644 index 00000000000..9122b014815 --- /dev/null +++ b/resource-manager/securityinsights/2022-07-01-preview/watchlists/method_list.go @@ -0,0 +1,91 @@ +package watchlists + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Watchlist +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Watchlist +} + +// List ... +func (c WatchlistsClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/watchlists", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Watchlist `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c WatchlistsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, WatchlistOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c WatchlistsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate WatchlistOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Watchlist, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-07-01-preview/watchlists/method_list_autorest.go b/resource-manager/securityinsights/2022-07-01-preview/watchlists/method_list_autorest.go deleted file mode 100644 index a3a2c27c15e..00000000000 --- a/resource-manager/securityinsights/2022-07-01-preview/watchlists/method_list_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package watchlists - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]Watchlist - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []Watchlist -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c WatchlistsClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c WatchlistsClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/watchlists", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c WatchlistsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c WatchlistsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []Watchlist `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c WatchlistsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, WatchlistOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c WatchlistsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate WatchlistOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]Watchlist, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-08-01/actions/client.go b/resource-manager/securityinsights/2022-08-01/actions/client.go index 9a66b55eb82..a2b7d01bfe1 100644 --- a/resource-manager/securityinsights/2022-08-01/actions/client.go +++ b/resource-manager/securityinsights/2022-08-01/actions/client.go @@ -1,18 +1,26 @@ package actions -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type ActionsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewActionsClientWithBaseURI(endpoint string) ActionsClient { - return ActionsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewActionsClientWithBaseURI(sdkApi sdkEnv.Api) (*ActionsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "actions", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ActionsClient: %+v", err) } + + return &ActionsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-08-01/actions/method_createorupdate.go b/resource-manager/securityinsights/2022-08-01/actions/method_createorupdate.go new file mode 100644 index 00000000000..1672bf99a0f --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/actions/method_createorupdate.go @@ -0,0 +1,56 @@ +package actions + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ActionResponse +} + +// CreateOrUpdate ... +func (c ActionsClient) CreateOrUpdate(ctx context.Context, id ActionId, input ActionRequest) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-08-01/actions/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-08-01/actions/method_createorupdate_autorest.go deleted file mode 100644 index f5145e1a555..00000000000 --- a/resource-manager/securityinsights/2022-08-01/actions/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package actions - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *ActionResponse -} - -// CreateOrUpdate ... -func (c ActionsClient) CreateOrUpdate(ctx context.Context, id ActionId, input ActionRequest) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c ActionsClient) preparerForCreateOrUpdate(ctx context.Context, id ActionId, input ActionRequest) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c ActionsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-08-01/actions/method_delete.go b/resource-manager/securityinsights/2022-08-01/actions/method_delete.go new file mode 100644 index 00000000000..0f8a28307c2 --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/actions/method_delete.go @@ -0,0 +1,47 @@ +package actions + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c ActionsClient) Delete(ctx context.Context, id ActionId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-08-01/actions/method_delete_autorest.go b/resource-manager/securityinsights/2022-08-01/actions/method_delete_autorest.go deleted file mode 100644 index d142f9f3054..00000000000 --- a/resource-manager/securityinsights/2022-08-01/actions/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package actions - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c ActionsClient) Delete(ctx context.Context, id ActionId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c ActionsClient) preparerForDelete(ctx context.Context, id ActionId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c ActionsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-08-01/actions/method_get.go b/resource-manager/securityinsights/2022-08-01/actions/method_get.go new file mode 100644 index 00000000000..76d3593e1f1 --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/actions/method_get.go @@ -0,0 +1,51 @@ +package actions + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ActionResponse +} + +// Get ... +func (c ActionsClient) Get(ctx context.Context, id ActionId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-08-01/actions/method_get_autorest.go b/resource-manager/securityinsights/2022-08-01/actions/method_get_autorest.go deleted file mode 100644 index aa1388a0c31..00000000000 --- a/resource-manager/securityinsights/2022-08-01/actions/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package actions - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *ActionResponse -} - -// Get ... -func (c ActionsClient) Get(ctx context.Context, id ActionId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c ActionsClient) preparerForGet(ctx context.Context, id ActionId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c ActionsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-08-01/actions/method_listbyalertrule.go b/resource-manager/securityinsights/2022-08-01/actions/method_listbyalertrule.go new file mode 100644 index 00000000000..09d32b9d82d --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/actions/method_listbyalertrule.go @@ -0,0 +1,91 @@ +package actions + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByAlertRuleOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ActionResponse +} + +type ListByAlertRuleCompleteResult struct { + LatestHttpResponse *http.Response + Items []ActionResponse +} + +// ListByAlertRule ... +func (c ActionsClient) ListByAlertRule(ctx context.Context, id AlertRuleId) (result ListByAlertRuleOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/actions", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ActionResponse `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByAlertRuleComplete retrieves all the results into a single object +func (c ActionsClient) ListByAlertRuleComplete(ctx context.Context, id AlertRuleId) (ListByAlertRuleCompleteResult, error) { + return c.ListByAlertRuleCompleteMatchingPredicate(ctx, id, ActionResponseOperationPredicate{}) +} + +// ListByAlertRuleCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ActionsClient) ListByAlertRuleCompleteMatchingPredicate(ctx context.Context, id AlertRuleId, predicate ActionResponseOperationPredicate) (result ListByAlertRuleCompleteResult, err error) { + items := make([]ActionResponse, 0) + + resp, err := c.ListByAlertRule(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByAlertRuleCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-08-01/actions/method_listbyalertrule_autorest.go b/resource-manager/securityinsights/2022-08-01/actions/method_listbyalertrule_autorest.go deleted file mode 100644 index a58a9738f1f..00000000000 --- a/resource-manager/securityinsights/2022-08-01/actions/method_listbyalertrule_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package actions - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListByAlertRuleOperationResponse struct { - HttpResponse *http.Response - Model *[]ActionResponse - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListByAlertRuleOperationResponse, error) -} - -type ListByAlertRuleCompleteResult struct { - Items []ActionResponse -} - -func (r ListByAlertRuleOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListByAlertRuleOperationResponse) LoadMore(ctx context.Context) (resp ListByAlertRuleOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// ListByAlertRule ... -func (c ActionsClient) ListByAlertRule(ctx context.Context, id AlertRuleId) (resp ListByAlertRuleOperationResponse, err error) { - req, err := c.preparerForListByAlertRule(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "ListByAlertRule", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "ListByAlertRule", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForListByAlertRule(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "ListByAlertRule", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForListByAlertRule prepares the ListByAlertRule request. -func (c ActionsClient) preparerForListByAlertRule(ctx context.Context, id AlertRuleId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/actions", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListByAlertRuleWithNextLink prepares the ListByAlertRule request with the given nextLink token. -func (c ActionsClient) preparerForListByAlertRuleWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForListByAlertRule handles the response to the ListByAlertRule request. The method always -// closes the http.Response Body. -func (c ActionsClient) responderForListByAlertRule(resp *http.Response) (result ListByAlertRuleOperationResponse, err error) { - type page struct { - Values []ActionResponse `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByAlertRuleOperationResponse, err error) { - req, err := c.preparerForListByAlertRuleWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "ListByAlertRule", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "ListByAlertRule", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForListByAlertRule(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "ListByAlertRule", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListByAlertRuleComplete retrieves all of the results into a single object -func (c ActionsClient) ListByAlertRuleComplete(ctx context.Context, id AlertRuleId) (ListByAlertRuleCompleteResult, error) { - return c.ListByAlertRuleCompleteMatchingPredicate(ctx, id, ActionResponseOperationPredicate{}) -} - -// ListByAlertRuleCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c ActionsClient) ListByAlertRuleCompleteMatchingPredicate(ctx context.Context, id AlertRuleId, predicate ActionResponseOperationPredicate) (resp ListByAlertRuleCompleteResult, err error) { - items := make([]ActionResponse, 0) - - page, err := c.ListByAlertRule(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListByAlertRuleCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-08-01/alertrules/client.go b/resource-manager/securityinsights/2022-08-01/alertrules/client.go index 6e34bca2ce3..e6ca04af9da 100644 --- a/resource-manager/securityinsights/2022-08-01/alertrules/client.go +++ b/resource-manager/securityinsights/2022-08-01/alertrules/client.go @@ -1,18 +1,26 @@ package alertrules -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type AlertRulesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewAlertRulesClientWithBaseURI(endpoint string) AlertRulesClient { - return AlertRulesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewAlertRulesClientWithBaseURI(sdkApi sdkEnv.Api) (*AlertRulesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "alertrules", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AlertRulesClient: %+v", err) } + + return &AlertRulesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-08-01/alertrules/constants.go b/resource-manager/securityinsights/2022-08-01/alertrules/constants.go index 91178a52cc5..8c0d36ec74b 100644 --- a/resource-manager/securityinsights/2022-08-01/alertrules/constants.go +++ b/resource-manager/securityinsights/2022-08-01/alertrules/constants.go @@ -1,6 +1,10 @@ package alertrules -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -19,6 +23,19 @@ func PossibleValuesForAlertDetail() []string { } } +func (s *AlertDetail) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertDetail(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertDetail(input string) (*AlertDetail, error) { vals := map[string]AlertDetail{ "displayname": AlertDetailDisplayName, @@ -49,6 +66,19 @@ func PossibleValuesForAlertRuleKind() []string { } } +func (s *AlertRuleKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertRuleKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertRuleKind(input string) (*AlertRuleKind, error) { vals := map[string]AlertRuleKind{ "fusion": AlertRuleKindFusion, @@ -82,6 +112,19 @@ func PossibleValuesForAlertSeverity() []string { } } +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertSeverity(input string) (*AlertSeverity, error) { vals := map[string]AlertSeverity{ "high": AlertSeverityHigh, @@ -142,6 +185,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -217,6 +273,19 @@ func PossibleValuesForEntityMappingType() []string { } } +func (s *EntityMappingType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityMappingType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityMappingType(input string) (*EntityMappingType, error) { vals := map[string]EntityMappingType{ "account": EntityMappingTypeAccount, @@ -261,6 +330,19 @@ func PossibleValuesForEventGroupingAggregationKind() []string { } } +func (s *EventGroupingAggregationKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEventGroupingAggregationKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEventGroupingAggregationKind(input string) (*EventGroupingAggregationKind, error) { vals := map[string]EventGroupingAggregationKind{ "alertperresult": EventGroupingAggregationKindAlertPerResult, @@ -291,6 +373,19 @@ func PossibleValuesForMatchingMethod() []string { } } +func (s *MatchingMethod) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMatchingMethod(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseMatchingMethod(input string) (*MatchingMethod, error) { vals := map[string]MatchingMethod{ "allentities": MatchingMethodAllEntities, @@ -326,6 +421,19 @@ func PossibleValuesForMicrosoftSecurityProductName() []string { } } +func (s *MicrosoftSecurityProductName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMicrosoftSecurityProductName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseMicrosoftSecurityProductName(input string) (*MicrosoftSecurityProductName, error) { vals := map[string]MicrosoftSecurityProductName{ "azure active directory identity protection": MicrosoftSecurityProductNameAzureActiveDirectoryIdentityProtection, @@ -361,6 +469,19 @@ func PossibleValuesForTriggerOperator() []string { } } +func (s *TriggerOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTriggerOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseTriggerOperator(input string) (*TriggerOperator, error) { vals := map[string]TriggerOperator{ "equal": TriggerOperatorEqual, diff --git a/resource-manager/securityinsights/2022-08-01/alertrules/method_createorupdate.go b/resource-manager/securityinsights/2022-08-01/alertrules/method_createorupdate.go new file mode 100644 index 00000000000..f77c7558d09 --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/alertrules/method_createorupdate.go @@ -0,0 +1,63 @@ +package alertrules + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AlertRule +} + +// CreateOrUpdate ... +func (c AlertRulesClient) CreateOrUpdate(ctx context.Context, id AlertRuleId, input AlertRule) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalAlertRuleImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-08-01/alertrules/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-08-01/alertrules/method_createorupdate_autorest.go deleted file mode 100644 index 548f6c4ef37..00000000000 --- a/resource-manager/securityinsights/2022-08-01/alertrules/method_createorupdate_autorest.go +++ /dev/null @@ -1,78 +0,0 @@ -package alertrules - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *AlertRule -} - -// CreateOrUpdate ... -func (c AlertRulesClient) CreateOrUpdate(ctx context.Context, id AlertRuleId, input AlertRule) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c AlertRulesClient) preparerForCreateOrUpdate(ctx context.Context, id AlertRuleId, input AlertRule) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c AlertRulesClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalAlertRuleImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-08-01/alertrules/method_delete.go b/resource-manager/securityinsights/2022-08-01/alertrules/method_delete.go new file mode 100644 index 00000000000..aae7085c25e --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/alertrules/method_delete.go @@ -0,0 +1,47 @@ +package alertrules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c AlertRulesClient) Delete(ctx context.Context, id AlertRuleId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-08-01/alertrules/method_delete_autorest.go b/resource-manager/securityinsights/2022-08-01/alertrules/method_delete_autorest.go deleted file mode 100644 index 417e1a0017e..00000000000 --- a/resource-manager/securityinsights/2022-08-01/alertrules/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package alertrules - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c AlertRulesClient) Delete(ctx context.Context, id AlertRuleId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c AlertRulesClient) preparerForDelete(ctx context.Context, id AlertRuleId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c AlertRulesClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-08-01/alertrules/method_get.go b/resource-manager/securityinsights/2022-08-01/alertrules/method_get.go new file mode 100644 index 00000000000..945c07bfad1 --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/alertrules/method_get.go @@ -0,0 +1,58 @@ +package alertrules + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AlertRule +} + +// Get ... +func (c AlertRulesClient) Get(ctx context.Context, id AlertRuleId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalAlertRuleImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-08-01/alertrules/method_get_autorest.go b/resource-manager/securityinsights/2022-08-01/alertrules/method_get_autorest.go deleted file mode 100644 index ddd1836d4de..00000000000 --- a/resource-manager/securityinsights/2022-08-01/alertrules/method_get_autorest.go +++ /dev/null @@ -1,77 +0,0 @@ -package alertrules - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *AlertRule -} - -// Get ... -func (c AlertRulesClient) Get(ctx context.Context, id AlertRuleId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c AlertRulesClient) preparerForGet(ctx context.Context, id AlertRuleId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c AlertRulesClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalAlertRuleImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-08-01/alertrules/method_list.go b/resource-manager/securityinsights/2022-08-01/alertrules/method_list.go new file mode 100644 index 00000000000..5ac99496167 --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/alertrules/method_list.go @@ -0,0 +1,103 @@ +package alertrules + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AlertRule +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []AlertRule +} + +// List ... +func (c AlertRulesClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/alertRules", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]AlertRule, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalAlertRuleImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for AlertRule (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// ListComplete retrieves all the results into a single object +func (c AlertRulesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, AlertRuleOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AlertRulesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AlertRuleOperationPredicate) (result ListCompleteResult, err error) { + items := make([]AlertRule, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-08-01/alertrules/method_list_autorest.go b/resource-manager/securityinsights/2022-08-01/alertrules/method_list_autorest.go deleted file mode 100644 index f06cf0f6241..00000000000 --- a/resource-manager/securityinsights/2022-08-01/alertrules/method_list_autorest.go +++ /dev/null @@ -1,196 +0,0 @@ -package alertrules - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]AlertRule - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []AlertRule -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c AlertRulesClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c AlertRulesClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/alertRules", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c AlertRulesClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c AlertRulesClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]AlertRule, 0) - for i, v := range respObj.Values { - val, err := unmarshalAlertRuleImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for AlertRule (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c AlertRulesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, AlertRuleOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c AlertRulesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AlertRuleOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]AlertRule, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-08-01/alertruletemplates/client.go b/resource-manager/securityinsights/2022-08-01/alertruletemplates/client.go index c439e5a41c7..2932bf14a55 100644 --- a/resource-manager/securityinsights/2022-08-01/alertruletemplates/client.go +++ b/resource-manager/securityinsights/2022-08-01/alertruletemplates/client.go @@ -1,18 +1,26 @@ package alertruletemplates -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type AlertRuleTemplatesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewAlertRuleTemplatesClientWithBaseURI(endpoint string) AlertRuleTemplatesClient { - return AlertRuleTemplatesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewAlertRuleTemplatesClientWithBaseURI(sdkApi sdkEnv.Api) (*AlertRuleTemplatesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "alertruletemplates", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AlertRuleTemplatesClient: %+v", err) } + + return &AlertRuleTemplatesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-08-01/alertruletemplates/constants.go b/resource-manager/securityinsights/2022-08-01/alertruletemplates/constants.go index 6354a51236f..7ec9389513f 100644 --- a/resource-manager/securityinsights/2022-08-01/alertruletemplates/constants.go +++ b/resource-manager/securityinsights/2022-08-01/alertruletemplates/constants.go @@ -1,6 +1,10 @@ package alertruletemplates -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -21,6 +25,19 @@ func PossibleValuesForAlertRuleKind() []string { } } +func (s *AlertRuleKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertRuleKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertRuleKind(input string) (*AlertRuleKind, error) { vals := map[string]AlertRuleKind{ "fusion": AlertRuleKindFusion, @@ -54,6 +71,19 @@ func PossibleValuesForAlertSeverity() []string { } } +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertSeverity(input string) (*AlertSeverity, error) { vals := map[string]AlertSeverity{ "high": AlertSeverityHigh, @@ -114,6 +144,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -189,6 +232,19 @@ func PossibleValuesForEntityMappingType() []string { } } +func (s *EntityMappingType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityMappingType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityMappingType(input string) (*EntityMappingType, error) { vals := map[string]EntityMappingType{ "account": EntityMappingTypeAccount, @@ -233,6 +289,19 @@ func PossibleValuesForEventGroupingAggregationKind() []string { } } +func (s *EventGroupingAggregationKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEventGroupingAggregationKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEventGroupingAggregationKind(input string) (*EventGroupingAggregationKind, error) { vals := map[string]EventGroupingAggregationKind{ "alertperresult": EventGroupingAggregationKindAlertPerResult, @@ -267,6 +336,19 @@ func PossibleValuesForMicrosoftSecurityProductName() []string { } } +func (s *MicrosoftSecurityProductName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMicrosoftSecurityProductName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseMicrosoftSecurityProductName(input string) (*MicrosoftSecurityProductName, error) { vals := map[string]MicrosoftSecurityProductName{ "azure active directory identity protection": MicrosoftSecurityProductNameAzureActiveDirectoryIdentityProtection, @@ -300,6 +382,19 @@ func PossibleValuesForTemplateStatus() []string { } } +func (s *TemplateStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTemplateStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseTemplateStatus(input string) (*TemplateStatus, error) { vals := map[string]TemplateStatus{ "available": TemplateStatusAvailable, @@ -333,6 +428,19 @@ func PossibleValuesForTriggerOperator() []string { } } +func (s *TriggerOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTriggerOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseTriggerOperator(input string) (*TriggerOperator, error) { vals := map[string]TriggerOperator{ "equal": TriggerOperatorEqual, diff --git a/resource-manager/securityinsights/2022-08-01/alertruletemplates/method_get.go b/resource-manager/securityinsights/2022-08-01/alertruletemplates/method_get.go new file mode 100644 index 00000000000..861712be66a --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/alertruletemplates/method_get.go @@ -0,0 +1,58 @@ +package alertruletemplates + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AlertRuleTemplate +} + +// Get ... +func (c AlertRuleTemplatesClient) Get(ctx context.Context, id AlertRuleTemplateId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalAlertRuleTemplateImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-08-01/alertruletemplates/method_get_autorest.go b/resource-manager/securityinsights/2022-08-01/alertruletemplates/method_get_autorest.go deleted file mode 100644 index ad4e0487d83..00000000000 --- a/resource-manager/securityinsights/2022-08-01/alertruletemplates/method_get_autorest.go +++ /dev/null @@ -1,77 +0,0 @@ -package alertruletemplates - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *AlertRuleTemplate -} - -// Get ... -func (c AlertRuleTemplatesClient) Get(ctx context.Context, id AlertRuleTemplateId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c AlertRuleTemplatesClient) preparerForGet(ctx context.Context, id AlertRuleTemplateId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c AlertRuleTemplatesClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalAlertRuleTemplateImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-08-01/alertruletemplates/method_list.go b/resource-manager/securityinsights/2022-08-01/alertruletemplates/method_list.go new file mode 100644 index 00000000000..21f9ceec3de --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/alertruletemplates/method_list.go @@ -0,0 +1,103 @@ +package alertruletemplates + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AlertRuleTemplate +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []AlertRuleTemplate +} + +// List ... +func (c AlertRuleTemplatesClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/alertRuleTemplates", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]AlertRuleTemplate, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalAlertRuleTemplateImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for AlertRuleTemplate (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// ListComplete retrieves all the results into a single object +func (c AlertRuleTemplatesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, AlertRuleTemplateOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AlertRuleTemplatesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AlertRuleTemplateOperationPredicate) (result ListCompleteResult, err error) { + items := make([]AlertRuleTemplate, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-08-01/alertruletemplates/method_list_autorest.go b/resource-manager/securityinsights/2022-08-01/alertruletemplates/method_list_autorest.go deleted file mode 100644 index 56794382966..00000000000 --- a/resource-manager/securityinsights/2022-08-01/alertruletemplates/method_list_autorest.go +++ /dev/null @@ -1,196 +0,0 @@ -package alertruletemplates - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]AlertRuleTemplate - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []AlertRuleTemplate -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c AlertRuleTemplatesClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c AlertRuleTemplatesClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/alertRuleTemplates", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c AlertRuleTemplatesClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c AlertRuleTemplatesClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]AlertRuleTemplate, 0) - for i, v := range respObj.Values { - val, err := unmarshalAlertRuleTemplateImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for AlertRuleTemplate (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c AlertRuleTemplatesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, AlertRuleTemplateOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c AlertRuleTemplatesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AlertRuleTemplateOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]AlertRuleTemplate, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-08-01/automationrules/client.go b/resource-manager/securityinsights/2022-08-01/automationrules/client.go index 960f049c387..18fafea1496 100644 --- a/resource-manager/securityinsights/2022-08-01/automationrules/client.go +++ b/resource-manager/securityinsights/2022-08-01/automationrules/client.go @@ -1,18 +1,26 @@ package automationrules -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type AutomationRulesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewAutomationRulesClientWithBaseURI(endpoint string) AutomationRulesClient { - return AutomationRulesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewAutomationRulesClientWithBaseURI(sdkApi sdkEnv.Api) (*AutomationRulesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "automationrules", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AutomationRulesClient: %+v", err) } + + return &AutomationRulesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-08-01/automationrules/constants.go b/resource-manager/securityinsights/2022-08-01/automationrules/constants.go index 6240723f8a9..1b99265c0e2 100644 --- a/resource-manager/securityinsights/2022-08-01/automationrules/constants.go +++ b/resource-manager/securityinsights/2022-08-01/automationrules/constants.go @@ -1,6 +1,10 @@ package automationrules -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -19,6 +23,19 @@ func PossibleValuesForActionType() []string { } } +func (s *ActionType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseActionType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseActionType(input string) (*ActionType, error) { vals := map[string]ActionType{ "modifyproperties": ActionTypeModifyProperties, @@ -59,6 +76,19 @@ func PossibleValuesForAutomationRulePropertyConditionSupportedOperator() []strin } } +func (s *AutomationRulePropertyConditionSupportedOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRulePropertyConditionSupportedOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAutomationRulePropertyConditionSupportedOperator(input string) (*AutomationRulePropertyConditionSupportedOperator, error) { vals := map[string]AutomationRulePropertyConditionSupportedOperator{ "contains": AutomationRulePropertyConditionSupportedOperatorContains, @@ -197,6 +227,19 @@ func PossibleValuesForAutomationRulePropertyConditionSupportedProperty() []strin } } +func (s *AutomationRulePropertyConditionSupportedProperty) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRulePropertyConditionSupportedProperty(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAutomationRulePropertyConditionSupportedProperty(input string) (*AutomationRulePropertyConditionSupportedProperty, error) { vals := map[string]AutomationRulePropertyConditionSupportedProperty{ "accountaadtenantid": AutomationRulePropertyConditionSupportedPropertyAccountAadTenantId, @@ -275,6 +318,19 @@ func PossibleValuesForConditionType() []string { } } +func (s *ConditionType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConditionType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConditionType(input string) (*ConditionType, error) { vals := map[string]ConditionType{ "property": ConditionTypeProperty, @@ -306,6 +362,19 @@ func PossibleValuesForIncidentClassification() []string { } } +func (s *IncidentClassification) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentClassification(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentClassification(input string) (*IncidentClassification, error) { vals := map[string]IncidentClassification{ "benignpositive": IncidentClassificationBenignPositive, @@ -340,6 +409,19 @@ func PossibleValuesForIncidentClassificationReason() []string { } } +func (s *IncidentClassificationReason) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentClassificationReason(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentClassificationReason(input string) (*IncidentClassificationReason, error) { vals := map[string]IncidentClassificationReason{ "inaccuratedata": IncidentClassificationReasonInaccurateData, @@ -370,6 +452,19 @@ func PossibleValuesForIncidentLabelType() []string { } } +func (s *IncidentLabelType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentLabelType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentLabelType(input string) (*IncidentLabelType, error) { vals := map[string]IncidentLabelType{ "autoassigned": IncidentLabelTypeAutoAssigned, @@ -402,6 +497,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, @@ -434,6 +542,19 @@ func PossibleValuesForIncidentStatus() []string { } } +func (s *IncidentStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentStatus(input string) (*IncidentStatus, error) { vals := map[string]IncidentStatus{ "active": IncidentStatusActive, @@ -465,6 +586,19 @@ func PossibleValuesForOwnerType() []string { } } +func (s *OwnerType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOwnerType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseOwnerType(input string) (*OwnerType, error) { vals := map[string]OwnerType{ "group": OwnerTypeGroup, @@ -492,6 +626,19 @@ func PossibleValuesForTriggersOn() []string { } } +func (s *TriggersOn) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTriggersOn(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseTriggersOn(input string) (*TriggersOn, error) { vals := map[string]TriggersOn{ "incidents": TriggersOnIncidents, @@ -517,6 +664,19 @@ func PossibleValuesForTriggersWhen() []string { } } +func (s *TriggersWhen) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTriggersWhen(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseTriggersWhen(input string) (*TriggersWhen, error) { vals := map[string]TriggersWhen{ "created": TriggersWhenCreated, diff --git a/resource-manager/securityinsights/2022-08-01/automationrules/method_createorupdate.go b/resource-manager/securityinsights/2022-08-01/automationrules/method_createorupdate.go new file mode 100644 index 00000000000..c0b3c44f2da --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/automationrules/method_createorupdate.go @@ -0,0 +1,56 @@ +package automationrules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AutomationRule +} + +// CreateOrUpdate ... +func (c AutomationRulesClient) CreateOrUpdate(ctx context.Context, id AutomationRuleId, input AutomationRule) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-08-01/automationrules/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-08-01/automationrules/method_createorupdate_autorest.go deleted file mode 100644 index 790f2ff99f9..00000000000 --- a/resource-manager/securityinsights/2022-08-01/automationrules/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package automationrules - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *AutomationRule -} - -// CreateOrUpdate ... -func (c AutomationRulesClient) CreateOrUpdate(ctx context.Context, id AutomationRuleId, input AutomationRule) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c AutomationRulesClient) preparerForCreateOrUpdate(ctx context.Context, id AutomationRuleId, input AutomationRule) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c AutomationRulesClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-08-01/automationrules/method_delete.go b/resource-manager/securityinsights/2022-08-01/automationrules/method_delete.go new file mode 100644 index 00000000000..682e97ed619 --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/automationrules/method_delete.go @@ -0,0 +1,52 @@ +package automationrules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *interface{} +} + +// Delete ... +func (c AutomationRulesClient) Delete(ctx context.Context, id AutomationRuleId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-08-01/automationrules/method_delete_autorest.go b/resource-manager/securityinsights/2022-08-01/automationrules/method_delete_autorest.go deleted file mode 100644 index cd33f79070e..00000000000 --- a/resource-manager/securityinsights/2022-08-01/automationrules/method_delete_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package automationrules - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response - Model *interface{} -} - -// Delete ... -func (c AutomationRulesClient) Delete(ctx context.Context, id AutomationRuleId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c AutomationRulesClient) preparerForDelete(ctx context.Context, id AutomationRuleId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c AutomationRulesClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-08-01/automationrules/method_get.go b/resource-manager/securityinsights/2022-08-01/automationrules/method_get.go new file mode 100644 index 00000000000..0676dc80f40 --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/automationrules/method_get.go @@ -0,0 +1,51 @@ +package automationrules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AutomationRule +} + +// Get ... +func (c AutomationRulesClient) Get(ctx context.Context, id AutomationRuleId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-08-01/automationrules/method_get_autorest.go b/resource-manager/securityinsights/2022-08-01/automationrules/method_get_autorest.go deleted file mode 100644 index 20f385aa8d7..00000000000 --- a/resource-manager/securityinsights/2022-08-01/automationrules/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package automationrules - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *AutomationRule -} - -// Get ... -func (c AutomationRulesClient) Get(ctx context.Context, id AutomationRuleId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c AutomationRulesClient) preparerForGet(ctx context.Context, id AutomationRuleId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c AutomationRulesClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-08-01/automationrules/method_list.go b/resource-manager/securityinsights/2022-08-01/automationrules/method_list.go new file mode 100644 index 00000000000..a3c7db4995a --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/automationrules/method_list.go @@ -0,0 +1,91 @@ +package automationrules + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AutomationRule +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []AutomationRule +} + +// List ... +func (c AutomationRulesClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/automationRules", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]AutomationRule `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c AutomationRulesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, AutomationRuleOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AutomationRulesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AutomationRuleOperationPredicate) (result ListCompleteResult, err error) { + items := make([]AutomationRule, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-08-01/automationrules/method_list_autorest.go b/resource-manager/securityinsights/2022-08-01/automationrules/method_list_autorest.go deleted file mode 100644 index e2818088fcf..00000000000 --- a/resource-manager/securityinsights/2022-08-01/automationrules/method_list_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package automationrules - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]AutomationRule - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []AutomationRule -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c AutomationRulesClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c AutomationRulesClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/automationRules", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c AutomationRulesClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c AutomationRulesClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []AutomationRule `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c AutomationRulesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, AutomationRuleOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c AutomationRulesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AutomationRuleOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]AutomationRule, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-08-01/bookmarks/client.go b/resource-manager/securityinsights/2022-08-01/bookmarks/client.go index ee8ca229e2d..22469155649 100644 --- a/resource-manager/securityinsights/2022-08-01/bookmarks/client.go +++ b/resource-manager/securityinsights/2022-08-01/bookmarks/client.go @@ -1,18 +1,26 @@ package bookmarks -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type BookmarksClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewBookmarksClientWithBaseURI(endpoint string) BookmarksClient { - return BookmarksClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewBookmarksClientWithBaseURI(sdkApi sdkEnv.Api) (*BookmarksClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "bookmarks", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating BookmarksClient: %+v", err) } + + return &BookmarksClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-08-01/bookmarks/constants.go b/resource-manager/securityinsights/2022-08-01/bookmarks/constants.go index f3a9bf2482b..c057284aed1 100644 --- a/resource-manager/securityinsights/2022-08-01/bookmarks/constants.go +++ b/resource-manager/securityinsights/2022-08-01/bookmarks/constants.go @@ -1,6 +1,10 @@ package bookmarks -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -23,6 +27,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, diff --git a/resource-manager/securityinsights/2022-08-01/bookmarks/method_createorupdate.go b/resource-manager/securityinsights/2022-08-01/bookmarks/method_createorupdate.go new file mode 100644 index 00000000000..72b6987ce5b --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/bookmarks/method_createorupdate.go @@ -0,0 +1,56 @@ +package bookmarks + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Bookmark +} + +// CreateOrUpdate ... +func (c BookmarksClient) CreateOrUpdate(ctx context.Context, id BookmarkId, input Bookmark) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-08-01/bookmarks/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-08-01/bookmarks/method_createorupdate_autorest.go deleted file mode 100644 index 6bae46884df..00000000000 --- a/resource-manager/securityinsights/2022-08-01/bookmarks/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package bookmarks - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *Bookmark -} - -// CreateOrUpdate ... -func (c BookmarksClient) CreateOrUpdate(ctx context.Context, id BookmarkId, input Bookmark) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c BookmarksClient) preparerForCreateOrUpdate(ctx context.Context, id BookmarkId, input Bookmark) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c BookmarksClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-08-01/bookmarks/method_delete.go b/resource-manager/securityinsights/2022-08-01/bookmarks/method_delete.go new file mode 100644 index 00000000000..75eef715a7c --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/bookmarks/method_delete.go @@ -0,0 +1,47 @@ +package bookmarks + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c BookmarksClient) Delete(ctx context.Context, id BookmarkId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-08-01/bookmarks/method_delete_autorest.go b/resource-manager/securityinsights/2022-08-01/bookmarks/method_delete_autorest.go deleted file mode 100644 index aa1033f513c..00000000000 --- a/resource-manager/securityinsights/2022-08-01/bookmarks/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package bookmarks - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c BookmarksClient) Delete(ctx context.Context, id BookmarkId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c BookmarksClient) preparerForDelete(ctx context.Context, id BookmarkId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c BookmarksClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-08-01/bookmarks/method_get.go b/resource-manager/securityinsights/2022-08-01/bookmarks/method_get.go new file mode 100644 index 00000000000..b8db3d1b69f --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/bookmarks/method_get.go @@ -0,0 +1,51 @@ +package bookmarks + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Bookmark +} + +// Get ... +func (c BookmarksClient) Get(ctx context.Context, id BookmarkId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-08-01/bookmarks/method_get_autorest.go b/resource-manager/securityinsights/2022-08-01/bookmarks/method_get_autorest.go deleted file mode 100644 index c76a6c0c211..00000000000 --- a/resource-manager/securityinsights/2022-08-01/bookmarks/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package bookmarks - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *Bookmark -} - -// Get ... -func (c BookmarksClient) Get(ctx context.Context, id BookmarkId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c BookmarksClient) preparerForGet(ctx context.Context, id BookmarkId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c BookmarksClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-08-01/bookmarks/method_list.go b/resource-manager/securityinsights/2022-08-01/bookmarks/method_list.go new file mode 100644 index 00000000000..432b04c413a --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/bookmarks/method_list.go @@ -0,0 +1,91 @@ +package bookmarks + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Bookmark +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Bookmark +} + +// List ... +func (c BookmarksClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/bookmarks", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Bookmark `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c BookmarksClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, BookmarkOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c BookmarksClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate BookmarkOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Bookmark, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-08-01/bookmarks/method_list_autorest.go b/resource-manager/securityinsights/2022-08-01/bookmarks/method_list_autorest.go deleted file mode 100644 index 7c4a69eacea..00000000000 --- a/resource-manager/securityinsights/2022-08-01/bookmarks/method_list_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package bookmarks - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]Bookmark - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []Bookmark -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c BookmarksClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c BookmarksClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/bookmarks", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c BookmarksClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c BookmarksClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []Bookmark `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c BookmarksClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, BookmarkOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c BookmarksClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate BookmarkOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]Bookmark, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-08-01/client.go b/resource-manager/securityinsights/2022-08-01/client.go index 23822a75359..dec96a8e832 100644 --- a/resource-manager/securityinsights/2022-08-01/client.go +++ b/resource-manager/securityinsights/2022-08-01/client.go @@ -4,7 +4,8 @@ package v2022_08_01 // Licensed under the MIT License. See NOTICE.txt in the project root for license information. import ( - "github.com/Azure/go-autorest/autorest" + "fmt" + "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-08-01/actions" "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-08-01/alertrules" "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-08-01/alertruletemplates" @@ -22,6 +23,8 @@ import ( "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-08-01/threatintelligence" "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-08-01/watchlistitems" "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-08-01/watchlists" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" ) type Client struct { @@ -44,76 +47,126 @@ type Client struct { Watchlists *watchlists.WatchlistsClient } -func NewClientWithBaseURI(endpoint string, configureAuthFunc func(c *autorest.Client)) Client { - - actionsClient := actions.NewActionsClientWithBaseURI(endpoint) - configureAuthFunc(&actionsClient.Client) - - alertRuleTemplatesClient := alertruletemplates.NewAlertRuleTemplatesClientWithBaseURI(endpoint) - configureAuthFunc(&alertRuleTemplatesClient.Client) +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + actionsClient, err := actions.NewActionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Actions client: %+v", err) + } + configureFunc(actionsClient.Client) - alertRulesClient := alertrules.NewAlertRulesClientWithBaseURI(endpoint) - configureAuthFunc(&alertRulesClient.Client) + alertRuleTemplatesClient, err := alertruletemplates.NewAlertRuleTemplatesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AlertRuleTemplates client: %+v", err) + } + configureFunc(alertRuleTemplatesClient.Client) - automationRulesClient := automationrules.NewAutomationRulesClientWithBaseURI(endpoint) - configureAuthFunc(&automationRulesClient.Client) + alertRulesClient, err := alertrules.NewAlertRulesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AlertRules client: %+v", err) + } + configureFunc(alertRulesClient.Client) - bookmarksClient := bookmarks.NewBookmarksClientWithBaseURI(endpoint) - configureAuthFunc(&bookmarksClient.Client) + automationRulesClient, err := automationrules.NewAutomationRulesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AutomationRules client: %+v", err) + } + configureFunc(automationRulesClient.Client) - dataConnectorsClient := dataconnectors.NewDataConnectorsClientWithBaseURI(endpoint) - configureAuthFunc(&dataConnectorsClient.Client) + bookmarksClient, err := bookmarks.NewBookmarksClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Bookmarks client: %+v", err) + } + configureFunc(bookmarksClient.Client) - entityTypesClient := entitytypes.NewEntityTypesClientWithBaseURI(endpoint) - configureAuthFunc(&entityTypesClient.Client) + dataConnectorsClient, err := dataconnectors.NewDataConnectorsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DataConnectors client: %+v", err) + } + configureFunc(dataConnectorsClient.Client) - incidentAlertsClient := incidentalerts.NewIncidentAlertsClientWithBaseURI(endpoint) - configureAuthFunc(&incidentAlertsClient.Client) + entityTypesClient, err := entitytypes.NewEntityTypesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building EntityTypes client: %+v", err) + } + configureFunc(entityTypesClient.Client) - incidentBookmarksClient := incidentbookmarks.NewIncidentBookmarksClientWithBaseURI(endpoint) - configureAuthFunc(&incidentBookmarksClient.Client) + incidentAlertsClient, err := incidentalerts.NewIncidentAlertsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IncidentAlerts client: %+v", err) + } + configureFunc(incidentAlertsClient.Client) - incidentCommentsClient := incidentcomments.NewIncidentCommentsClientWithBaseURI(endpoint) - configureAuthFunc(&incidentCommentsClient.Client) + incidentBookmarksClient, err := incidentbookmarks.NewIncidentBookmarksClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IncidentBookmarks client: %+v", err) + } + configureFunc(incidentBookmarksClient.Client) - incidentEntitiesClient := incidententities.NewIncidentEntitiesClientWithBaseURI(endpoint) - configureAuthFunc(&incidentEntitiesClient.Client) + incidentCommentsClient, err := incidentcomments.NewIncidentCommentsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IncidentComments client: %+v", err) + } + configureFunc(incidentCommentsClient.Client) - incidentRelationsClient := incidentrelations.NewIncidentRelationsClientWithBaseURI(endpoint) - configureAuthFunc(&incidentRelationsClient.Client) + incidentEntitiesClient, err := incidententities.NewIncidentEntitiesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IncidentEntities client: %+v", err) + } + configureFunc(incidentEntitiesClient.Client) - incidentsClient := incidents.NewIncidentsClientWithBaseURI(endpoint) - configureAuthFunc(&incidentsClient.Client) + incidentRelationsClient, err := incidentrelations.NewIncidentRelationsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IncidentRelations client: %+v", err) + } + configureFunc(incidentRelationsClient.Client) - sentinelOnboardingStatesClient := sentinelonboardingstates.NewSentinelOnboardingStatesClientWithBaseURI(endpoint) - configureAuthFunc(&sentinelOnboardingStatesClient.Client) + incidentsClient, err := incidents.NewIncidentsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Incidents client: %+v", err) + } + configureFunc(incidentsClient.Client) - threatIntelligenceClient := threatintelligence.NewThreatIntelligenceClientWithBaseURI(endpoint) - configureAuthFunc(&threatIntelligenceClient.Client) + sentinelOnboardingStatesClient, err := sentinelonboardingstates.NewSentinelOnboardingStatesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SentinelOnboardingStates client: %+v", err) + } + configureFunc(sentinelOnboardingStatesClient.Client) - watchlistItemsClient := watchlistitems.NewWatchlistItemsClientWithBaseURI(endpoint) - configureAuthFunc(&watchlistItemsClient.Client) + threatIntelligenceClient, err := threatintelligence.NewThreatIntelligenceClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ThreatIntelligence client: %+v", err) + } + configureFunc(threatIntelligenceClient.Client) - watchlistsClient := watchlists.NewWatchlistsClientWithBaseURI(endpoint) - configureAuthFunc(&watchlistsClient.Client) + watchlistItemsClient, err := watchlistitems.NewWatchlistItemsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building WatchlistItems client: %+v", err) + } + configureFunc(watchlistItemsClient.Client) - return Client{ - Actions: &actionsClient, - AlertRuleTemplates: &alertRuleTemplatesClient, - AlertRules: &alertRulesClient, - AutomationRules: &automationRulesClient, - Bookmarks: &bookmarksClient, - DataConnectors: &dataConnectorsClient, - EntityTypes: &entityTypesClient, - IncidentAlerts: &incidentAlertsClient, - IncidentBookmarks: &incidentBookmarksClient, - IncidentComments: &incidentCommentsClient, - IncidentEntities: &incidentEntitiesClient, - IncidentRelations: &incidentRelationsClient, - Incidents: &incidentsClient, - SentinelOnboardingStates: &sentinelOnboardingStatesClient, - ThreatIntelligence: &threatIntelligenceClient, - WatchlistItems: &watchlistItemsClient, - Watchlists: &watchlistsClient, + watchlistsClient, err := watchlists.NewWatchlistsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Watchlists client: %+v", err) } + configureFunc(watchlistsClient.Client) + + return &Client{ + Actions: actionsClient, + AlertRuleTemplates: alertRuleTemplatesClient, + AlertRules: alertRulesClient, + AutomationRules: automationRulesClient, + Bookmarks: bookmarksClient, + DataConnectors: dataConnectorsClient, + EntityTypes: entityTypesClient, + IncidentAlerts: incidentAlertsClient, + IncidentBookmarks: incidentBookmarksClient, + IncidentComments: incidentCommentsClient, + IncidentEntities: incidentEntitiesClient, + IncidentRelations: incidentRelationsClient, + Incidents: incidentsClient, + SentinelOnboardingStates: sentinelOnboardingStatesClient, + ThreatIntelligence: threatIntelligenceClient, + WatchlistItems: watchlistItemsClient, + Watchlists: watchlistsClient, + }, nil } diff --git a/resource-manager/securityinsights/2022-08-01/dataconnectors/client.go b/resource-manager/securityinsights/2022-08-01/dataconnectors/client.go index cf334b72568..8ed0120c79a 100644 --- a/resource-manager/securityinsights/2022-08-01/dataconnectors/client.go +++ b/resource-manager/securityinsights/2022-08-01/dataconnectors/client.go @@ -1,18 +1,26 @@ package dataconnectors -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type DataConnectorsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewDataConnectorsClientWithBaseURI(endpoint string) DataConnectorsClient { - return DataConnectorsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewDataConnectorsClientWithBaseURI(sdkApi sdkEnv.Api) (*DataConnectorsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "dataconnectors", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DataConnectorsClient: %+v", err) } + + return &DataConnectorsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-08-01/dataconnectors/constants.go b/resource-manager/securityinsights/2022-08-01/dataconnectors/constants.go index db98dc83577..3fb78689b33 100644 --- a/resource-manager/securityinsights/2022-08-01/dataconnectors/constants.go +++ b/resource-manager/securityinsights/2022-08-01/dataconnectors/constants.go @@ -1,6 +1,10 @@ package dataconnectors -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -31,6 +35,19 @@ func PossibleValuesForDataConnectorKind() []string { } } +func (s *DataConnectorKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataConnectorKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDataConnectorKind(input string) (*DataConnectorKind, error) { vals := map[string]DataConnectorKind{ "amazonwebservicescloudtrail": DataConnectorKindAmazonWebServicesCloudTrail, @@ -65,6 +82,19 @@ func PossibleValuesForDataTypeState() []string { } } +func (s *DataTypeState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataTypeState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDataTypeState(input string) (*DataTypeState, error) { vals := map[string]DataTypeState{ "disabled": DataTypeStateDisabled, diff --git a/resource-manager/securityinsights/2022-08-01/dataconnectors/method_createorupdate.go b/resource-manager/securityinsights/2022-08-01/dataconnectors/method_createorupdate.go new file mode 100644 index 00000000000..c5f6e5d1503 --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/dataconnectors/method_createorupdate.go @@ -0,0 +1,63 @@ +package dataconnectors + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DataConnector +} + +// CreateOrUpdate ... +func (c DataConnectorsClient) CreateOrUpdate(ctx context.Context, id DataConnectorId, input DataConnector) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalDataConnectorImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-08-01/dataconnectors/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-08-01/dataconnectors/method_createorupdate_autorest.go deleted file mode 100644 index 1f259eca36c..00000000000 --- a/resource-manager/securityinsights/2022-08-01/dataconnectors/method_createorupdate_autorest.go +++ /dev/null @@ -1,78 +0,0 @@ -package dataconnectors - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *DataConnector -} - -// CreateOrUpdate ... -func (c DataConnectorsClient) CreateOrUpdate(ctx context.Context, id DataConnectorId, input DataConnector) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c DataConnectorsClient) preparerForCreateOrUpdate(ctx context.Context, id DataConnectorId, input DataConnector) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c DataConnectorsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalDataConnectorImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-08-01/dataconnectors/method_delete.go b/resource-manager/securityinsights/2022-08-01/dataconnectors/method_delete.go new file mode 100644 index 00000000000..8461ec6d8a1 --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/dataconnectors/method_delete.go @@ -0,0 +1,47 @@ +package dataconnectors + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c DataConnectorsClient) Delete(ctx context.Context, id DataConnectorId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-08-01/dataconnectors/method_delete_autorest.go b/resource-manager/securityinsights/2022-08-01/dataconnectors/method_delete_autorest.go deleted file mode 100644 index ac4ddf57441..00000000000 --- a/resource-manager/securityinsights/2022-08-01/dataconnectors/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package dataconnectors - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c DataConnectorsClient) Delete(ctx context.Context, id DataConnectorId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c DataConnectorsClient) preparerForDelete(ctx context.Context, id DataConnectorId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c DataConnectorsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-08-01/dataconnectors/method_get.go b/resource-manager/securityinsights/2022-08-01/dataconnectors/method_get.go new file mode 100644 index 00000000000..3511ba85477 --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/dataconnectors/method_get.go @@ -0,0 +1,58 @@ +package dataconnectors + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DataConnector +} + +// Get ... +func (c DataConnectorsClient) Get(ctx context.Context, id DataConnectorId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalDataConnectorImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-08-01/dataconnectors/method_get_autorest.go b/resource-manager/securityinsights/2022-08-01/dataconnectors/method_get_autorest.go deleted file mode 100644 index af56be19c9c..00000000000 --- a/resource-manager/securityinsights/2022-08-01/dataconnectors/method_get_autorest.go +++ /dev/null @@ -1,77 +0,0 @@ -package dataconnectors - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *DataConnector -} - -// Get ... -func (c DataConnectorsClient) Get(ctx context.Context, id DataConnectorId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c DataConnectorsClient) preparerForGet(ctx context.Context, id DataConnectorId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c DataConnectorsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalDataConnectorImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-08-01/dataconnectors/method_list.go b/resource-manager/securityinsights/2022-08-01/dataconnectors/method_list.go new file mode 100644 index 00000000000..6975384fdee --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/dataconnectors/method_list.go @@ -0,0 +1,103 @@ +package dataconnectors + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DataConnector +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []DataConnector +} + +// List ... +func (c DataConnectorsClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/dataConnectors", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]DataConnector, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalDataConnectorImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for DataConnector (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// ListComplete retrieves all the results into a single object +func (c DataConnectorsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, DataConnectorOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DataConnectorsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate DataConnectorOperationPredicate) (result ListCompleteResult, err error) { + items := make([]DataConnector, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-08-01/dataconnectors/method_list_autorest.go b/resource-manager/securityinsights/2022-08-01/dataconnectors/method_list_autorest.go deleted file mode 100644 index e08d153a6eb..00000000000 --- a/resource-manager/securityinsights/2022-08-01/dataconnectors/method_list_autorest.go +++ /dev/null @@ -1,196 +0,0 @@ -package dataconnectors - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]DataConnector - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []DataConnector -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c DataConnectorsClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c DataConnectorsClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/dataConnectors", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c DataConnectorsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c DataConnectorsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]DataConnector, 0) - for i, v := range respObj.Values { - val, err := unmarshalDataConnectorImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for DataConnector (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c DataConnectorsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, DataConnectorOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c DataConnectorsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate DataConnectorOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]DataConnector, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-08-01/entitytypes/client.go b/resource-manager/securityinsights/2022-08-01/entitytypes/client.go index 60583ea834f..bcdd09e4029 100644 --- a/resource-manager/securityinsights/2022-08-01/entitytypes/client.go +++ b/resource-manager/securityinsights/2022-08-01/entitytypes/client.go @@ -1,18 +1,26 @@ package entitytypes -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type EntityTypesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewEntityTypesClientWithBaseURI(endpoint string) EntityTypesClient { - return EntityTypesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewEntityTypesClientWithBaseURI(sdkApi sdkEnv.Api) (*EntityTypesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "entitytypes", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating EntityTypesClient: %+v", err) } + + return &EntityTypesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-08-01/entitytypes/constants.go b/resource-manager/securityinsights/2022-08-01/entitytypes/constants.go index fbe60ce0f02..2f194a6f29d 100644 --- a/resource-manager/securityinsights/2022-08-01/entitytypes/constants.go +++ b/resource-manager/securityinsights/2022-08-01/entitytypes/constants.go @@ -1,6 +1,10 @@ package entitytypes -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -23,6 +27,19 @@ func PossibleValuesForAlertSeverity() []string { } } +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertSeverity(input string) (*AlertSeverity, error) { vals := map[string]AlertSeverity{ "high": AlertSeverityHigh, @@ -59,6 +76,19 @@ func PossibleValuesForAlertStatus() []string { } } +func (s *AlertStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertStatus(input string) (*AlertStatus, error) { vals := map[string]AlertStatus{ "dismissed": AlertStatusDismissed, @@ -94,6 +124,19 @@ func PossibleValuesForAntispamMailDirection() []string { } } +func (s *AntispamMailDirection) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAntispamMailDirection(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAntispamMailDirection(input string) (*AntispamMailDirection, error) { vals := map[string]AntispamMailDirection{ "inbound": AntispamMailDirectionInbound, @@ -154,6 +197,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -199,6 +255,19 @@ func PossibleValuesForConfidenceLevel() []string { } } +func (s *ConfidenceLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceLevel(input string) (*ConfidenceLevel, error) { vals := map[string]ConfidenceLevel{ "high": ConfidenceLevelHigh, @@ -232,6 +301,19 @@ func PossibleValuesForConfidenceScoreStatus() []string { } } +func (s *ConfidenceScoreStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceScoreStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceScoreStatus(input string) (*ConfidenceScoreStatus, error) { vals := map[string]ConfidenceScoreStatus{ "final": ConfidenceScoreStatusFinal, @@ -266,6 +348,19 @@ func PossibleValuesForCreatedByType() []string { } } +func (s *CreatedByType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCreatedByType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseCreatedByType(input string) (*CreatedByType, error) { vals := map[string]CreatedByType{ "application": CreatedByTypeApplication, @@ -302,6 +397,19 @@ func PossibleValuesForDeliveryAction() []string { } } +func (s *DeliveryAction) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeliveryAction(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDeliveryAction(input string) (*DeliveryAction, error) { vals := map[string]DeliveryAction{ "blocked": DeliveryActionBlocked, @@ -347,6 +455,19 @@ func PossibleValuesForDeliveryLocation() []string { } } +func (s *DeliveryLocation) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeliveryLocation(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDeliveryLocation(input string) (*DeliveryLocation, error) { vals := map[string]DeliveryLocation{ "deletedfolder": DeliveryLocationDeletedFolder, @@ -384,6 +505,19 @@ func PossibleValuesForElevationToken() []string { } } +func (s *ElevationToken) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseElevationToken(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseElevationToken(input string) (*ElevationToken, error) { vals := map[string]ElevationToken{ "default": ElevationTokenDefault, @@ -451,6 +585,19 @@ func PossibleValuesForEntityKindEnum() []string { } } +func (s *EntityKindEnum) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityKindEnum(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityKindEnum(input string) (*EntityKindEnum, error) { vals := map[string]EntityKindEnum{ "account": EntityKindEnumAccount, @@ -504,6 +651,19 @@ func PossibleValuesForFileHashAlgorithm() []string { } } +func (s *FileHashAlgorithm) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseFileHashAlgorithm(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseFileHashAlgorithm(input string) (*FileHashAlgorithm, error) { vals := map[string]FileHashAlgorithm{ "md5": FileHashAlgorithmMDFive, @@ -539,6 +699,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, @@ -593,6 +766,19 @@ func PossibleValuesForKillChainIntent() []string { } } +func (s *KillChainIntent) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKillChainIntent(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseKillChainIntent(input string) (*KillChainIntent, error) { vals := map[string]KillChainIntent{ "collection": KillChainIntentCollection, @@ -639,6 +825,19 @@ func PossibleValuesForOSFamily() []string { } } +func (s *OSFamily) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOSFamily(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseOSFamily(input string) (*OSFamily, error) { vals := map[string]OSFamily{ "android": OSFamilyAndroid, @@ -686,6 +885,19 @@ func PossibleValuesForRegistryHive() []string { } } +func (s *RegistryHive) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRegistryHive(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseRegistryHive(input string) (*RegistryHive, error) { vals := map[string]RegistryHive{ "hkey_a": RegistryHiveHKEYA, @@ -734,6 +946,19 @@ func PossibleValuesForRegistryValueKind() []string { } } +func (s *RegistryValueKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRegistryValueKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseRegistryValueKind(input string) (*RegistryValueKind, error) { vals := map[string]RegistryValueKind{ "binary": RegistryValueKindBinary, diff --git a/resource-manager/securityinsights/2022-08-01/incidentalerts/client.go b/resource-manager/securityinsights/2022-08-01/incidentalerts/client.go index ae19637d473..53dc2b4cd4e 100644 --- a/resource-manager/securityinsights/2022-08-01/incidentalerts/client.go +++ b/resource-manager/securityinsights/2022-08-01/incidentalerts/client.go @@ -1,18 +1,26 @@ package incidentalerts -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type IncidentAlertsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewIncidentAlertsClientWithBaseURI(endpoint string) IncidentAlertsClient { - return IncidentAlertsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewIncidentAlertsClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentAlertsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidentalerts", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentAlertsClient: %+v", err) } + + return &IncidentAlertsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-08-01/incidentalerts/constants.go b/resource-manager/securityinsights/2022-08-01/incidentalerts/constants.go index 8f605bb09d5..3673d5b1163 100644 --- a/resource-manager/securityinsights/2022-08-01/incidentalerts/constants.go +++ b/resource-manager/securityinsights/2022-08-01/incidentalerts/constants.go @@ -1,6 +1,10 @@ package incidentalerts -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -23,6 +27,19 @@ func PossibleValuesForAlertSeverity() []string { } } +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertSeverity(input string) (*AlertSeverity, error) { vals := map[string]AlertSeverity{ "high": AlertSeverityHigh, @@ -59,6 +76,19 @@ func PossibleValuesForAlertStatus() []string { } } +func (s *AlertStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertStatus(input string) (*AlertStatus, error) { vals := map[string]AlertStatus{ "dismissed": AlertStatusDismissed, @@ -120,6 +150,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -165,6 +208,19 @@ func PossibleValuesForConfidenceLevel() []string { } } +func (s *ConfidenceLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceLevel(input string) (*ConfidenceLevel, error) { vals := map[string]ConfidenceLevel{ "high": ConfidenceLevelHigh, @@ -198,6 +254,19 @@ func PossibleValuesForConfidenceScoreStatus() []string { } } +func (s *ConfidenceScoreStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceScoreStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceScoreStatus(input string) (*ConfidenceScoreStatus, error) { vals := map[string]ConfidenceScoreStatus{ "final": ConfidenceScoreStatusFinal, @@ -266,6 +335,19 @@ func PossibleValuesForEntityKindEnum() []string { } } +func (s *EntityKindEnum) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityKindEnum(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityKindEnum(input string) (*EntityKindEnum, error) { vals := map[string]EntityKindEnum{ "account": EntityKindEnumAccount, @@ -317,6 +399,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, @@ -371,6 +466,19 @@ func PossibleValuesForKillChainIntent() []string { } } +func (s *KillChainIntent) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKillChainIntent(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseKillChainIntent(input string) (*KillChainIntent, error) { vals := map[string]KillChainIntent{ "collection": KillChainIntentCollection, diff --git a/resource-manager/securityinsights/2022-08-01/incidentalerts/method_incidentslistalerts.go b/resource-manager/securityinsights/2022-08-01/incidentalerts/method_incidentslistalerts.go new file mode 100644 index 00000000000..fe83693eae2 --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/incidentalerts/method_incidentslistalerts.go @@ -0,0 +1,52 @@ +package incidentalerts + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentsListAlertsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IncidentAlertList +} + +// IncidentsListAlerts ... +func (c IncidentAlertsClient) IncidentsListAlerts(ctx context.Context, id IncidentId) (result IncidentsListAlertsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/alerts", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-08-01/incidentalerts/method_incidentslistalerts_autorest.go b/resource-manager/securityinsights/2022-08-01/incidentalerts/method_incidentslistalerts_autorest.go deleted file mode 100644 index de6c08e09a2..00000000000 --- a/resource-manager/securityinsights/2022-08-01/incidentalerts/method_incidentslistalerts_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package incidentalerts - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IncidentsListAlertsOperationResponse struct { - HttpResponse *http.Response - Model *IncidentAlertList -} - -// IncidentsListAlerts ... -func (c IncidentAlertsClient) IncidentsListAlerts(ctx context.Context, id IncidentId) (result IncidentsListAlertsOperationResponse, err error) { - req, err := c.preparerForIncidentsListAlerts(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentalerts.IncidentAlertsClient", "IncidentsListAlerts", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentalerts.IncidentAlertsClient", "IncidentsListAlerts", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIncidentsListAlerts(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentalerts.IncidentAlertsClient", "IncidentsListAlerts", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIncidentsListAlerts prepares the IncidentsListAlerts request. -func (c IncidentAlertsClient) preparerForIncidentsListAlerts(ctx context.Context, id IncidentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/alerts", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIncidentsListAlerts handles the response to the IncidentsListAlerts request. The method always -// closes the http.Response Body. -func (c IncidentAlertsClient) responderForIncidentsListAlerts(resp *http.Response) (result IncidentsListAlertsOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-08-01/incidentbookmarks/client.go b/resource-manager/securityinsights/2022-08-01/incidentbookmarks/client.go index e2fcca6728b..e6a60ede52d 100644 --- a/resource-manager/securityinsights/2022-08-01/incidentbookmarks/client.go +++ b/resource-manager/securityinsights/2022-08-01/incidentbookmarks/client.go @@ -1,18 +1,26 @@ package incidentbookmarks -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type IncidentBookmarksClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewIncidentBookmarksClientWithBaseURI(endpoint string) IncidentBookmarksClient { - return IncidentBookmarksClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewIncidentBookmarksClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentBookmarksClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidentbookmarks", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentBookmarksClient: %+v", err) } + + return &IncidentBookmarksClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-08-01/incidentbookmarks/constants.go b/resource-manager/securityinsights/2022-08-01/incidentbookmarks/constants.go index 7080e0657bc..27f31cfcc5e 100644 --- a/resource-manager/securityinsights/2022-08-01/incidentbookmarks/constants.go +++ b/resource-manager/securityinsights/2022-08-01/incidentbookmarks/constants.go @@ -1,6 +1,10 @@ package incidentbookmarks -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -23,6 +27,19 @@ func PossibleValuesForAlertSeverity() []string { } } +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertSeverity(input string) (*AlertSeverity, error) { vals := map[string]AlertSeverity{ "high": AlertSeverityHigh, @@ -59,6 +76,19 @@ func PossibleValuesForAlertStatus() []string { } } +func (s *AlertStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertStatus(input string) (*AlertStatus, error) { vals := map[string]AlertStatus{ "dismissed": AlertStatusDismissed, @@ -120,6 +150,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -165,6 +208,19 @@ func PossibleValuesForConfidenceLevel() []string { } } +func (s *ConfidenceLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceLevel(input string) (*ConfidenceLevel, error) { vals := map[string]ConfidenceLevel{ "high": ConfidenceLevelHigh, @@ -198,6 +254,19 @@ func PossibleValuesForConfidenceScoreStatus() []string { } } +func (s *ConfidenceScoreStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceScoreStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceScoreStatus(input string) (*ConfidenceScoreStatus, error) { vals := map[string]ConfidenceScoreStatus{ "final": ConfidenceScoreStatusFinal, @@ -266,6 +335,19 @@ func PossibleValuesForEntityKindEnum() []string { } } +func (s *EntityKindEnum) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityKindEnum(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityKindEnum(input string) (*EntityKindEnum, error) { vals := map[string]EntityKindEnum{ "account": EntityKindEnumAccount, @@ -317,6 +399,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, @@ -371,6 +466,19 @@ func PossibleValuesForKillChainIntent() []string { } } +func (s *KillChainIntent) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKillChainIntent(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseKillChainIntent(input string) (*KillChainIntent, error) { vals := map[string]KillChainIntent{ "collection": KillChainIntentCollection, diff --git a/resource-manager/securityinsights/2022-08-01/incidentbookmarks/method_incidentslistbookmarks.go b/resource-manager/securityinsights/2022-08-01/incidentbookmarks/method_incidentslistbookmarks.go new file mode 100644 index 00000000000..3ac7b9e8b2e --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/incidentbookmarks/method_incidentslistbookmarks.go @@ -0,0 +1,52 @@ +package incidentbookmarks + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentsListBookmarksOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IncidentBookmarkList +} + +// IncidentsListBookmarks ... +func (c IncidentBookmarksClient) IncidentsListBookmarks(ctx context.Context, id IncidentId) (result IncidentsListBookmarksOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/bookmarks", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-08-01/incidentbookmarks/method_incidentslistbookmarks_autorest.go b/resource-manager/securityinsights/2022-08-01/incidentbookmarks/method_incidentslistbookmarks_autorest.go deleted file mode 100644 index a5c3a89a09c..00000000000 --- a/resource-manager/securityinsights/2022-08-01/incidentbookmarks/method_incidentslistbookmarks_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package incidentbookmarks - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IncidentsListBookmarksOperationResponse struct { - HttpResponse *http.Response - Model *IncidentBookmarkList -} - -// IncidentsListBookmarks ... -func (c IncidentBookmarksClient) IncidentsListBookmarks(ctx context.Context, id IncidentId) (result IncidentsListBookmarksOperationResponse, err error) { - req, err := c.preparerForIncidentsListBookmarks(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentbookmarks.IncidentBookmarksClient", "IncidentsListBookmarks", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentbookmarks.IncidentBookmarksClient", "IncidentsListBookmarks", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIncidentsListBookmarks(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentbookmarks.IncidentBookmarksClient", "IncidentsListBookmarks", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIncidentsListBookmarks prepares the IncidentsListBookmarks request. -func (c IncidentBookmarksClient) preparerForIncidentsListBookmarks(ctx context.Context, id IncidentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/bookmarks", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIncidentsListBookmarks handles the response to the IncidentsListBookmarks request. The method always -// closes the http.Response Body. -func (c IncidentBookmarksClient) responderForIncidentsListBookmarks(resp *http.Response) (result IncidentsListBookmarksOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-08-01/incidentcomments/client.go b/resource-manager/securityinsights/2022-08-01/incidentcomments/client.go index 4006779247d..981e6f75216 100644 --- a/resource-manager/securityinsights/2022-08-01/incidentcomments/client.go +++ b/resource-manager/securityinsights/2022-08-01/incidentcomments/client.go @@ -1,18 +1,26 @@ package incidentcomments -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type IncidentCommentsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewIncidentCommentsClientWithBaseURI(endpoint string) IncidentCommentsClient { - return IncidentCommentsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewIncidentCommentsClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentCommentsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidentcomments", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentCommentsClient: %+v", err) } + + return &IncidentCommentsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-08-01/incidentcomments/method_createorupdate.go b/resource-manager/securityinsights/2022-08-01/incidentcomments/method_createorupdate.go new file mode 100644 index 00000000000..5c59b2be8d3 --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/incidentcomments/method_createorupdate.go @@ -0,0 +1,56 @@ +package incidentcomments + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IncidentComment +} + +// CreateOrUpdate ... +func (c IncidentCommentsClient) CreateOrUpdate(ctx context.Context, id CommentId, input IncidentComment) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-08-01/incidentcomments/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-08-01/incidentcomments/method_createorupdate_autorest.go deleted file mode 100644 index b27777aad2c..00000000000 --- a/resource-manager/securityinsights/2022-08-01/incidentcomments/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package incidentcomments - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *IncidentComment -} - -// CreateOrUpdate ... -func (c IncidentCommentsClient) CreateOrUpdate(ctx context.Context, id CommentId, input IncidentComment) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c IncidentCommentsClient) preparerForCreateOrUpdate(ctx context.Context, id CommentId, input IncidentComment) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c IncidentCommentsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-08-01/incidentcomments/method_delete.go b/resource-manager/securityinsights/2022-08-01/incidentcomments/method_delete.go new file mode 100644 index 00000000000..78412a13e76 --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/incidentcomments/method_delete.go @@ -0,0 +1,47 @@ +package incidentcomments + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c IncidentCommentsClient) Delete(ctx context.Context, id CommentId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-08-01/incidentcomments/method_delete_autorest.go b/resource-manager/securityinsights/2022-08-01/incidentcomments/method_delete_autorest.go deleted file mode 100644 index 6bbb4c92cbf..00000000000 --- a/resource-manager/securityinsights/2022-08-01/incidentcomments/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package incidentcomments - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c IncidentCommentsClient) Delete(ctx context.Context, id CommentId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c IncidentCommentsClient) preparerForDelete(ctx context.Context, id CommentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c IncidentCommentsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-08-01/incidentcomments/method_get.go b/resource-manager/securityinsights/2022-08-01/incidentcomments/method_get.go new file mode 100644 index 00000000000..e8d11306ddb --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/incidentcomments/method_get.go @@ -0,0 +1,51 @@ +package incidentcomments + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IncidentComment +} + +// Get ... +func (c IncidentCommentsClient) Get(ctx context.Context, id CommentId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-08-01/incidentcomments/method_get_autorest.go b/resource-manager/securityinsights/2022-08-01/incidentcomments/method_get_autorest.go deleted file mode 100644 index 8402ed77e94..00000000000 --- a/resource-manager/securityinsights/2022-08-01/incidentcomments/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package incidentcomments - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *IncidentComment -} - -// Get ... -func (c IncidentCommentsClient) Get(ctx context.Context, id CommentId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c IncidentCommentsClient) preparerForGet(ctx context.Context, id CommentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c IncidentCommentsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-08-01/incidentcomments/method_list.go b/resource-manager/securityinsights/2022-08-01/incidentcomments/method_list.go new file mode 100644 index 00000000000..b4c16058b38 --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/incidentcomments/method_list.go @@ -0,0 +1,127 @@ +package incidentcomments + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]IncidentComment +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []IncidentComment +} + +type ListOperationOptions struct { + Filter *string + Orderby *string + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c IncidentCommentsClient) List(ctx context.Context, id IncidentId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/comments", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]IncidentComment `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c IncidentCommentsClient) ListComplete(ctx context.Context, id IncidentId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, IncidentCommentOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c IncidentCommentsClient) ListCompleteMatchingPredicate(ctx context.Context, id IncidentId, options ListOperationOptions, predicate IncidentCommentOperationPredicate) (result ListCompleteResult, err error) { + items := make([]IncidentComment, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-08-01/incidentcomments/method_list_autorest.go b/resource-manager/securityinsights/2022-08-01/incidentcomments/method_list_autorest.go deleted file mode 100644 index 24fb8d1d7e7..00000000000 --- a/resource-manager/securityinsights/2022-08-01/incidentcomments/method_list_autorest.go +++ /dev/null @@ -1,225 +0,0 @@ -package incidentcomments - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]IncidentComment - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []IncidentComment -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ListOperationOptions struct { - Filter *string - Orderby *string - Top *int64 -} - -func DefaultListOperationOptions() ListOperationOptions { - return ListOperationOptions{} -} - -func (o ListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Filter != nil { - out["$filter"] = *o.Filter - } - - if o.Orderby != nil { - out["$orderby"] = *o.Orderby - } - - if o.Top != nil { - out["$top"] = *o.Top - } - - return out -} - -// List ... -func (c IncidentCommentsClient) List(ctx context.Context, id IncidentId, options ListOperationOptions) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c IncidentCommentsClient) preparerForList(ctx context.Context, id IncidentId, options ListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/comments", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c IncidentCommentsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c IncidentCommentsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []IncidentComment `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c IncidentCommentsClient) ListComplete(ctx context.Context, id IncidentId, options ListOperationOptions) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, options, IncidentCommentOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c IncidentCommentsClient) ListCompleteMatchingPredicate(ctx context.Context, id IncidentId, options ListOperationOptions, predicate IncidentCommentOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]IncidentComment, 0) - - page, err := c.List(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-08-01/incidententities/client.go b/resource-manager/securityinsights/2022-08-01/incidententities/client.go index 5f0eaf07782..740e7b81755 100644 --- a/resource-manager/securityinsights/2022-08-01/incidententities/client.go +++ b/resource-manager/securityinsights/2022-08-01/incidententities/client.go @@ -1,18 +1,26 @@ package incidententities -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type IncidentEntitiesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewIncidentEntitiesClientWithBaseURI(endpoint string) IncidentEntitiesClient { - return IncidentEntitiesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewIncidentEntitiesClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentEntitiesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidententities", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentEntitiesClient: %+v", err) } + + return &IncidentEntitiesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-08-01/incidententities/constants.go b/resource-manager/securityinsights/2022-08-01/incidententities/constants.go index cb1b487a229..a1d54eb28d0 100644 --- a/resource-manager/securityinsights/2022-08-01/incidententities/constants.go +++ b/resource-manager/securityinsights/2022-08-01/incidententities/constants.go @@ -1,6 +1,10 @@ package incidententities -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -23,6 +27,19 @@ func PossibleValuesForAlertSeverity() []string { } } +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertSeverity(input string) (*AlertSeverity, error) { vals := map[string]AlertSeverity{ "high": AlertSeverityHigh, @@ -59,6 +76,19 @@ func PossibleValuesForAlertStatus() []string { } } +func (s *AlertStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertStatus(input string) (*AlertStatus, error) { vals := map[string]AlertStatus{ "dismissed": AlertStatusDismissed, @@ -120,6 +150,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -165,6 +208,19 @@ func PossibleValuesForConfidenceLevel() []string { } } +func (s *ConfidenceLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceLevel(input string) (*ConfidenceLevel, error) { vals := map[string]ConfidenceLevel{ "high": ConfidenceLevelHigh, @@ -198,6 +254,19 @@ func PossibleValuesForConfidenceScoreStatus() []string { } } +func (s *ConfidenceScoreStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceScoreStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceScoreStatus(input string) (*ConfidenceScoreStatus, error) { vals := map[string]ConfidenceScoreStatus{ "final": ConfidenceScoreStatusFinal, @@ -266,6 +335,19 @@ func PossibleValuesForEntityKindEnum() []string { } } +func (s *EntityKindEnum) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityKindEnum(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityKindEnum(input string) (*EntityKindEnum, error) { vals := map[string]EntityKindEnum{ "account": EntityKindEnumAccount, @@ -317,6 +399,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, @@ -371,6 +466,19 @@ func PossibleValuesForKillChainIntent() []string { } } +func (s *KillChainIntent) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKillChainIntent(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseKillChainIntent(input string) (*KillChainIntent, error) { vals := map[string]KillChainIntent{ "collection": KillChainIntentCollection, diff --git a/resource-manager/securityinsights/2022-08-01/incidententities/method_incidentslistentities.go b/resource-manager/securityinsights/2022-08-01/incidententities/method_incidentslistentities.go new file mode 100644 index 00000000000..36ec8f0c75b --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/incidententities/method_incidentslistentities.go @@ -0,0 +1,52 @@ +package incidententities + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentsListEntitiesOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IncidentEntitiesResponse +} + +// IncidentsListEntities ... +func (c IncidentEntitiesClient) IncidentsListEntities(ctx context.Context, id IncidentId) (result IncidentsListEntitiesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/entities", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-08-01/incidententities/method_incidentslistentities_autorest.go b/resource-manager/securityinsights/2022-08-01/incidententities/method_incidentslistentities_autorest.go deleted file mode 100644 index 9d796d431cb..00000000000 --- a/resource-manager/securityinsights/2022-08-01/incidententities/method_incidentslistentities_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package incidententities - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IncidentsListEntitiesOperationResponse struct { - HttpResponse *http.Response - Model *IncidentEntitiesResponse -} - -// IncidentsListEntities ... -func (c IncidentEntitiesClient) IncidentsListEntities(ctx context.Context, id IncidentId) (result IncidentsListEntitiesOperationResponse, err error) { - req, err := c.preparerForIncidentsListEntities(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidententities.IncidentEntitiesClient", "IncidentsListEntities", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidententities.IncidentEntitiesClient", "IncidentsListEntities", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIncidentsListEntities(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidententities.IncidentEntitiesClient", "IncidentsListEntities", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIncidentsListEntities prepares the IncidentsListEntities request. -func (c IncidentEntitiesClient) preparerForIncidentsListEntities(ctx context.Context, id IncidentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/entities", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIncidentsListEntities handles the response to the IncidentsListEntities request. The method always -// closes the http.Response Body. -func (c IncidentEntitiesClient) responderForIncidentsListEntities(resp *http.Response) (result IncidentsListEntitiesOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-08-01/incidentrelations/client.go b/resource-manager/securityinsights/2022-08-01/incidentrelations/client.go index 58aa27c43e8..4e8fbfeb71d 100644 --- a/resource-manager/securityinsights/2022-08-01/incidentrelations/client.go +++ b/resource-manager/securityinsights/2022-08-01/incidentrelations/client.go @@ -1,18 +1,26 @@ package incidentrelations -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type IncidentRelationsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewIncidentRelationsClientWithBaseURI(endpoint string) IncidentRelationsClient { - return IncidentRelationsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewIncidentRelationsClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentRelationsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidentrelations", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentRelationsClient: %+v", err) } + + return &IncidentRelationsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-08-01/incidentrelations/method_createorupdate.go b/resource-manager/securityinsights/2022-08-01/incidentrelations/method_createorupdate.go new file mode 100644 index 00000000000..4b4ff3d56f8 --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/incidentrelations/method_createorupdate.go @@ -0,0 +1,56 @@ +package incidentrelations + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Relation +} + +// CreateOrUpdate ... +func (c IncidentRelationsClient) CreateOrUpdate(ctx context.Context, id RelationId, input Relation) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-08-01/incidentrelations/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-08-01/incidentrelations/method_createorupdate_autorest.go deleted file mode 100644 index 79cf52b5347..00000000000 --- a/resource-manager/securityinsights/2022-08-01/incidentrelations/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package incidentrelations - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *Relation -} - -// CreateOrUpdate ... -func (c IncidentRelationsClient) CreateOrUpdate(ctx context.Context, id RelationId, input Relation) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c IncidentRelationsClient) preparerForCreateOrUpdate(ctx context.Context, id RelationId, input Relation) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c IncidentRelationsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-08-01/incidentrelations/method_delete.go b/resource-manager/securityinsights/2022-08-01/incidentrelations/method_delete.go new file mode 100644 index 00000000000..de3afbf47c9 --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/incidentrelations/method_delete.go @@ -0,0 +1,47 @@ +package incidentrelations + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c IncidentRelationsClient) Delete(ctx context.Context, id RelationId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-08-01/incidentrelations/method_delete_autorest.go b/resource-manager/securityinsights/2022-08-01/incidentrelations/method_delete_autorest.go deleted file mode 100644 index 9003689e999..00000000000 --- a/resource-manager/securityinsights/2022-08-01/incidentrelations/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package incidentrelations - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c IncidentRelationsClient) Delete(ctx context.Context, id RelationId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c IncidentRelationsClient) preparerForDelete(ctx context.Context, id RelationId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c IncidentRelationsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-08-01/incidentrelations/method_get.go b/resource-manager/securityinsights/2022-08-01/incidentrelations/method_get.go new file mode 100644 index 00000000000..7cc37b68825 --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/incidentrelations/method_get.go @@ -0,0 +1,51 @@ +package incidentrelations + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Relation +} + +// Get ... +func (c IncidentRelationsClient) Get(ctx context.Context, id RelationId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-08-01/incidentrelations/method_get_autorest.go b/resource-manager/securityinsights/2022-08-01/incidentrelations/method_get_autorest.go deleted file mode 100644 index a8b88ddecb4..00000000000 --- a/resource-manager/securityinsights/2022-08-01/incidentrelations/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package incidentrelations - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *Relation -} - -// Get ... -func (c IncidentRelationsClient) Get(ctx context.Context, id RelationId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c IncidentRelationsClient) preparerForGet(ctx context.Context, id RelationId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c IncidentRelationsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-08-01/incidentrelations/method_list.go b/resource-manager/securityinsights/2022-08-01/incidentrelations/method_list.go new file mode 100644 index 00000000000..80873d441b4 --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/incidentrelations/method_list.go @@ -0,0 +1,127 @@ +package incidentrelations + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Relation +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Relation +} + +type ListOperationOptions struct { + Filter *string + Orderby *string + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c IncidentRelationsClient) List(ctx context.Context, id IncidentId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/relations", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Relation `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c IncidentRelationsClient) ListComplete(ctx context.Context, id IncidentId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, RelationOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c IncidentRelationsClient) ListCompleteMatchingPredicate(ctx context.Context, id IncidentId, options ListOperationOptions, predicate RelationOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Relation, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-08-01/incidentrelations/method_list_autorest.go b/resource-manager/securityinsights/2022-08-01/incidentrelations/method_list_autorest.go deleted file mode 100644 index a270a442886..00000000000 --- a/resource-manager/securityinsights/2022-08-01/incidentrelations/method_list_autorest.go +++ /dev/null @@ -1,225 +0,0 @@ -package incidentrelations - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]Relation - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []Relation -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ListOperationOptions struct { - Filter *string - Orderby *string - Top *int64 -} - -func DefaultListOperationOptions() ListOperationOptions { - return ListOperationOptions{} -} - -func (o ListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Filter != nil { - out["$filter"] = *o.Filter - } - - if o.Orderby != nil { - out["$orderby"] = *o.Orderby - } - - if o.Top != nil { - out["$top"] = *o.Top - } - - return out -} - -// List ... -func (c IncidentRelationsClient) List(ctx context.Context, id IncidentId, options ListOperationOptions) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c IncidentRelationsClient) preparerForList(ctx context.Context, id IncidentId, options ListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/relations", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c IncidentRelationsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c IncidentRelationsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []Relation `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c IncidentRelationsClient) ListComplete(ctx context.Context, id IncidentId, options ListOperationOptions) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, options, RelationOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c IncidentRelationsClient) ListCompleteMatchingPredicate(ctx context.Context, id IncidentId, options ListOperationOptions, predicate RelationOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]Relation, 0) - - page, err := c.List(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-08-01/incidents/client.go b/resource-manager/securityinsights/2022-08-01/incidents/client.go index 659897d18d7..aaf38071c39 100644 --- a/resource-manager/securityinsights/2022-08-01/incidents/client.go +++ b/resource-manager/securityinsights/2022-08-01/incidents/client.go @@ -1,18 +1,26 @@ package incidents -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type IncidentsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewIncidentsClientWithBaseURI(endpoint string) IncidentsClient { - return IncidentsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewIncidentsClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidents", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentsClient: %+v", err) } + + return &IncidentsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-08-01/incidents/constants.go b/resource-manager/securityinsights/2022-08-01/incidents/constants.go index 82782d4107f..ce046b9edba 100644 --- a/resource-manager/securityinsights/2022-08-01/incidents/constants.go +++ b/resource-manager/securityinsights/2022-08-01/incidents/constants.go @@ -1,6 +1,10 @@ package incidents -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -49,6 +53,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -96,6 +113,19 @@ func PossibleValuesForIncidentClassification() []string { } } +func (s *IncidentClassification) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentClassification(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentClassification(input string) (*IncidentClassification, error) { vals := map[string]IncidentClassification{ "benignpositive": IncidentClassificationBenignPositive, @@ -130,6 +160,19 @@ func PossibleValuesForIncidentClassificationReason() []string { } } +func (s *IncidentClassificationReason) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentClassificationReason(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentClassificationReason(input string) (*IncidentClassificationReason, error) { vals := map[string]IncidentClassificationReason{ "inaccuratedata": IncidentClassificationReasonInaccurateData, @@ -160,6 +203,19 @@ func PossibleValuesForIncidentLabelType() []string { } } +func (s *IncidentLabelType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentLabelType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentLabelType(input string) (*IncidentLabelType, error) { vals := map[string]IncidentLabelType{ "autoassigned": IncidentLabelTypeAutoAssigned, @@ -192,6 +248,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, @@ -224,6 +293,19 @@ func PossibleValuesForIncidentStatus() []string { } } +func (s *IncidentStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentStatus(input string) (*IncidentStatus, error) { vals := map[string]IncidentStatus{ "active": IncidentStatusActive, @@ -255,6 +337,19 @@ func PossibleValuesForOwnerType() []string { } } +func (s *OwnerType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOwnerType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseOwnerType(input string) (*OwnerType, error) { vals := map[string]OwnerType{ "group": OwnerTypeGroup, diff --git a/resource-manager/securityinsights/2022-08-01/incidents/method_createorupdate.go b/resource-manager/securityinsights/2022-08-01/incidents/method_createorupdate.go new file mode 100644 index 00000000000..3fcc110ed02 --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/incidents/method_createorupdate.go @@ -0,0 +1,56 @@ +package incidents + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Incident +} + +// CreateOrUpdate ... +func (c IncidentsClient) CreateOrUpdate(ctx context.Context, id IncidentId, input Incident) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-08-01/incidents/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-08-01/incidents/method_createorupdate_autorest.go deleted file mode 100644 index 837aa7c92a0..00000000000 --- a/resource-manager/securityinsights/2022-08-01/incidents/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package incidents - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *Incident -} - -// CreateOrUpdate ... -func (c IncidentsClient) CreateOrUpdate(ctx context.Context, id IncidentId, input Incident) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c IncidentsClient) preparerForCreateOrUpdate(ctx context.Context, id IncidentId, input Incident) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c IncidentsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-08-01/incidents/method_delete.go b/resource-manager/securityinsights/2022-08-01/incidents/method_delete.go new file mode 100644 index 00000000000..9b3205af5fc --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/incidents/method_delete.go @@ -0,0 +1,47 @@ +package incidents + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c IncidentsClient) Delete(ctx context.Context, id IncidentId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-08-01/incidents/method_delete_autorest.go b/resource-manager/securityinsights/2022-08-01/incidents/method_delete_autorest.go deleted file mode 100644 index 280832422f8..00000000000 --- a/resource-manager/securityinsights/2022-08-01/incidents/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package incidents - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c IncidentsClient) Delete(ctx context.Context, id IncidentId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c IncidentsClient) preparerForDelete(ctx context.Context, id IncidentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c IncidentsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-08-01/incidents/method_get.go b/resource-manager/securityinsights/2022-08-01/incidents/method_get.go new file mode 100644 index 00000000000..e6d4e9e933b --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/incidents/method_get.go @@ -0,0 +1,51 @@ +package incidents + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Incident +} + +// Get ... +func (c IncidentsClient) Get(ctx context.Context, id IncidentId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-08-01/incidents/method_get_autorest.go b/resource-manager/securityinsights/2022-08-01/incidents/method_get_autorest.go deleted file mode 100644 index d8d2b7debeb..00000000000 --- a/resource-manager/securityinsights/2022-08-01/incidents/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package incidents - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *Incident -} - -// Get ... -func (c IncidentsClient) Get(ctx context.Context, id IncidentId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c IncidentsClient) preparerForGet(ctx context.Context, id IncidentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c IncidentsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-08-01/incidents/method_list.go b/resource-manager/securityinsights/2022-08-01/incidents/method_list.go new file mode 100644 index 00000000000..fe19cd4d9ff --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/incidents/method_list.go @@ -0,0 +1,127 @@ +package incidents + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Incident +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Incident +} + +type ListOperationOptions struct { + Filter *string + Orderby *string + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c IncidentsClient) List(ctx context.Context, id WorkspaceId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/incidents", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Incident `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c IncidentsClient) ListComplete(ctx context.Context, id WorkspaceId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, IncidentOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c IncidentsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ListOperationOptions, predicate IncidentOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Incident, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-08-01/incidents/method_list_autorest.go b/resource-manager/securityinsights/2022-08-01/incidents/method_list_autorest.go deleted file mode 100644 index 8d2f5acc547..00000000000 --- a/resource-manager/securityinsights/2022-08-01/incidents/method_list_autorest.go +++ /dev/null @@ -1,225 +0,0 @@ -package incidents - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]Incident - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []Incident -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ListOperationOptions struct { - Filter *string - Orderby *string - Top *int64 -} - -func DefaultListOperationOptions() ListOperationOptions { - return ListOperationOptions{} -} - -func (o ListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Filter != nil { - out["$filter"] = *o.Filter - } - - if o.Orderby != nil { - out["$orderby"] = *o.Orderby - } - - if o.Top != nil { - out["$top"] = *o.Top - } - - return out -} - -// List ... -func (c IncidentsClient) List(ctx context.Context, id WorkspaceId, options ListOperationOptions) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c IncidentsClient) preparerForList(ctx context.Context, id WorkspaceId, options ListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/incidents", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c IncidentsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c IncidentsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []Incident `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c IncidentsClient) ListComplete(ctx context.Context, id WorkspaceId, options ListOperationOptions) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, options, IncidentOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c IncidentsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ListOperationOptions, predicate IncidentOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]Incident, 0) - - page, err := c.List(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-08-01/sentinelonboardingstates/client.go b/resource-manager/securityinsights/2022-08-01/sentinelonboardingstates/client.go index 0ae442ba3fa..94701ed853a 100644 --- a/resource-manager/securityinsights/2022-08-01/sentinelonboardingstates/client.go +++ b/resource-manager/securityinsights/2022-08-01/sentinelonboardingstates/client.go @@ -1,18 +1,26 @@ package sentinelonboardingstates -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type SentinelOnboardingStatesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewSentinelOnboardingStatesClientWithBaseURI(endpoint string) SentinelOnboardingStatesClient { - return SentinelOnboardingStatesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewSentinelOnboardingStatesClientWithBaseURI(sdkApi sdkEnv.Api) (*SentinelOnboardingStatesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sentinelonboardingstates", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SentinelOnboardingStatesClient: %+v", err) } + + return &SentinelOnboardingStatesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-08-01/sentinelonboardingstates/method_create.go b/resource-manager/securityinsights/2022-08-01/sentinelonboardingstates/method_create.go new file mode 100644 index 00000000000..af163a9d66b --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/sentinelonboardingstates/method_create.go @@ -0,0 +1,56 @@ +package sentinelonboardingstates + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SentinelOnboardingState +} + +// Create ... +func (c SentinelOnboardingStatesClient) Create(ctx context.Context, id OnboardingStateId, input SentinelOnboardingState) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-08-01/sentinelonboardingstates/method_create_autorest.go b/resource-manager/securityinsights/2022-08-01/sentinelonboardingstates/method_create_autorest.go deleted file mode 100644 index 9ad88e95157..00000000000 --- a/resource-manager/securityinsights/2022-08-01/sentinelonboardingstates/method_create_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package sentinelonboardingstates - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOperationResponse struct { - HttpResponse *http.Response - Model *SentinelOnboardingState -} - -// Create ... -func (c SentinelOnboardingStatesClient) Create(ctx context.Context, id OnboardingStateId, input SentinelOnboardingState) (result CreateOperationResponse, err error) { - req, err := c.preparerForCreate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Create", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Create", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Create", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreate prepares the Create request. -func (c SentinelOnboardingStatesClient) preparerForCreate(ctx context.Context, id OnboardingStateId, input SentinelOnboardingState) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreate handles the response to the Create request. The method always -// closes the http.Response Body. -func (c SentinelOnboardingStatesClient) responderForCreate(resp *http.Response) (result CreateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-08-01/sentinelonboardingstates/method_delete.go b/resource-manager/securityinsights/2022-08-01/sentinelonboardingstates/method_delete.go new file mode 100644 index 00000000000..1c6c5e372d7 --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/sentinelonboardingstates/method_delete.go @@ -0,0 +1,47 @@ +package sentinelonboardingstates + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c SentinelOnboardingStatesClient) Delete(ctx context.Context, id OnboardingStateId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-08-01/sentinelonboardingstates/method_delete_autorest.go b/resource-manager/securityinsights/2022-08-01/sentinelonboardingstates/method_delete_autorest.go deleted file mode 100644 index 65fa74282f7..00000000000 --- a/resource-manager/securityinsights/2022-08-01/sentinelonboardingstates/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package sentinelonboardingstates - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c SentinelOnboardingStatesClient) Delete(ctx context.Context, id OnboardingStateId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c SentinelOnboardingStatesClient) preparerForDelete(ctx context.Context, id OnboardingStateId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c SentinelOnboardingStatesClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-08-01/sentinelonboardingstates/method_get.go b/resource-manager/securityinsights/2022-08-01/sentinelonboardingstates/method_get.go new file mode 100644 index 00000000000..82165662910 --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/sentinelonboardingstates/method_get.go @@ -0,0 +1,51 @@ +package sentinelonboardingstates + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SentinelOnboardingState +} + +// Get ... +func (c SentinelOnboardingStatesClient) Get(ctx context.Context, id OnboardingStateId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-08-01/sentinelonboardingstates/method_get_autorest.go b/resource-manager/securityinsights/2022-08-01/sentinelonboardingstates/method_get_autorest.go deleted file mode 100644 index d6174a7522a..00000000000 --- a/resource-manager/securityinsights/2022-08-01/sentinelonboardingstates/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package sentinelonboardingstates - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *SentinelOnboardingState -} - -// Get ... -func (c SentinelOnboardingStatesClient) Get(ctx context.Context, id OnboardingStateId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c SentinelOnboardingStatesClient) preparerForGet(ctx context.Context, id OnboardingStateId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c SentinelOnboardingStatesClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-08-01/sentinelonboardingstates/method_list.go b/resource-manager/securityinsights/2022-08-01/sentinelonboardingstates/method_list.go new file mode 100644 index 00000000000..2efd1d41230 --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/sentinelonboardingstates/method_list.go @@ -0,0 +1,52 @@ +package sentinelonboardingstates + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SentinelOnboardingStatesList +} + +// List ... +func (c SentinelOnboardingStatesClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/onboardingStates", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-08-01/sentinelonboardingstates/method_list_autorest.go b/resource-manager/securityinsights/2022-08-01/sentinelonboardingstates/method_list_autorest.go deleted file mode 100644 index 6a00bb3d3fd..00000000000 --- a/resource-manager/securityinsights/2022-08-01/sentinelonboardingstates/method_list_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package sentinelonboardingstates - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *SentinelOnboardingStatesList -} - -// List ... -func (c SentinelOnboardingStatesClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForList prepares the List request. -func (c SentinelOnboardingStatesClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/onboardingStates", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c SentinelOnboardingStatesClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-08-01/threatintelligence/client.go b/resource-manager/securityinsights/2022-08-01/threatintelligence/client.go index 35caff31357..edf96c3143f 100644 --- a/resource-manager/securityinsights/2022-08-01/threatintelligence/client.go +++ b/resource-manager/securityinsights/2022-08-01/threatintelligence/client.go @@ -1,18 +1,26 @@ package threatintelligence -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type ThreatIntelligenceClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewThreatIntelligenceClientWithBaseURI(endpoint string) ThreatIntelligenceClient { - return ThreatIntelligenceClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewThreatIntelligenceClientWithBaseURI(sdkApi sdkEnv.Api) (*ThreatIntelligenceClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "threatintelligence", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ThreatIntelligenceClient: %+v", err) } + + return &ThreatIntelligenceClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-08-01/threatintelligence/constants.go b/resource-manager/securityinsights/2022-08-01/threatintelligence/constants.go index 76610b31101..8cef3ba3f75 100644 --- a/resource-manager/securityinsights/2022-08-01/threatintelligence/constants.go +++ b/resource-manager/securityinsights/2022-08-01/threatintelligence/constants.go @@ -1,6 +1,10 @@ package threatintelligence -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -17,6 +21,19 @@ func PossibleValuesForThreatIntelligenceResourceInnerKind() []string { } } +func (s *ThreatIntelligenceResourceInnerKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseThreatIntelligenceResourceInnerKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseThreatIntelligenceResourceInnerKind(input string) (*ThreatIntelligenceResourceInnerKind, error) { vals := map[string]ThreatIntelligenceResourceInnerKind{ "indicator": ThreatIntelligenceResourceInnerKindIndicator, @@ -46,6 +63,19 @@ func PossibleValuesForThreatIntelligenceSortingOrder() []string { } } +func (s *ThreatIntelligenceSortingOrder) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseThreatIntelligenceSortingOrder(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseThreatIntelligenceSortingOrder(input string) (*ThreatIntelligenceSortingOrder, error) { vals := map[string]ThreatIntelligenceSortingOrder{ "ascending": ThreatIntelligenceSortingOrderAscending, diff --git a/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatorappendtags.go b/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatorappendtags.go new file mode 100644 index 00000000000..4384327485d --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatorappendtags.go @@ -0,0 +1,51 @@ +package threatintelligence + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorAppendTagsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// IndicatorAppendTags ... +func (c ThreatIntelligenceClient) IndicatorAppendTags(ctx context.Context, id IndicatorId, input ThreatIntelligenceAppendTags) (result IndicatorAppendTagsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/appendTags", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatorappendtags_autorest.go b/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatorappendtags_autorest.go deleted file mode 100644 index 18b86a166fe..00000000000 --- a/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatorappendtags_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package threatintelligence - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorAppendTagsOperationResponse struct { - HttpResponse *http.Response -} - -// IndicatorAppendTags ... -func (c ThreatIntelligenceClient) IndicatorAppendTags(ctx context.Context, id IndicatorId, input ThreatIntelligenceAppendTags) (result IndicatorAppendTagsOperationResponse, err error) { - req, err := c.preparerForIndicatorAppendTags(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorAppendTags", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorAppendTags", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorAppendTags(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorAppendTags", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorAppendTags prepares the IndicatorAppendTags request. -func (c ThreatIntelligenceClient) preparerForIndicatorAppendTags(ctx context.Context, id IndicatorId, input ThreatIntelligenceAppendTags) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/appendTags", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorAppendTags handles the response to the IndicatorAppendTags request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorAppendTags(resp *http.Response) (result IndicatorAppendTagsOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatorcreate.go b/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatorcreate.go new file mode 100644 index 00000000000..3cee598931c --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatorcreate.go @@ -0,0 +1,63 @@ +package threatintelligence + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorCreateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ThreatIntelligenceInformation +} + +// IndicatorCreate ... +func (c ThreatIntelligenceClient) IndicatorCreate(ctx context.Context, id IndicatorId, input ThreatIntelligenceIndicatorModel) (result IndicatorCreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatorcreate_autorest.go b/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatorcreate_autorest.go deleted file mode 100644 index 98609062b7f..00000000000 --- a/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatorcreate_autorest.go +++ /dev/null @@ -1,78 +0,0 @@ -package threatintelligence - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorCreateOperationResponse struct { - HttpResponse *http.Response - Model *ThreatIntelligenceInformation -} - -// IndicatorCreate ... -func (c ThreatIntelligenceClient) IndicatorCreate(ctx context.Context, id IndicatorId, input ThreatIntelligenceIndicatorModel) (result IndicatorCreateOperationResponse, err error) { - req, err := c.preparerForIndicatorCreate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorCreate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorCreate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorCreate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorCreate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorCreate prepares the IndicatorCreate request. -func (c ThreatIntelligenceClient) preparerForIndicatorCreate(ctx context.Context, id IndicatorId, input ThreatIntelligenceIndicatorModel) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorCreate handles the response to the IndicatorCreate request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorCreate(resp *http.Response) (result IndicatorCreateOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatorcreateindicator.go b/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatorcreateindicator.go new file mode 100644 index 00000000000..0f3ab94c4f5 --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatorcreateindicator.go @@ -0,0 +1,63 @@ +package threatintelligence + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorCreateIndicatorOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ThreatIntelligenceInformation +} + +// IndicatorCreateIndicator ... +func (c ThreatIntelligenceClient) IndicatorCreateIndicator(ctx context.Context, id WorkspaceId, input ThreatIntelligenceIndicatorModel) (result IndicatorCreateIndicatorOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/createIndicator", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatorcreateindicator_autorest.go b/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatorcreateindicator_autorest.go deleted file mode 100644 index ecc76b88f5c..00000000000 --- a/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatorcreateindicator_autorest.go +++ /dev/null @@ -1,79 +0,0 @@ -package threatintelligence - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorCreateIndicatorOperationResponse struct { - HttpResponse *http.Response - Model *ThreatIntelligenceInformation -} - -// IndicatorCreateIndicator ... -func (c ThreatIntelligenceClient) IndicatorCreateIndicator(ctx context.Context, id WorkspaceId, input ThreatIntelligenceIndicatorModel) (result IndicatorCreateIndicatorOperationResponse, err error) { - req, err := c.preparerForIndicatorCreateIndicator(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorCreateIndicator", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorCreateIndicator", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorCreateIndicator(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorCreateIndicator", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorCreateIndicator prepares the IndicatorCreateIndicator request. -func (c ThreatIntelligenceClient) preparerForIndicatorCreateIndicator(ctx context.Context, id WorkspaceId, input ThreatIntelligenceIndicatorModel) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/createIndicator", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorCreateIndicator handles the response to the IndicatorCreateIndicator request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorCreateIndicator(resp *http.Response) (result IndicatorCreateIndicatorOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatordelete.go b/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatordelete.go new file mode 100644 index 00000000000..4de264524d5 --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatordelete.go @@ -0,0 +1,47 @@ +package threatintelligence + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// IndicatorDelete ... +func (c ThreatIntelligenceClient) IndicatorDelete(ctx context.Context, id IndicatorId) (result IndicatorDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatordelete_autorest.go b/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatordelete_autorest.go deleted file mode 100644 index 825d3b911ce..00000000000 --- a/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatordelete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package threatintelligence - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorDeleteOperationResponse struct { - HttpResponse *http.Response -} - -// IndicatorDelete ... -func (c ThreatIntelligenceClient) IndicatorDelete(ctx context.Context, id IndicatorId) (result IndicatorDeleteOperationResponse, err error) { - req, err := c.preparerForIndicatorDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorDelete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorDelete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorDelete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorDelete prepares the IndicatorDelete request. -func (c ThreatIntelligenceClient) preparerForIndicatorDelete(ctx context.Context, id IndicatorId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorDelete handles the response to the IndicatorDelete request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorDelete(resp *http.Response) (result IndicatorDeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatorget.go b/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatorget.go new file mode 100644 index 00000000000..3358363f139 --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatorget.go @@ -0,0 +1,58 @@ +package threatintelligence + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ThreatIntelligenceInformation +} + +// IndicatorGet ... +func (c ThreatIntelligenceClient) IndicatorGet(ctx context.Context, id IndicatorId) (result IndicatorGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatorget_autorest.go b/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatorget_autorest.go deleted file mode 100644 index ac1187fb285..00000000000 --- a/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatorget_autorest.go +++ /dev/null @@ -1,77 +0,0 @@ -package threatintelligence - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorGetOperationResponse struct { - HttpResponse *http.Response - Model *ThreatIntelligenceInformation -} - -// IndicatorGet ... -func (c ThreatIntelligenceClient) IndicatorGet(ctx context.Context, id IndicatorId) (result IndicatorGetOperationResponse, err error) { - req, err := c.preparerForIndicatorGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorGet", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorGet", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorGet", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorGet prepares the IndicatorGet request. -func (c ThreatIntelligenceClient) preparerForIndicatorGet(ctx context.Context, id IndicatorId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorGet handles the response to the IndicatorGet request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorGet(resp *http.Response) (result IndicatorGetOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatormetricslist.go b/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatormetricslist.go new file mode 100644 index 00000000000..688ff3c16d1 --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatormetricslist.go @@ -0,0 +1,52 @@ +package threatintelligence + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorMetricsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ThreatIntelligenceMetricsList +} + +// IndicatorMetricsList ... +func (c ThreatIntelligenceClient) IndicatorMetricsList(ctx context.Context, id WorkspaceId) (result IndicatorMetricsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/metrics", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatormetricslist_autorest.go b/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatormetricslist_autorest.go deleted file mode 100644 index 1835c26ed96..00000000000 --- a/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatormetricslist_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package threatintelligence - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorMetricsListOperationResponse struct { - HttpResponse *http.Response - Model *ThreatIntelligenceMetricsList -} - -// IndicatorMetricsList ... -func (c ThreatIntelligenceClient) IndicatorMetricsList(ctx context.Context, id WorkspaceId) (result IndicatorMetricsListOperationResponse, err error) { - req, err := c.preparerForIndicatorMetricsList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorMetricsList", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorMetricsList", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorMetricsList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorMetricsList", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorMetricsList prepares the IndicatorMetricsList request. -func (c ThreatIntelligenceClient) preparerForIndicatorMetricsList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/metrics", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorMetricsList handles the response to the IndicatorMetricsList request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorMetricsList(resp *http.Response) (result IndicatorMetricsListOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatorqueryindicators.go b/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatorqueryindicators.go new file mode 100644 index 00000000000..8ce639f2623 --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatorqueryindicators.go @@ -0,0 +1,103 @@ +package threatintelligence + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorQueryIndicatorsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ThreatIntelligenceInformation +} + +type IndicatorQueryIndicatorsCompleteResult struct { + LatestHttpResponse *http.Response + Items []ThreatIntelligenceInformation +} + +// IndicatorQueryIndicators ... +func (c ThreatIntelligenceClient) IndicatorQueryIndicators(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria) (result IndicatorQueryIndicatorsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/queryIndicators", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]ThreatIntelligenceInformation, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalThreatIntelligenceInformationImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for ThreatIntelligenceInformation (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// IndicatorQueryIndicatorsComplete retrieves all the results into a single object +func (c ThreatIntelligenceClient) IndicatorQueryIndicatorsComplete(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria) (IndicatorQueryIndicatorsCompleteResult, error) { + return c.IndicatorQueryIndicatorsCompleteMatchingPredicate(ctx, id, input, ThreatIntelligenceInformationOperationPredicate{}) +} + +// IndicatorQueryIndicatorsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ThreatIntelligenceClient) IndicatorQueryIndicatorsCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria, predicate ThreatIntelligenceInformationOperationPredicate) (result IndicatorQueryIndicatorsCompleteResult, err error) { + items := make([]ThreatIntelligenceInformation, 0) + + resp, err := c.IndicatorQueryIndicators(ctx, id, input) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = IndicatorQueryIndicatorsCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatorqueryindicators_autorest.go b/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatorqueryindicators_autorest.go deleted file mode 100644 index fcbe7c74758..00000000000 --- a/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatorqueryindicators_autorest.go +++ /dev/null @@ -1,197 +0,0 @@ -package threatintelligence - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorQueryIndicatorsOperationResponse struct { - HttpResponse *http.Response - Model *[]ThreatIntelligenceInformation - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (IndicatorQueryIndicatorsOperationResponse, error) -} - -type IndicatorQueryIndicatorsCompleteResult struct { - Items []ThreatIntelligenceInformation -} - -func (r IndicatorQueryIndicatorsOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r IndicatorQueryIndicatorsOperationResponse) LoadMore(ctx context.Context) (resp IndicatorQueryIndicatorsOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// IndicatorQueryIndicators ... -func (c ThreatIntelligenceClient) IndicatorQueryIndicators(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria) (resp IndicatorQueryIndicatorsOperationResponse, err error) { - req, err := c.preparerForIndicatorQueryIndicators(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorQueryIndicators", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorQueryIndicators", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForIndicatorQueryIndicators(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorQueryIndicators", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForIndicatorQueryIndicators prepares the IndicatorQueryIndicators request. -func (c ThreatIntelligenceClient) preparerForIndicatorQueryIndicators(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/queryIndicators", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForIndicatorQueryIndicatorsWithNextLink prepares the IndicatorQueryIndicators request with the given nextLink token. -func (c ThreatIntelligenceClient) preparerForIndicatorQueryIndicatorsWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorQueryIndicators handles the response to the IndicatorQueryIndicators request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorQueryIndicators(resp *http.Response) (result IndicatorQueryIndicatorsOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]ThreatIntelligenceInformation, 0) - for i, v := range respObj.Values { - val, err := unmarshalThreatIntelligenceInformationImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for ThreatIntelligenceInformation (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result IndicatorQueryIndicatorsOperationResponse, err error) { - req, err := c.preparerForIndicatorQueryIndicatorsWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorQueryIndicators", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorQueryIndicators", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorQueryIndicators(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorQueryIndicators", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// IndicatorQueryIndicatorsComplete retrieves all of the results into a single object -func (c ThreatIntelligenceClient) IndicatorQueryIndicatorsComplete(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria) (IndicatorQueryIndicatorsCompleteResult, error) { - return c.IndicatorQueryIndicatorsCompleteMatchingPredicate(ctx, id, input, ThreatIntelligenceInformationOperationPredicate{}) -} - -// IndicatorQueryIndicatorsCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c ThreatIntelligenceClient) IndicatorQueryIndicatorsCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria, predicate ThreatIntelligenceInformationOperationPredicate) (resp IndicatorQueryIndicatorsCompleteResult, err error) { - items := make([]ThreatIntelligenceInformation, 0) - - page, err := c.IndicatorQueryIndicators(ctx, id, input) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := IndicatorQueryIndicatorsCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatorreplacetags.go b/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatorreplacetags.go new file mode 100644 index 00000000000..052bbe7b66a --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatorreplacetags.go @@ -0,0 +1,63 @@ +package threatintelligence + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorReplaceTagsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ThreatIntelligenceInformation +} + +// IndicatorReplaceTags ... +func (c ThreatIntelligenceClient) IndicatorReplaceTags(ctx context.Context, id IndicatorId, input ThreatIntelligenceIndicatorModel) (result IndicatorReplaceTagsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/replaceTags", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatorreplacetags_autorest.go b/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatorreplacetags_autorest.go deleted file mode 100644 index 01efbe5b778..00000000000 --- a/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatorreplacetags_autorest.go +++ /dev/null @@ -1,79 +0,0 @@ -package threatintelligence - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorReplaceTagsOperationResponse struct { - HttpResponse *http.Response - Model *ThreatIntelligenceInformation -} - -// IndicatorReplaceTags ... -func (c ThreatIntelligenceClient) IndicatorReplaceTags(ctx context.Context, id IndicatorId, input ThreatIntelligenceIndicatorModel) (result IndicatorReplaceTagsOperationResponse, err error) { - req, err := c.preparerForIndicatorReplaceTags(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorReplaceTags", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorReplaceTags", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorReplaceTags(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorReplaceTags", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorReplaceTags prepares the IndicatorReplaceTags request. -func (c ThreatIntelligenceClient) preparerForIndicatorReplaceTags(ctx context.Context, id IndicatorId, input ThreatIntelligenceIndicatorModel) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/replaceTags", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorReplaceTags handles the response to the IndicatorReplaceTags request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorReplaceTags(resp *http.Response) (result IndicatorReplaceTagsOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatorslist.go b/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatorslist.go new file mode 100644 index 00000000000..860ecd26255 --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatorslist.go @@ -0,0 +1,139 @@ +package threatintelligence + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ThreatIntelligenceInformation +} + +type IndicatorsListCompleteResult struct { + LatestHttpResponse *http.Response + Items []ThreatIntelligenceInformation +} + +type IndicatorsListOperationOptions struct { + Filter *string + Orderby *string + Top *int64 +} + +func DefaultIndicatorsListOperationOptions() IndicatorsListOperationOptions { + return IndicatorsListOperationOptions{} +} + +func (o IndicatorsListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o IndicatorsListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o IndicatorsListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// IndicatorsList ... +func (c ThreatIntelligenceClient) IndicatorsList(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions) (result IndicatorsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/indicators", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]ThreatIntelligenceInformation, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalThreatIntelligenceInformationImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for ThreatIntelligenceInformation (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// IndicatorsListComplete retrieves all the results into a single object +func (c ThreatIntelligenceClient) IndicatorsListComplete(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions) (IndicatorsListCompleteResult, error) { + return c.IndicatorsListCompleteMatchingPredicate(ctx, id, options, ThreatIntelligenceInformationOperationPredicate{}) +} + +// IndicatorsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ThreatIntelligenceClient) IndicatorsListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions, predicate ThreatIntelligenceInformationOperationPredicate) (result IndicatorsListCompleteResult, err error) { + items := make([]ThreatIntelligenceInformation, 0) + + resp, err := c.IndicatorsList(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = IndicatorsListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatorslist_autorest.go b/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatorslist_autorest.go deleted file mode 100644 index 22ef9d7b193..00000000000 --- a/resource-manager/securityinsights/2022-08-01/threatintelligence/method_indicatorslist_autorest.go +++ /dev/null @@ -1,235 +0,0 @@ -package threatintelligence - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorsListOperationResponse struct { - HttpResponse *http.Response - Model *[]ThreatIntelligenceInformation - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (IndicatorsListOperationResponse, error) -} - -type IndicatorsListCompleteResult struct { - Items []ThreatIntelligenceInformation -} - -func (r IndicatorsListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r IndicatorsListOperationResponse) LoadMore(ctx context.Context) (resp IndicatorsListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type IndicatorsListOperationOptions struct { - Filter *string - Orderby *string - Top *int64 -} - -func DefaultIndicatorsListOperationOptions() IndicatorsListOperationOptions { - return IndicatorsListOperationOptions{} -} - -func (o IndicatorsListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o IndicatorsListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Filter != nil { - out["$filter"] = *o.Filter - } - - if o.Orderby != nil { - out["$orderby"] = *o.Orderby - } - - if o.Top != nil { - out["$top"] = *o.Top - } - - return out -} - -// IndicatorsList ... -func (c ThreatIntelligenceClient) IndicatorsList(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions) (resp IndicatorsListOperationResponse, err error) { - req, err := c.preparerForIndicatorsList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForIndicatorsList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForIndicatorsList prepares the IndicatorsList request. -func (c ThreatIntelligenceClient) preparerForIndicatorsList(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/indicators", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForIndicatorsListWithNextLink prepares the IndicatorsList request with the given nextLink token. -func (c ThreatIntelligenceClient) preparerForIndicatorsListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorsList handles the response to the IndicatorsList request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorsList(resp *http.Response) (result IndicatorsListOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]ThreatIntelligenceInformation, 0) - for i, v := range respObj.Values { - val, err := unmarshalThreatIntelligenceInformationImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for ThreatIntelligenceInformation (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result IndicatorsListOperationResponse, err error) { - req, err := c.preparerForIndicatorsListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorsList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// IndicatorsListComplete retrieves all of the results into a single object -func (c ThreatIntelligenceClient) IndicatorsListComplete(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions) (IndicatorsListCompleteResult, error) { - return c.IndicatorsListCompleteMatchingPredicate(ctx, id, options, ThreatIntelligenceInformationOperationPredicate{}) -} - -// IndicatorsListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c ThreatIntelligenceClient) IndicatorsListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions, predicate ThreatIntelligenceInformationOperationPredicate) (resp IndicatorsListCompleteResult, err error) { - items := make([]ThreatIntelligenceInformation, 0) - - page, err := c.IndicatorsList(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := IndicatorsListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-08-01/watchlistitems/client.go b/resource-manager/securityinsights/2022-08-01/watchlistitems/client.go index 9403755456e..d3193694a48 100644 --- a/resource-manager/securityinsights/2022-08-01/watchlistitems/client.go +++ b/resource-manager/securityinsights/2022-08-01/watchlistitems/client.go @@ -1,18 +1,26 @@ package watchlistitems -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type WatchlistItemsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewWatchlistItemsClientWithBaseURI(endpoint string) WatchlistItemsClient { - return WatchlistItemsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewWatchlistItemsClientWithBaseURI(sdkApi sdkEnv.Api) (*WatchlistItemsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "watchlistitems", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating WatchlistItemsClient: %+v", err) } + + return &WatchlistItemsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-08-01/watchlistitems/method_createorupdate.go b/resource-manager/securityinsights/2022-08-01/watchlistitems/method_createorupdate.go new file mode 100644 index 00000000000..d02782f71bc --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/watchlistitems/method_createorupdate.go @@ -0,0 +1,56 @@ +package watchlistitems + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *WatchlistItem +} + +// CreateOrUpdate ... +func (c WatchlistItemsClient) CreateOrUpdate(ctx context.Context, id WatchlistItemId, input WatchlistItem) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-08-01/watchlistitems/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-08-01/watchlistitems/method_createorupdate_autorest.go deleted file mode 100644 index 15d8fdcc2be..00000000000 --- a/resource-manager/securityinsights/2022-08-01/watchlistitems/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package watchlistitems - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *WatchlistItem -} - -// CreateOrUpdate ... -func (c WatchlistItemsClient) CreateOrUpdate(ctx context.Context, id WatchlistItemId, input WatchlistItem) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c WatchlistItemsClient) preparerForCreateOrUpdate(ctx context.Context, id WatchlistItemId, input WatchlistItem) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c WatchlistItemsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-08-01/watchlistitems/method_delete.go b/resource-manager/securityinsights/2022-08-01/watchlistitems/method_delete.go new file mode 100644 index 00000000000..5565b767fa5 --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/watchlistitems/method_delete.go @@ -0,0 +1,47 @@ +package watchlistitems + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c WatchlistItemsClient) Delete(ctx context.Context, id WatchlistItemId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-08-01/watchlistitems/method_delete_autorest.go b/resource-manager/securityinsights/2022-08-01/watchlistitems/method_delete_autorest.go deleted file mode 100644 index c9b8c46f9e5..00000000000 --- a/resource-manager/securityinsights/2022-08-01/watchlistitems/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package watchlistitems - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c WatchlistItemsClient) Delete(ctx context.Context, id WatchlistItemId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c WatchlistItemsClient) preparerForDelete(ctx context.Context, id WatchlistItemId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c WatchlistItemsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-08-01/watchlistitems/method_get.go b/resource-manager/securityinsights/2022-08-01/watchlistitems/method_get.go new file mode 100644 index 00000000000..ff9a8e143fa --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/watchlistitems/method_get.go @@ -0,0 +1,51 @@ +package watchlistitems + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *WatchlistItem +} + +// Get ... +func (c WatchlistItemsClient) Get(ctx context.Context, id WatchlistItemId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-08-01/watchlistitems/method_get_autorest.go b/resource-manager/securityinsights/2022-08-01/watchlistitems/method_get_autorest.go deleted file mode 100644 index b294f999f64..00000000000 --- a/resource-manager/securityinsights/2022-08-01/watchlistitems/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package watchlistitems - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *WatchlistItem -} - -// Get ... -func (c WatchlistItemsClient) Get(ctx context.Context, id WatchlistItemId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c WatchlistItemsClient) preparerForGet(ctx context.Context, id WatchlistItemId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c WatchlistItemsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-08-01/watchlistitems/method_list.go b/resource-manager/securityinsights/2022-08-01/watchlistitems/method_list.go new file mode 100644 index 00000000000..8a4d418ea0b --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/watchlistitems/method_list.go @@ -0,0 +1,91 @@ +package watchlistitems + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]WatchlistItem +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []WatchlistItem +} + +// List ... +func (c WatchlistItemsClient) List(ctx context.Context, id WatchlistId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/watchlistItems", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]WatchlistItem `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c WatchlistItemsClient) ListComplete(ctx context.Context, id WatchlistId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, WatchlistItemOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c WatchlistItemsClient) ListCompleteMatchingPredicate(ctx context.Context, id WatchlistId, predicate WatchlistItemOperationPredicate) (result ListCompleteResult, err error) { + items := make([]WatchlistItem, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-08-01/watchlistitems/method_list_autorest.go b/resource-manager/securityinsights/2022-08-01/watchlistitems/method_list_autorest.go deleted file mode 100644 index d8e4bf85bf1..00000000000 --- a/resource-manager/securityinsights/2022-08-01/watchlistitems/method_list_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package watchlistitems - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]WatchlistItem - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []WatchlistItem -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c WatchlistItemsClient) List(ctx context.Context, id WatchlistId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c WatchlistItemsClient) preparerForList(ctx context.Context, id WatchlistId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/watchlistItems", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c WatchlistItemsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c WatchlistItemsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []WatchlistItem `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c WatchlistItemsClient) ListComplete(ctx context.Context, id WatchlistId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, WatchlistItemOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c WatchlistItemsClient) ListCompleteMatchingPredicate(ctx context.Context, id WatchlistId, predicate WatchlistItemOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]WatchlistItem, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-08-01/watchlists/client.go b/resource-manager/securityinsights/2022-08-01/watchlists/client.go index 61cfa3d0ac3..45211175054 100644 --- a/resource-manager/securityinsights/2022-08-01/watchlists/client.go +++ b/resource-manager/securityinsights/2022-08-01/watchlists/client.go @@ -1,18 +1,26 @@ package watchlists -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type WatchlistsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewWatchlistsClientWithBaseURI(endpoint string) WatchlistsClient { - return WatchlistsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewWatchlistsClientWithBaseURI(sdkApi sdkEnv.Api) (*WatchlistsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "watchlists", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating WatchlistsClient: %+v", err) } + + return &WatchlistsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-08-01/watchlists/constants.go b/resource-manager/securityinsights/2022-08-01/watchlists/constants.go index 504c5ecef48..2ec351b8408 100644 --- a/resource-manager/securityinsights/2022-08-01/watchlists/constants.go +++ b/resource-manager/securityinsights/2022-08-01/watchlists/constants.go @@ -1,6 +1,10 @@ package watchlists -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -19,6 +23,19 @@ func PossibleValuesForSource() []string { } } +func (s *Source) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSource(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSource(input string) (*Source, error) { vals := map[string]Source{ "local file": SourceLocalFile, diff --git a/resource-manager/securityinsights/2022-08-01/watchlists/method_createorupdate.go b/resource-manager/securityinsights/2022-08-01/watchlists/method_createorupdate.go new file mode 100644 index 00000000000..cf0dc47e9d7 --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/watchlists/method_createorupdate.go @@ -0,0 +1,56 @@ +package watchlists + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Watchlist +} + +// CreateOrUpdate ... +func (c WatchlistsClient) CreateOrUpdate(ctx context.Context, id WatchlistId, input Watchlist) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-08-01/watchlists/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-08-01/watchlists/method_createorupdate_autorest.go deleted file mode 100644 index e6d8a5976b8..00000000000 --- a/resource-manager/securityinsights/2022-08-01/watchlists/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package watchlists - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *Watchlist -} - -// CreateOrUpdate ... -func (c WatchlistsClient) CreateOrUpdate(ctx context.Context, id WatchlistId, input Watchlist) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c WatchlistsClient) preparerForCreateOrUpdate(ctx context.Context, id WatchlistId, input Watchlist) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c WatchlistsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-08-01/watchlists/method_delete.go b/resource-manager/securityinsights/2022-08-01/watchlists/method_delete.go new file mode 100644 index 00000000000..9d495f99c57 --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/watchlists/method_delete.go @@ -0,0 +1,47 @@ +package watchlists + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c WatchlistsClient) Delete(ctx context.Context, id WatchlistId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-08-01/watchlists/method_delete_autorest.go b/resource-manager/securityinsights/2022-08-01/watchlists/method_delete_autorest.go deleted file mode 100644 index 56234124b82..00000000000 --- a/resource-manager/securityinsights/2022-08-01/watchlists/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package watchlists - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c WatchlistsClient) Delete(ctx context.Context, id WatchlistId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c WatchlistsClient) preparerForDelete(ctx context.Context, id WatchlistId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c WatchlistsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-08-01/watchlists/method_get.go b/resource-manager/securityinsights/2022-08-01/watchlists/method_get.go new file mode 100644 index 00000000000..39ec92feaeb --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/watchlists/method_get.go @@ -0,0 +1,51 @@ +package watchlists + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Watchlist +} + +// Get ... +func (c WatchlistsClient) Get(ctx context.Context, id WatchlistId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-08-01/watchlists/method_get_autorest.go b/resource-manager/securityinsights/2022-08-01/watchlists/method_get_autorest.go deleted file mode 100644 index d7253f62215..00000000000 --- a/resource-manager/securityinsights/2022-08-01/watchlists/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package watchlists - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *Watchlist -} - -// Get ... -func (c WatchlistsClient) Get(ctx context.Context, id WatchlistId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c WatchlistsClient) preparerForGet(ctx context.Context, id WatchlistId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c WatchlistsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-08-01/watchlists/method_list.go b/resource-manager/securityinsights/2022-08-01/watchlists/method_list.go new file mode 100644 index 00000000000..9122b014815 --- /dev/null +++ b/resource-manager/securityinsights/2022-08-01/watchlists/method_list.go @@ -0,0 +1,91 @@ +package watchlists + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Watchlist +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Watchlist +} + +// List ... +func (c WatchlistsClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/watchlists", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Watchlist `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c WatchlistsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, WatchlistOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c WatchlistsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate WatchlistOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Watchlist, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-08-01/watchlists/method_list_autorest.go b/resource-manager/securityinsights/2022-08-01/watchlists/method_list_autorest.go deleted file mode 100644 index a3a2c27c15e..00000000000 --- a/resource-manager/securityinsights/2022-08-01/watchlists/method_list_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package watchlists - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]Watchlist - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []Watchlist -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c WatchlistsClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c WatchlistsClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/watchlists", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c WatchlistsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c WatchlistsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []Watchlist `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c WatchlistsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, WatchlistOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c WatchlistsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate WatchlistOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]Watchlist, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/actions/client.go b/resource-manager/securityinsights/2022-10-01-preview/actions/client.go index 9a66b55eb82..a2b7d01bfe1 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/actions/client.go +++ b/resource-manager/securityinsights/2022-10-01-preview/actions/client.go @@ -1,18 +1,26 @@ package actions -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type ActionsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewActionsClientWithBaseURI(endpoint string) ActionsClient { - return ActionsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewActionsClientWithBaseURI(sdkApi sdkEnv.Api) (*ActionsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "actions", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ActionsClient: %+v", err) } + + return &ActionsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-10-01-preview/actions/method_createorupdate.go b/resource-manager/securityinsights/2022-10-01-preview/actions/method_createorupdate.go new file mode 100644 index 00000000000..1672bf99a0f --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/actions/method_createorupdate.go @@ -0,0 +1,56 @@ +package actions + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ActionResponse +} + +// CreateOrUpdate ... +func (c ActionsClient) CreateOrUpdate(ctx context.Context, id ActionId, input ActionRequest) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/actions/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/actions/method_createorupdate_autorest.go deleted file mode 100644 index f5145e1a555..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/actions/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package actions - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *ActionResponse -} - -// CreateOrUpdate ... -func (c ActionsClient) CreateOrUpdate(ctx context.Context, id ActionId, input ActionRequest) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c ActionsClient) preparerForCreateOrUpdate(ctx context.Context, id ActionId, input ActionRequest) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c ActionsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/actions/method_delete.go b/resource-manager/securityinsights/2022-10-01-preview/actions/method_delete.go new file mode 100644 index 00000000000..0f8a28307c2 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/actions/method_delete.go @@ -0,0 +1,47 @@ +package actions + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c ActionsClient) Delete(ctx context.Context, id ActionId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/actions/method_delete_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/actions/method_delete_autorest.go deleted file mode 100644 index d142f9f3054..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/actions/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package actions - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c ActionsClient) Delete(ctx context.Context, id ActionId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c ActionsClient) preparerForDelete(ctx context.Context, id ActionId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c ActionsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/actions/method_get.go b/resource-manager/securityinsights/2022-10-01-preview/actions/method_get.go new file mode 100644 index 00000000000..76d3593e1f1 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/actions/method_get.go @@ -0,0 +1,51 @@ +package actions + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ActionResponse +} + +// Get ... +func (c ActionsClient) Get(ctx context.Context, id ActionId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/actions/method_get_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/actions/method_get_autorest.go deleted file mode 100644 index aa1388a0c31..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/actions/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package actions - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *ActionResponse -} - -// Get ... -func (c ActionsClient) Get(ctx context.Context, id ActionId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c ActionsClient) preparerForGet(ctx context.Context, id ActionId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c ActionsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/actions/method_listbyalertrule.go b/resource-manager/securityinsights/2022-10-01-preview/actions/method_listbyalertrule.go new file mode 100644 index 00000000000..09d32b9d82d --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/actions/method_listbyalertrule.go @@ -0,0 +1,91 @@ +package actions + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByAlertRuleOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ActionResponse +} + +type ListByAlertRuleCompleteResult struct { + LatestHttpResponse *http.Response + Items []ActionResponse +} + +// ListByAlertRule ... +func (c ActionsClient) ListByAlertRule(ctx context.Context, id AlertRuleId) (result ListByAlertRuleOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/actions", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ActionResponse `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByAlertRuleComplete retrieves all the results into a single object +func (c ActionsClient) ListByAlertRuleComplete(ctx context.Context, id AlertRuleId) (ListByAlertRuleCompleteResult, error) { + return c.ListByAlertRuleCompleteMatchingPredicate(ctx, id, ActionResponseOperationPredicate{}) +} + +// ListByAlertRuleCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ActionsClient) ListByAlertRuleCompleteMatchingPredicate(ctx context.Context, id AlertRuleId, predicate ActionResponseOperationPredicate) (result ListByAlertRuleCompleteResult, err error) { + items := make([]ActionResponse, 0) + + resp, err := c.ListByAlertRule(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByAlertRuleCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/actions/method_listbyalertrule_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/actions/method_listbyalertrule_autorest.go deleted file mode 100644 index a58a9738f1f..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/actions/method_listbyalertrule_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package actions - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListByAlertRuleOperationResponse struct { - HttpResponse *http.Response - Model *[]ActionResponse - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListByAlertRuleOperationResponse, error) -} - -type ListByAlertRuleCompleteResult struct { - Items []ActionResponse -} - -func (r ListByAlertRuleOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListByAlertRuleOperationResponse) LoadMore(ctx context.Context) (resp ListByAlertRuleOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// ListByAlertRule ... -func (c ActionsClient) ListByAlertRule(ctx context.Context, id AlertRuleId) (resp ListByAlertRuleOperationResponse, err error) { - req, err := c.preparerForListByAlertRule(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "ListByAlertRule", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "ListByAlertRule", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForListByAlertRule(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "ListByAlertRule", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForListByAlertRule prepares the ListByAlertRule request. -func (c ActionsClient) preparerForListByAlertRule(ctx context.Context, id AlertRuleId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/actions", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListByAlertRuleWithNextLink prepares the ListByAlertRule request with the given nextLink token. -func (c ActionsClient) preparerForListByAlertRuleWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForListByAlertRule handles the response to the ListByAlertRule request. The method always -// closes the http.Response Body. -func (c ActionsClient) responderForListByAlertRule(resp *http.Response) (result ListByAlertRuleOperationResponse, err error) { - type page struct { - Values []ActionResponse `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByAlertRuleOperationResponse, err error) { - req, err := c.preparerForListByAlertRuleWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "ListByAlertRule", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "ListByAlertRule", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForListByAlertRule(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "ListByAlertRule", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListByAlertRuleComplete retrieves all of the results into a single object -func (c ActionsClient) ListByAlertRuleComplete(ctx context.Context, id AlertRuleId) (ListByAlertRuleCompleteResult, error) { - return c.ListByAlertRuleCompleteMatchingPredicate(ctx, id, ActionResponseOperationPredicate{}) -} - -// ListByAlertRuleCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c ActionsClient) ListByAlertRuleCompleteMatchingPredicate(ctx context.Context, id AlertRuleId, predicate ActionResponseOperationPredicate) (resp ListByAlertRuleCompleteResult, err error) { - items := make([]ActionResponse, 0) - - page, err := c.ListByAlertRule(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListByAlertRuleCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/alertrules/client.go b/resource-manager/securityinsights/2022-10-01-preview/alertrules/client.go index 6e34bca2ce3..e6ca04af9da 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/alertrules/client.go +++ b/resource-manager/securityinsights/2022-10-01-preview/alertrules/client.go @@ -1,18 +1,26 @@ package alertrules -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type AlertRulesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewAlertRulesClientWithBaseURI(endpoint string) AlertRulesClient { - return AlertRulesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewAlertRulesClientWithBaseURI(sdkApi sdkEnv.Api) (*AlertRulesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "alertrules", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AlertRulesClient: %+v", err) } + + return &AlertRulesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-10-01-preview/alertrules/constants.go b/resource-manager/securityinsights/2022-10-01-preview/alertrules/constants.go index 793d176c710..269a786b12f 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/alertrules/constants.go +++ b/resource-manager/securityinsights/2022-10-01-preview/alertrules/constants.go @@ -1,6 +1,10 @@ package alertrules -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -19,6 +23,19 @@ func PossibleValuesForAlertDetail() []string { } } +func (s *AlertDetail) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertDetail(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertDetail(input string) (*AlertDetail, error) { vals := map[string]AlertDetail{ "displayname": AlertDetailDisplayName, @@ -61,6 +78,19 @@ func PossibleValuesForAlertProperty() []string { } } +func (s *AlertProperty) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertProperty(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertProperty(input string) (*AlertProperty, error) { vals := map[string]AlertProperty{ "alertlink": AlertPropertyAlertLink, @@ -104,6 +134,19 @@ func PossibleValuesForAlertRuleKind() []string { } } +func (s *AlertRuleKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertRuleKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertRuleKind(input string) (*AlertRuleKind, error) { vals := map[string]AlertRuleKind{ "fusion": AlertRuleKindFusion, @@ -140,6 +183,19 @@ func PossibleValuesForAlertSeverity() []string { } } +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertSeverity(input string) (*AlertSeverity, error) { vals := map[string]AlertSeverity{ "high": AlertSeverityHigh, @@ -200,6 +256,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -275,6 +344,19 @@ func PossibleValuesForEntityMappingType() []string { } } +func (s *EntityMappingType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityMappingType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityMappingType(input string) (*EntityMappingType, error) { vals := map[string]EntityMappingType{ "account": EntityMappingTypeAccount, @@ -319,6 +401,19 @@ func PossibleValuesForEventGroupingAggregationKind() []string { } } +func (s *EventGroupingAggregationKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEventGroupingAggregationKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEventGroupingAggregationKind(input string) (*EventGroupingAggregationKind, error) { vals := map[string]EventGroupingAggregationKind{ "alertperresult": EventGroupingAggregationKindAlertPerResult, @@ -349,6 +444,19 @@ func PossibleValuesForMatchingMethod() []string { } } +func (s *MatchingMethod) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMatchingMethod(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseMatchingMethod(input string) (*MatchingMethod, error) { vals := map[string]MatchingMethod{ "allentities": MatchingMethodAllEntities, @@ -388,6 +496,19 @@ func PossibleValuesForMicrosoftSecurityProductName() []string { } } +func (s *MicrosoftSecurityProductName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMicrosoftSecurityProductName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseMicrosoftSecurityProductName(input string) (*MicrosoftSecurityProductName, error) { vals := map[string]MicrosoftSecurityProductName{ "azure active directory identity protection": MicrosoftSecurityProductNameAzureActiveDirectoryIdentityProtection, @@ -425,6 +546,19 @@ func PossibleValuesForTriggerOperator() []string { } } +func (s *TriggerOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTriggerOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseTriggerOperator(input string) (*TriggerOperator, error) { vals := map[string]TriggerOperator{ "equal": TriggerOperatorEqual, diff --git a/resource-manager/securityinsights/2022-10-01-preview/alertrules/method_createorupdate.go b/resource-manager/securityinsights/2022-10-01-preview/alertrules/method_createorupdate.go new file mode 100644 index 00000000000..f77c7558d09 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/alertrules/method_createorupdate.go @@ -0,0 +1,63 @@ +package alertrules + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AlertRule +} + +// CreateOrUpdate ... +func (c AlertRulesClient) CreateOrUpdate(ctx context.Context, id AlertRuleId, input AlertRule) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalAlertRuleImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/alertrules/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/alertrules/method_createorupdate_autorest.go deleted file mode 100644 index 548f6c4ef37..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/alertrules/method_createorupdate_autorest.go +++ /dev/null @@ -1,78 +0,0 @@ -package alertrules - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *AlertRule -} - -// CreateOrUpdate ... -func (c AlertRulesClient) CreateOrUpdate(ctx context.Context, id AlertRuleId, input AlertRule) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c AlertRulesClient) preparerForCreateOrUpdate(ctx context.Context, id AlertRuleId, input AlertRule) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c AlertRulesClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalAlertRuleImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/alertrules/method_delete.go b/resource-manager/securityinsights/2022-10-01-preview/alertrules/method_delete.go new file mode 100644 index 00000000000..aae7085c25e --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/alertrules/method_delete.go @@ -0,0 +1,47 @@ +package alertrules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c AlertRulesClient) Delete(ctx context.Context, id AlertRuleId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/alertrules/method_delete_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/alertrules/method_delete_autorest.go deleted file mode 100644 index 417e1a0017e..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/alertrules/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package alertrules - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c AlertRulesClient) Delete(ctx context.Context, id AlertRuleId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c AlertRulesClient) preparerForDelete(ctx context.Context, id AlertRuleId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c AlertRulesClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/alertrules/method_get.go b/resource-manager/securityinsights/2022-10-01-preview/alertrules/method_get.go new file mode 100644 index 00000000000..945c07bfad1 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/alertrules/method_get.go @@ -0,0 +1,58 @@ +package alertrules + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AlertRule +} + +// Get ... +func (c AlertRulesClient) Get(ctx context.Context, id AlertRuleId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalAlertRuleImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/alertrules/method_get_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/alertrules/method_get_autorest.go deleted file mode 100644 index ddd1836d4de..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/alertrules/method_get_autorest.go +++ /dev/null @@ -1,77 +0,0 @@ -package alertrules - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *AlertRule -} - -// Get ... -func (c AlertRulesClient) Get(ctx context.Context, id AlertRuleId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c AlertRulesClient) preparerForGet(ctx context.Context, id AlertRuleId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c AlertRulesClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalAlertRuleImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/alertrules/method_list.go b/resource-manager/securityinsights/2022-10-01-preview/alertrules/method_list.go new file mode 100644 index 00000000000..5ac99496167 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/alertrules/method_list.go @@ -0,0 +1,103 @@ +package alertrules + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AlertRule +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []AlertRule +} + +// List ... +func (c AlertRulesClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/alertRules", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]AlertRule, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalAlertRuleImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for AlertRule (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// ListComplete retrieves all the results into a single object +func (c AlertRulesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, AlertRuleOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AlertRulesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AlertRuleOperationPredicate) (result ListCompleteResult, err error) { + items := make([]AlertRule, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/alertrules/method_list_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/alertrules/method_list_autorest.go deleted file mode 100644 index f06cf0f6241..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/alertrules/method_list_autorest.go +++ /dev/null @@ -1,196 +0,0 @@ -package alertrules - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]AlertRule - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []AlertRule -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c AlertRulesClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c AlertRulesClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/alertRules", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c AlertRulesClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c AlertRulesClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]AlertRule, 0) - for i, v := range respObj.Values { - val, err := unmarshalAlertRuleImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for AlertRule (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c AlertRulesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, AlertRuleOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c AlertRulesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AlertRuleOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]AlertRule, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/alertruletemplates/client.go b/resource-manager/securityinsights/2022-10-01-preview/alertruletemplates/client.go index c439e5a41c7..2932bf14a55 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/alertruletemplates/client.go +++ b/resource-manager/securityinsights/2022-10-01-preview/alertruletemplates/client.go @@ -1,18 +1,26 @@ package alertruletemplates -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type AlertRuleTemplatesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewAlertRuleTemplatesClientWithBaseURI(endpoint string) AlertRuleTemplatesClient { - return AlertRuleTemplatesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewAlertRuleTemplatesClientWithBaseURI(sdkApi sdkEnv.Api) (*AlertRuleTemplatesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "alertruletemplates", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AlertRuleTemplatesClient: %+v", err) } + + return &AlertRuleTemplatesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-10-01-preview/alertruletemplates/constants.go b/resource-manager/securityinsights/2022-10-01-preview/alertruletemplates/constants.go index 8bbeb170365..2436c4ff7a9 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/alertruletemplates/constants.go +++ b/resource-manager/securityinsights/2022-10-01-preview/alertruletemplates/constants.go @@ -1,6 +1,10 @@ package alertruletemplates -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -33,6 +37,19 @@ func PossibleValuesForAlertProperty() []string { } } +func (s *AlertProperty) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertProperty(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertProperty(input string) (*AlertProperty, error) { vals := map[string]AlertProperty{ "alertlink": AlertPropertyAlertLink, @@ -76,6 +93,19 @@ func PossibleValuesForAlertRuleKind() []string { } } +func (s *AlertRuleKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertRuleKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertRuleKind(input string) (*AlertRuleKind, error) { vals := map[string]AlertRuleKind{ "fusion": AlertRuleKindFusion, @@ -112,6 +142,19 @@ func PossibleValuesForAlertSeverity() []string { } } +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertSeverity(input string) (*AlertSeverity, error) { vals := map[string]AlertSeverity{ "high": AlertSeverityHigh, @@ -172,6 +215,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -247,6 +303,19 @@ func PossibleValuesForEntityMappingType() []string { } } +func (s *EntityMappingType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityMappingType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityMappingType(input string) (*EntityMappingType, error) { vals := map[string]EntityMappingType{ "account": EntityMappingTypeAccount, @@ -291,6 +360,19 @@ func PossibleValuesForEventGroupingAggregationKind() []string { } } +func (s *EventGroupingAggregationKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEventGroupingAggregationKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEventGroupingAggregationKind(input string) (*EventGroupingAggregationKind, error) { vals := map[string]EventGroupingAggregationKind{ "alertperresult": EventGroupingAggregationKindAlertPerResult, @@ -329,6 +411,19 @@ func PossibleValuesForMicrosoftSecurityProductName() []string { } } +func (s *MicrosoftSecurityProductName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMicrosoftSecurityProductName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseMicrosoftSecurityProductName(input string) (*MicrosoftSecurityProductName, error) { vals := map[string]MicrosoftSecurityProductName{ "azure active directory identity protection": MicrosoftSecurityProductNameAzureActiveDirectoryIdentityProtection, @@ -364,6 +459,19 @@ func PossibleValuesForTemplateStatus() []string { } } +func (s *TemplateStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTemplateStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseTemplateStatus(input string) (*TemplateStatus, error) { vals := map[string]TemplateStatus{ "available": TemplateStatusAvailable, @@ -397,6 +505,19 @@ func PossibleValuesForTriggerOperator() []string { } } +func (s *TriggerOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTriggerOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseTriggerOperator(input string) (*TriggerOperator, error) { vals := map[string]TriggerOperator{ "equal": TriggerOperatorEqual, diff --git a/resource-manager/securityinsights/2022-10-01-preview/alertruletemplates/method_get.go b/resource-manager/securityinsights/2022-10-01-preview/alertruletemplates/method_get.go new file mode 100644 index 00000000000..861712be66a --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/alertruletemplates/method_get.go @@ -0,0 +1,58 @@ +package alertruletemplates + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AlertRuleTemplate +} + +// Get ... +func (c AlertRuleTemplatesClient) Get(ctx context.Context, id AlertRuleTemplateId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalAlertRuleTemplateImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/alertruletemplates/method_get_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/alertruletemplates/method_get_autorest.go deleted file mode 100644 index ad4e0487d83..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/alertruletemplates/method_get_autorest.go +++ /dev/null @@ -1,77 +0,0 @@ -package alertruletemplates - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *AlertRuleTemplate -} - -// Get ... -func (c AlertRuleTemplatesClient) Get(ctx context.Context, id AlertRuleTemplateId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c AlertRuleTemplatesClient) preparerForGet(ctx context.Context, id AlertRuleTemplateId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c AlertRuleTemplatesClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalAlertRuleTemplateImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/alertruletemplates/method_list.go b/resource-manager/securityinsights/2022-10-01-preview/alertruletemplates/method_list.go new file mode 100644 index 00000000000..21f9ceec3de --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/alertruletemplates/method_list.go @@ -0,0 +1,103 @@ +package alertruletemplates + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AlertRuleTemplate +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []AlertRuleTemplate +} + +// List ... +func (c AlertRuleTemplatesClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/alertRuleTemplates", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]AlertRuleTemplate, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalAlertRuleTemplateImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for AlertRuleTemplate (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// ListComplete retrieves all the results into a single object +func (c AlertRuleTemplatesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, AlertRuleTemplateOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AlertRuleTemplatesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AlertRuleTemplateOperationPredicate) (result ListCompleteResult, err error) { + items := make([]AlertRuleTemplate, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/alertruletemplates/method_list_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/alertruletemplates/method_list_autorest.go deleted file mode 100644 index 56794382966..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/alertruletemplates/method_list_autorest.go +++ /dev/null @@ -1,196 +0,0 @@ -package alertruletemplates - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]AlertRuleTemplate - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []AlertRuleTemplate -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c AlertRuleTemplatesClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c AlertRuleTemplatesClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/alertRuleTemplates", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c AlertRuleTemplatesClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c AlertRuleTemplatesClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]AlertRuleTemplate, 0) - for i, v := range respObj.Values { - val, err := unmarshalAlertRuleTemplateImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for AlertRuleTemplate (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c AlertRuleTemplatesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, AlertRuleTemplateOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c AlertRuleTemplatesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AlertRuleTemplateOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]AlertRuleTemplate, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/automationrules/client.go b/resource-manager/securityinsights/2022-10-01-preview/automationrules/client.go index 960f049c387..18fafea1496 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/automationrules/client.go +++ b/resource-manager/securityinsights/2022-10-01-preview/automationrules/client.go @@ -1,18 +1,26 @@ package automationrules -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type AutomationRulesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewAutomationRulesClientWithBaseURI(endpoint string) AutomationRulesClient { - return AutomationRulesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewAutomationRulesClientWithBaseURI(sdkApi sdkEnv.Api) (*AutomationRulesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "automationrules", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AutomationRulesClient: %+v", err) } + + return &AutomationRulesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-10-01-preview/automationrules/constants.go b/resource-manager/securityinsights/2022-10-01-preview/automationrules/constants.go index 73ef09a0903..7e27f51e7cc 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/automationrules/constants.go +++ b/resource-manager/securityinsights/2022-10-01-preview/automationrules/constants.go @@ -1,6 +1,10 @@ package automationrules -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -19,6 +23,19 @@ func PossibleValuesForActionType() []string { } } +func (s *ActionType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseActionType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseActionType(input string) (*ActionType, error) { vals := map[string]ActionType{ "modifyproperties": ActionTypeModifyProperties, @@ -47,6 +64,19 @@ func PossibleValuesForAutomationRuleBooleanConditionSupportedOperator() []string } } +func (s *AutomationRuleBooleanConditionSupportedOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRuleBooleanConditionSupportedOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAutomationRuleBooleanConditionSupportedOperator(input string) (*AutomationRuleBooleanConditionSupportedOperator, error) { vals := map[string]AutomationRuleBooleanConditionSupportedOperator{ "and": AutomationRuleBooleanConditionSupportedOperatorAnd, @@ -79,6 +109,19 @@ func PossibleValuesForAutomationRulePropertyArrayChangedConditionSupportedArrayT } } +func (s *AutomationRulePropertyArrayChangedConditionSupportedArrayType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRulePropertyArrayChangedConditionSupportedArrayType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAutomationRulePropertyArrayChangedConditionSupportedArrayType(input string) (*AutomationRulePropertyArrayChangedConditionSupportedArrayType, error) { vals := map[string]AutomationRulePropertyArrayChangedConditionSupportedArrayType{ "alerts": AutomationRulePropertyArrayChangedConditionSupportedArrayTypeAlerts, @@ -107,6 +150,19 @@ func PossibleValuesForAutomationRulePropertyArrayChangedConditionSupportedChange } } +func (s *AutomationRulePropertyArrayChangedConditionSupportedChangeType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRulePropertyArrayChangedConditionSupportedChangeType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAutomationRulePropertyArrayChangedConditionSupportedChangeType(input string) (*AutomationRulePropertyArrayChangedConditionSupportedChangeType, error) { vals := map[string]AutomationRulePropertyArrayChangedConditionSupportedChangeType{ "added": AutomationRulePropertyArrayChangedConditionSupportedChangeTypeAdded, @@ -132,6 +188,19 @@ func PossibleValuesForAutomationRulePropertyArrayConditionSupportedArrayConditio } } +func (s *AutomationRulePropertyArrayConditionSupportedArrayConditionType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRulePropertyArrayConditionSupportedArrayConditionType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAutomationRulePropertyArrayConditionSupportedArrayConditionType(input string) (*AutomationRulePropertyArrayConditionSupportedArrayConditionType, error) { vals := map[string]AutomationRulePropertyArrayConditionSupportedArrayConditionType{ "anyitem": AutomationRulePropertyArrayConditionSupportedArrayConditionTypeAnyItem, @@ -159,6 +228,19 @@ func PossibleValuesForAutomationRulePropertyArrayConditionSupportedArrayType() [ } } +func (s *AutomationRulePropertyArrayConditionSupportedArrayType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRulePropertyArrayConditionSupportedArrayType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAutomationRulePropertyArrayConditionSupportedArrayType(input string) (*AutomationRulePropertyArrayConditionSupportedArrayType, error) { vals := map[string]AutomationRulePropertyArrayConditionSupportedArrayType{ "customdetailvalues": AutomationRulePropertyArrayConditionSupportedArrayTypeCustomDetailValues, @@ -187,6 +269,19 @@ func PossibleValuesForAutomationRulePropertyChangedConditionSupportedChangedType } } +func (s *AutomationRulePropertyChangedConditionSupportedChangedType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRulePropertyChangedConditionSupportedChangedType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAutomationRulePropertyChangedConditionSupportedChangedType(input string) (*AutomationRulePropertyChangedConditionSupportedChangedType, error) { vals := map[string]AutomationRulePropertyChangedConditionSupportedChangedType{ "changedfrom": AutomationRulePropertyChangedConditionSupportedChangedTypeChangedFrom, @@ -217,6 +312,19 @@ func PossibleValuesForAutomationRulePropertyChangedConditionSupportedPropertyTyp } } +func (s *AutomationRulePropertyChangedConditionSupportedPropertyType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRulePropertyChangedConditionSupportedPropertyType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAutomationRulePropertyChangedConditionSupportedPropertyType(input string) (*AutomationRulePropertyChangedConditionSupportedPropertyType, error) { vals := map[string]AutomationRulePropertyChangedConditionSupportedPropertyType{ "incidentowner": AutomationRulePropertyChangedConditionSupportedPropertyTypeIncidentOwner, @@ -258,6 +366,19 @@ func PossibleValuesForAutomationRulePropertyConditionSupportedOperator() []strin } } +func (s *AutomationRulePropertyConditionSupportedOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRulePropertyConditionSupportedOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAutomationRulePropertyConditionSupportedOperator(input string) (*AutomationRulePropertyConditionSupportedOperator, error) { vals := map[string]AutomationRulePropertyConditionSupportedOperator{ "contains": AutomationRulePropertyConditionSupportedOperatorContains, @@ -404,6 +525,19 @@ func PossibleValuesForAutomationRulePropertyConditionSupportedProperty() []strin } } +func (s *AutomationRulePropertyConditionSupportedProperty) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRulePropertyConditionSupportedProperty(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAutomationRulePropertyConditionSupportedProperty(input string) (*AutomationRulePropertyConditionSupportedProperty, error) { vals := map[string]AutomationRulePropertyConditionSupportedProperty{ "accountaadtenantid": AutomationRulePropertyConditionSupportedPropertyAccountAadTenantId, @@ -494,6 +628,19 @@ func PossibleValuesForConditionType() []string { } } +func (s *ConditionType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConditionType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConditionType(input string) (*ConditionType, error) { vals := map[string]ConditionType{ "boolean": ConditionTypeBoolean, @@ -529,6 +676,19 @@ func PossibleValuesForIncidentClassification() []string { } } +func (s *IncidentClassification) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentClassification(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentClassification(input string) (*IncidentClassification, error) { vals := map[string]IncidentClassification{ "benignpositive": IncidentClassificationBenignPositive, @@ -563,6 +723,19 @@ func PossibleValuesForIncidentClassificationReason() []string { } } +func (s *IncidentClassificationReason) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentClassificationReason(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentClassificationReason(input string) (*IncidentClassificationReason, error) { vals := map[string]IncidentClassificationReason{ "inaccuratedata": IncidentClassificationReasonInaccurateData, @@ -593,6 +766,19 @@ func PossibleValuesForIncidentLabelType() []string { } } +func (s *IncidentLabelType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentLabelType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentLabelType(input string) (*IncidentLabelType, error) { vals := map[string]IncidentLabelType{ "autoassigned": IncidentLabelTypeAutoAssigned, @@ -625,6 +811,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, @@ -657,6 +856,19 @@ func PossibleValuesForIncidentStatus() []string { } } +func (s *IncidentStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentStatus(input string) (*IncidentStatus, error) { vals := map[string]IncidentStatus{ "active": IncidentStatusActive, @@ -688,6 +900,19 @@ func PossibleValuesForOwnerType() []string { } } +func (s *OwnerType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOwnerType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseOwnerType(input string) (*OwnerType, error) { vals := map[string]OwnerType{ "group": OwnerTypeGroup, @@ -717,6 +942,19 @@ func PossibleValuesForTriggersOn() []string { } } +func (s *TriggersOn) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTriggersOn(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseTriggersOn(input string) (*TriggersOn, error) { vals := map[string]TriggersOn{ "alerts": TriggersOnAlerts, @@ -745,6 +983,19 @@ func PossibleValuesForTriggersWhen() []string { } } +func (s *TriggersWhen) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTriggersWhen(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseTriggersWhen(input string) (*TriggersWhen, error) { vals := map[string]TriggersWhen{ "created": TriggersWhenCreated, diff --git a/resource-manager/securityinsights/2022-10-01-preview/automationrules/method_createorupdate.go b/resource-manager/securityinsights/2022-10-01-preview/automationrules/method_createorupdate.go new file mode 100644 index 00000000000..c0b3c44f2da --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/automationrules/method_createorupdate.go @@ -0,0 +1,56 @@ +package automationrules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AutomationRule +} + +// CreateOrUpdate ... +func (c AutomationRulesClient) CreateOrUpdate(ctx context.Context, id AutomationRuleId, input AutomationRule) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/automationrules/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/automationrules/method_createorupdate_autorest.go deleted file mode 100644 index 790f2ff99f9..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/automationrules/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package automationrules - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *AutomationRule -} - -// CreateOrUpdate ... -func (c AutomationRulesClient) CreateOrUpdate(ctx context.Context, id AutomationRuleId, input AutomationRule) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c AutomationRulesClient) preparerForCreateOrUpdate(ctx context.Context, id AutomationRuleId, input AutomationRule) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c AutomationRulesClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/automationrules/method_delete.go b/resource-manager/securityinsights/2022-10-01-preview/automationrules/method_delete.go new file mode 100644 index 00000000000..682e97ed619 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/automationrules/method_delete.go @@ -0,0 +1,52 @@ +package automationrules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *interface{} +} + +// Delete ... +func (c AutomationRulesClient) Delete(ctx context.Context, id AutomationRuleId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/automationrules/method_delete_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/automationrules/method_delete_autorest.go deleted file mode 100644 index cd33f79070e..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/automationrules/method_delete_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package automationrules - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response - Model *interface{} -} - -// Delete ... -func (c AutomationRulesClient) Delete(ctx context.Context, id AutomationRuleId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c AutomationRulesClient) preparerForDelete(ctx context.Context, id AutomationRuleId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c AutomationRulesClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/automationrules/method_get.go b/resource-manager/securityinsights/2022-10-01-preview/automationrules/method_get.go new file mode 100644 index 00000000000..0676dc80f40 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/automationrules/method_get.go @@ -0,0 +1,51 @@ +package automationrules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AutomationRule +} + +// Get ... +func (c AutomationRulesClient) Get(ctx context.Context, id AutomationRuleId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/automationrules/method_get_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/automationrules/method_get_autorest.go deleted file mode 100644 index 20f385aa8d7..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/automationrules/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package automationrules - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *AutomationRule -} - -// Get ... -func (c AutomationRulesClient) Get(ctx context.Context, id AutomationRuleId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c AutomationRulesClient) preparerForGet(ctx context.Context, id AutomationRuleId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c AutomationRulesClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/automationrules/method_list.go b/resource-manager/securityinsights/2022-10-01-preview/automationrules/method_list.go new file mode 100644 index 00000000000..a3c7db4995a --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/automationrules/method_list.go @@ -0,0 +1,91 @@ +package automationrules + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AutomationRule +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []AutomationRule +} + +// List ... +func (c AutomationRulesClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/automationRules", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]AutomationRule `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c AutomationRulesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, AutomationRuleOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AutomationRulesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AutomationRuleOperationPredicate) (result ListCompleteResult, err error) { + items := make([]AutomationRule, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/automationrules/method_list_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/automationrules/method_list_autorest.go deleted file mode 100644 index e2818088fcf..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/automationrules/method_list_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package automationrules - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]AutomationRule - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []AutomationRule -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c AutomationRulesClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c AutomationRulesClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/automationRules", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c AutomationRulesClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c AutomationRulesClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []AutomationRule `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c AutomationRulesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, AutomationRuleOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c AutomationRulesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AutomationRuleOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]AutomationRule, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/bookmark/client.go b/resource-manager/securityinsights/2022-10-01-preview/bookmark/client.go index 0bd7283b391..f20b4939301 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/bookmark/client.go +++ b/resource-manager/securityinsights/2022-10-01-preview/bookmark/client.go @@ -1,18 +1,26 @@ package bookmark -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type BookmarkClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewBookmarkClientWithBaseURI(endpoint string) BookmarkClient { - return BookmarkClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewBookmarkClientWithBaseURI(sdkApi sdkEnv.Api) (*BookmarkClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "bookmark", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating BookmarkClient: %+v", err) } + + return &BookmarkClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-10-01-preview/bookmark/constants.go b/resource-manager/securityinsights/2022-10-01-preview/bookmark/constants.go index 017a99af542..95e462c1392 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/bookmark/constants.go +++ b/resource-manager/securityinsights/2022-10-01-preview/bookmark/constants.go @@ -1,6 +1,10 @@ package bookmark -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -59,6 +63,19 @@ func PossibleValuesForEntityKind() []string { } } +func (s *EntityKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityKind(input string) (*EntityKind, error) { vals := map[string]EntityKind{ "account": EntityKindAccount, diff --git a/resource-manager/securityinsights/2022-10-01-preview/bookmark/method_expand.go b/resource-manager/securityinsights/2022-10-01-preview/bookmark/method_expand.go new file mode 100644 index 00000000000..5d8ee564063 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/bookmark/method_expand.go @@ -0,0 +1,56 @@ +package bookmark + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExpandOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *BookmarkExpandResponse +} + +// Expand ... +func (c BookmarkClient) Expand(ctx context.Context, id BookmarkId, input BookmarkExpandParameters) (result ExpandOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/expand", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/bookmark/method_expand_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/bookmark/method_expand_autorest.go deleted file mode 100644 index c01b051eade..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/bookmark/method_expand_autorest.go +++ /dev/null @@ -1,70 +0,0 @@ -package bookmark - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ExpandOperationResponse struct { - HttpResponse *http.Response - Model *BookmarkExpandResponse -} - -// Expand ... -func (c BookmarkClient) Expand(ctx context.Context, id BookmarkId, input BookmarkExpandParameters) (result ExpandOperationResponse, err error) { - req, err := c.preparerForExpand(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmark.BookmarkClient", "Expand", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmark.BookmarkClient", "Expand", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForExpand(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmark.BookmarkClient", "Expand", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForExpand prepares the Expand request. -func (c BookmarkClient) preparerForExpand(ctx context.Context, id BookmarkId, input BookmarkExpandParameters) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/expand", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForExpand handles the response to the Expand request. The method always -// closes the http.Response Body. -func (c BookmarkClient) responderForExpand(resp *http.Response) (result ExpandOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/bookmarkrelations/client.go b/resource-manager/securityinsights/2022-10-01-preview/bookmarkrelations/client.go index c16a1534a9c..7b2f113e83b 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/bookmarkrelations/client.go +++ b/resource-manager/securityinsights/2022-10-01-preview/bookmarkrelations/client.go @@ -1,18 +1,26 @@ package bookmarkrelations -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type BookmarkRelationsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewBookmarkRelationsClientWithBaseURI(endpoint string) BookmarkRelationsClient { - return BookmarkRelationsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewBookmarkRelationsClientWithBaseURI(sdkApi sdkEnv.Api) (*BookmarkRelationsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "bookmarkrelations", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating BookmarkRelationsClient: %+v", err) } + + return &BookmarkRelationsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-10-01-preview/bookmarkrelations/method_createorupdate.go b/resource-manager/securityinsights/2022-10-01-preview/bookmarkrelations/method_createorupdate.go new file mode 100644 index 00000000000..c62743243a5 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/bookmarkrelations/method_createorupdate.go @@ -0,0 +1,56 @@ +package bookmarkrelations + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Relation +} + +// CreateOrUpdate ... +func (c BookmarkRelationsClient) CreateOrUpdate(ctx context.Context, id BookmarkRelationId, input Relation) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/bookmarkrelations/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/bookmarkrelations/method_createorupdate_autorest.go deleted file mode 100644 index 31cbda7e37e..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/bookmarkrelations/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package bookmarkrelations - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *Relation -} - -// CreateOrUpdate ... -func (c BookmarkRelationsClient) CreateOrUpdate(ctx context.Context, id BookmarkRelationId, input Relation) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarkrelations.BookmarkRelationsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarkrelations.BookmarkRelationsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarkrelations.BookmarkRelationsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c BookmarkRelationsClient) preparerForCreateOrUpdate(ctx context.Context, id BookmarkRelationId, input Relation) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c BookmarkRelationsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/bookmarkrelations/method_delete.go b/resource-manager/securityinsights/2022-10-01-preview/bookmarkrelations/method_delete.go new file mode 100644 index 00000000000..be83fdfe96b --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/bookmarkrelations/method_delete.go @@ -0,0 +1,47 @@ +package bookmarkrelations + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c BookmarkRelationsClient) Delete(ctx context.Context, id BookmarkRelationId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/bookmarkrelations/method_delete_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/bookmarkrelations/method_delete_autorest.go deleted file mode 100644 index b94d5add215..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/bookmarkrelations/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package bookmarkrelations - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c BookmarkRelationsClient) Delete(ctx context.Context, id BookmarkRelationId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarkrelations.BookmarkRelationsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarkrelations.BookmarkRelationsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarkrelations.BookmarkRelationsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c BookmarkRelationsClient) preparerForDelete(ctx context.Context, id BookmarkRelationId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c BookmarkRelationsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/bookmarkrelations/method_get.go b/resource-manager/securityinsights/2022-10-01-preview/bookmarkrelations/method_get.go new file mode 100644 index 00000000000..a689e84623f --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/bookmarkrelations/method_get.go @@ -0,0 +1,51 @@ +package bookmarkrelations + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Relation +} + +// Get ... +func (c BookmarkRelationsClient) Get(ctx context.Context, id BookmarkRelationId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/bookmarkrelations/method_get_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/bookmarkrelations/method_get_autorest.go deleted file mode 100644 index 68c15700cd0..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/bookmarkrelations/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package bookmarkrelations - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *Relation -} - -// Get ... -func (c BookmarkRelationsClient) Get(ctx context.Context, id BookmarkRelationId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarkrelations.BookmarkRelationsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarkrelations.BookmarkRelationsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarkrelations.BookmarkRelationsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c BookmarkRelationsClient) preparerForGet(ctx context.Context, id BookmarkRelationId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c BookmarkRelationsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/bookmarkrelations/method_list.go b/resource-manager/securityinsights/2022-10-01-preview/bookmarkrelations/method_list.go new file mode 100644 index 00000000000..c7b0e80ee33 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/bookmarkrelations/method_list.go @@ -0,0 +1,127 @@ +package bookmarkrelations + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Relation +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Relation +} + +type ListOperationOptions struct { + Filter *string + Orderby *string + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c BookmarkRelationsClient) List(ctx context.Context, id BookmarkId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/relations", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Relation `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c BookmarkRelationsClient) ListComplete(ctx context.Context, id BookmarkId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, RelationOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c BookmarkRelationsClient) ListCompleteMatchingPredicate(ctx context.Context, id BookmarkId, options ListOperationOptions, predicate RelationOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Relation, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/bookmarkrelations/method_list_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/bookmarkrelations/method_list_autorest.go deleted file mode 100644 index df04eb11905..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/bookmarkrelations/method_list_autorest.go +++ /dev/null @@ -1,225 +0,0 @@ -package bookmarkrelations - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]Relation - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []Relation -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ListOperationOptions struct { - Filter *string - Orderby *string - Top *int64 -} - -func DefaultListOperationOptions() ListOperationOptions { - return ListOperationOptions{} -} - -func (o ListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Filter != nil { - out["$filter"] = *o.Filter - } - - if o.Orderby != nil { - out["$orderby"] = *o.Orderby - } - - if o.Top != nil { - out["$top"] = *o.Top - } - - return out -} - -// List ... -func (c BookmarkRelationsClient) List(ctx context.Context, id BookmarkId, options ListOperationOptions) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarkrelations.BookmarkRelationsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarkrelations.BookmarkRelationsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarkrelations.BookmarkRelationsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c BookmarkRelationsClient) preparerForList(ctx context.Context, id BookmarkId, options ListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/relations", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c BookmarkRelationsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c BookmarkRelationsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []Relation `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarkrelations.BookmarkRelationsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarkrelations.BookmarkRelationsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarkrelations.BookmarkRelationsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c BookmarkRelationsClient) ListComplete(ctx context.Context, id BookmarkId, options ListOperationOptions) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, options, RelationOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c BookmarkRelationsClient) ListCompleteMatchingPredicate(ctx context.Context, id BookmarkId, options ListOperationOptions, predicate RelationOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]Relation, 0) - - page, err := c.List(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/bookmarks/client.go b/resource-manager/securityinsights/2022-10-01-preview/bookmarks/client.go index ee8ca229e2d..22469155649 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/bookmarks/client.go +++ b/resource-manager/securityinsights/2022-10-01-preview/bookmarks/client.go @@ -1,18 +1,26 @@ package bookmarks -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type BookmarksClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewBookmarksClientWithBaseURI(endpoint string) BookmarksClient { - return BookmarksClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewBookmarksClientWithBaseURI(sdkApi sdkEnv.Api) (*BookmarksClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "bookmarks", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating BookmarksClient: %+v", err) } + + return &BookmarksClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-10-01-preview/bookmarks/constants.go b/resource-manager/securityinsights/2022-10-01-preview/bookmarks/constants.go index f8d553d0e55..9ec53ffa34f 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/bookmarks/constants.go +++ b/resource-manager/securityinsights/2022-10-01-preview/bookmarks/constants.go @@ -1,6 +1,10 @@ package bookmarks -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -49,6 +53,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -96,6 +113,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, diff --git a/resource-manager/securityinsights/2022-10-01-preview/bookmarks/method_createorupdate.go b/resource-manager/securityinsights/2022-10-01-preview/bookmarks/method_createorupdate.go new file mode 100644 index 00000000000..72b6987ce5b --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/bookmarks/method_createorupdate.go @@ -0,0 +1,56 @@ +package bookmarks + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Bookmark +} + +// CreateOrUpdate ... +func (c BookmarksClient) CreateOrUpdate(ctx context.Context, id BookmarkId, input Bookmark) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/bookmarks/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/bookmarks/method_createorupdate_autorest.go deleted file mode 100644 index 6bae46884df..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/bookmarks/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package bookmarks - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *Bookmark -} - -// CreateOrUpdate ... -func (c BookmarksClient) CreateOrUpdate(ctx context.Context, id BookmarkId, input Bookmark) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c BookmarksClient) preparerForCreateOrUpdate(ctx context.Context, id BookmarkId, input Bookmark) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c BookmarksClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/bookmarks/method_delete.go b/resource-manager/securityinsights/2022-10-01-preview/bookmarks/method_delete.go new file mode 100644 index 00000000000..75eef715a7c --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/bookmarks/method_delete.go @@ -0,0 +1,47 @@ +package bookmarks + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c BookmarksClient) Delete(ctx context.Context, id BookmarkId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/bookmarks/method_delete_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/bookmarks/method_delete_autorest.go deleted file mode 100644 index aa1033f513c..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/bookmarks/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package bookmarks - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c BookmarksClient) Delete(ctx context.Context, id BookmarkId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c BookmarksClient) preparerForDelete(ctx context.Context, id BookmarkId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c BookmarksClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/bookmarks/method_get.go b/resource-manager/securityinsights/2022-10-01-preview/bookmarks/method_get.go new file mode 100644 index 00000000000..b8db3d1b69f --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/bookmarks/method_get.go @@ -0,0 +1,51 @@ +package bookmarks + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Bookmark +} + +// Get ... +func (c BookmarksClient) Get(ctx context.Context, id BookmarkId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/bookmarks/method_get_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/bookmarks/method_get_autorest.go deleted file mode 100644 index c76a6c0c211..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/bookmarks/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package bookmarks - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *Bookmark -} - -// Get ... -func (c BookmarksClient) Get(ctx context.Context, id BookmarkId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c BookmarksClient) preparerForGet(ctx context.Context, id BookmarkId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c BookmarksClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/bookmarks/method_list.go b/resource-manager/securityinsights/2022-10-01-preview/bookmarks/method_list.go new file mode 100644 index 00000000000..432b04c413a --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/bookmarks/method_list.go @@ -0,0 +1,91 @@ +package bookmarks + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Bookmark +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Bookmark +} + +// List ... +func (c BookmarksClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/bookmarks", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Bookmark `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c BookmarksClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, BookmarkOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c BookmarksClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate BookmarkOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Bookmark, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/bookmarks/method_list_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/bookmarks/method_list_autorest.go deleted file mode 100644 index 7c4a69eacea..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/bookmarks/method_list_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package bookmarks - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]Bookmark - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []Bookmark -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c BookmarksClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c BookmarksClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/bookmarks", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c BookmarksClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c BookmarksClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []Bookmark `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c BookmarksClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, BookmarkOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c BookmarksClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate BookmarkOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]Bookmark, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/checkdataconnectorrequirements/client.go b/resource-manager/securityinsights/2022-10-01-preview/checkdataconnectorrequirements/client.go index 1eef55a1676..c01575bd213 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/checkdataconnectorrequirements/client.go +++ b/resource-manager/securityinsights/2022-10-01-preview/checkdataconnectorrequirements/client.go @@ -1,18 +1,26 @@ package checkdataconnectorrequirements -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type CheckDataConnectorRequirementsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewCheckDataConnectorRequirementsClientWithBaseURI(endpoint string) CheckDataConnectorRequirementsClient { - return CheckDataConnectorRequirementsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewCheckDataConnectorRequirementsClientWithBaseURI(sdkApi sdkEnv.Api) (*CheckDataConnectorRequirementsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "checkdataconnectorrequirements", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating CheckDataConnectorRequirementsClient: %+v", err) } + + return &CheckDataConnectorRequirementsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-10-01-preview/checkdataconnectorrequirements/constants.go b/resource-manager/securityinsights/2022-10-01-preview/checkdataconnectorrequirements/constants.go index 5884c4d9c6a..c2cb4a1623a 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/checkdataconnectorrequirements/constants.go +++ b/resource-manager/securityinsights/2022-10-01-preview/checkdataconnectorrequirements/constants.go @@ -1,6 +1,10 @@ package checkdataconnectorrequirements -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -19,6 +23,19 @@ func PossibleValuesForDataConnectorAuthorizationState() []string { } } +func (s *DataConnectorAuthorizationState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataConnectorAuthorizationState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDataConnectorAuthorizationState(input string) (*DataConnectorAuthorizationState, error) { vals := map[string]DataConnectorAuthorizationState{ "invalid": DataConnectorAuthorizationStateInvalid, @@ -83,6 +100,19 @@ func PossibleValuesForDataConnectorKind() []string { } } +func (s *DataConnectorKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataConnectorKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDataConnectorKind(input string) (*DataConnectorKind, error) { vals := map[string]DataConnectorKind{ "apipolling": DataConnectorKindAPIPolling, @@ -131,6 +161,19 @@ func PossibleValuesForDataConnectorLicenseState() []string { } } +func (s *DataConnectorLicenseState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataConnectorLicenseState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDataConnectorLicenseState(input string) (*DataConnectorLicenseState, error) { vals := map[string]DataConnectorLicenseState{ "invalid": DataConnectorLicenseStateInvalid, diff --git a/resource-manager/securityinsights/2022-10-01-preview/checkdataconnectorrequirements/method_dataconnectorscheckrequirementspost.go b/resource-manager/securityinsights/2022-10-01-preview/checkdataconnectorrequirements/method_dataconnectorscheckrequirementspost.go new file mode 100644 index 00000000000..91c387f6a09 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/checkdataconnectorrequirements/method_dataconnectorscheckrequirementspost.go @@ -0,0 +1,56 @@ +package checkdataconnectorrequirements + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataConnectorsCheckRequirementsPostOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DataConnectorRequirementsState +} + +// DataConnectorsCheckRequirementsPost ... +func (c CheckDataConnectorRequirementsClient) DataConnectorsCheckRequirementsPost(ctx context.Context, id WorkspaceId, input DataConnectorsCheckRequirements) (result DataConnectorsCheckRequirementsPostOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/dataConnectorsCheckRequirements", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/checkdataconnectorrequirements/method_dataconnectorscheckrequirementspost_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/checkdataconnectorrequirements/method_dataconnectorscheckrequirementspost_autorest.go deleted file mode 100644 index 596830a1ab4..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/checkdataconnectorrequirements/method_dataconnectorscheckrequirementspost_autorest.go +++ /dev/null @@ -1,70 +0,0 @@ -package checkdataconnectorrequirements - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DataConnectorsCheckRequirementsPostOperationResponse struct { - HttpResponse *http.Response - Model *DataConnectorRequirementsState -} - -// DataConnectorsCheckRequirementsPost ... -func (c CheckDataConnectorRequirementsClient) DataConnectorsCheckRequirementsPost(ctx context.Context, id WorkspaceId, input DataConnectorsCheckRequirements) (result DataConnectorsCheckRequirementsPostOperationResponse, err error) { - req, err := c.preparerForDataConnectorsCheckRequirementsPost(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "checkdataconnectorrequirements.CheckDataConnectorRequirementsClient", "DataConnectorsCheckRequirementsPost", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "checkdataconnectorrequirements.CheckDataConnectorRequirementsClient", "DataConnectorsCheckRequirementsPost", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDataConnectorsCheckRequirementsPost(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "checkdataconnectorrequirements.CheckDataConnectorRequirementsClient", "DataConnectorsCheckRequirementsPost", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDataConnectorsCheckRequirementsPost prepares the DataConnectorsCheckRequirementsPost request. -func (c CheckDataConnectorRequirementsClient) preparerForDataConnectorsCheckRequirementsPost(ctx context.Context, id WorkspaceId, input DataConnectorsCheckRequirements) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/dataConnectorsCheckRequirements", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDataConnectorsCheckRequirementsPost handles the response to the DataConnectorsCheckRequirementsPost request. The method always -// closes the http.Response Body. -func (c CheckDataConnectorRequirementsClient) responderForDataConnectorsCheckRequirementsPost(resp *http.Response) (result DataConnectorsCheckRequirementsPostOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/client.go b/resource-manager/securityinsights/2022-10-01-preview/client.go index 0f85f74fcec..971158b59e8 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/client.go +++ b/resource-manager/securityinsights/2022-10-01-preview/client.go @@ -4,7 +4,8 @@ package v2022_10_01_preview // Licensed under the MIT License. See NOTICE.txt in the project root for license information. import ( - "github.com/Azure/go-autorest/autorest" + "fmt" + "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/actions" "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/alertrules" "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/alertruletemplates" @@ -40,6 +41,8 @@ import ( "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/threatintelligence" "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/watchlistitems" "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/watchlists" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" ) type Client struct { @@ -80,148 +83,252 @@ type Client struct { Watchlists *watchlists.WatchlistsClient } -func NewClientWithBaseURI(endpoint string, configureAuthFunc func(c *autorest.Client)) Client { - - actionsClient := actions.NewActionsClientWithBaseURI(endpoint) - configureAuthFunc(&actionsClient.Client) - - alertRuleTemplatesClient := alertruletemplates.NewAlertRuleTemplatesClientWithBaseURI(endpoint) - configureAuthFunc(&alertRuleTemplatesClient.Client) +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + actionsClient, err := actions.NewActionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Actions client: %+v", err) + } + configureFunc(actionsClient.Client) - alertRulesClient := alertrules.NewAlertRulesClientWithBaseURI(endpoint) - configureAuthFunc(&alertRulesClient.Client) + alertRuleTemplatesClient, err := alertruletemplates.NewAlertRuleTemplatesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AlertRuleTemplates client: %+v", err) + } + configureFunc(alertRuleTemplatesClient.Client) - automationRulesClient := automationrules.NewAutomationRulesClientWithBaseURI(endpoint) - configureAuthFunc(&automationRulesClient.Client) + alertRulesClient, err := alertrules.NewAlertRulesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AlertRules client: %+v", err) + } + configureFunc(alertRulesClient.Client) - bookmarkClient := bookmark.NewBookmarkClientWithBaseURI(endpoint) - configureAuthFunc(&bookmarkClient.Client) + automationRulesClient, err := automationrules.NewAutomationRulesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AutomationRules client: %+v", err) + } + configureFunc(automationRulesClient.Client) - bookmarkRelationsClient := bookmarkrelations.NewBookmarkRelationsClientWithBaseURI(endpoint) - configureAuthFunc(&bookmarkRelationsClient.Client) + bookmarkClient, err := bookmark.NewBookmarkClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Bookmark client: %+v", err) + } + configureFunc(bookmarkClient.Client) - bookmarksClient := bookmarks.NewBookmarksClientWithBaseURI(endpoint) - configureAuthFunc(&bookmarksClient.Client) + bookmarkRelationsClient, err := bookmarkrelations.NewBookmarkRelationsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building BookmarkRelations client: %+v", err) + } + configureFunc(bookmarkRelationsClient.Client) - checkDataConnectorRequirementsClient := checkdataconnectorrequirements.NewCheckDataConnectorRequirementsClientWithBaseURI(endpoint) - configureAuthFunc(&checkDataConnectorRequirementsClient.Client) + bookmarksClient, err := bookmarks.NewBookmarksClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Bookmarks client: %+v", err) + } + configureFunc(bookmarksClient.Client) - dataConnectorsClient := dataconnectors.NewDataConnectorsClientWithBaseURI(endpoint) - configureAuthFunc(&dataConnectorsClient.Client) + checkDataConnectorRequirementsClient, err := checkdataconnectorrequirements.NewCheckDataConnectorRequirementsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building CheckDataConnectorRequirements client: %+v", err) + } + configureFunc(checkDataConnectorRequirementsClient.Client) - dataConnectorsConnectClient := dataconnectorsconnect.NewDataConnectorsConnectClientWithBaseURI(endpoint) - configureAuthFunc(&dataConnectorsConnectClient.Client) + dataConnectorsClient, err := dataconnectors.NewDataConnectorsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DataConnectors client: %+v", err) + } + configureFunc(dataConnectorsClient.Client) - dataConnectorsDisconnectClient := dataconnectorsdisconnect.NewDataConnectorsDisconnectClientWithBaseURI(endpoint) - configureAuthFunc(&dataConnectorsDisconnectClient.Client) + dataConnectorsConnectClient, err := dataconnectorsconnect.NewDataConnectorsConnectClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DataConnectorsConnect client: %+v", err) + } + configureFunc(dataConnectorsConnectClient.Client) - enrichmentClient := enrichment.NewEnrichmentClientWithBaseURI(endpoint) - configureAuthFunc(&enrichmentClient.Client) + dataConnectorsDisconnectClient, err := dataconnectorsdisconnect.NewDataConnectorsDisconnectClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DataConnectorsDisconnect client: %+v", err) + } + configureFunc(dataConnectorsDisconnectClient.Client) - entitiesClient := entities.NewEntitiesClientWithBaseURI(endpoint) - configureAuthFunc(&entitiesClient.Client) + enrichmentClient, err := enrichment.NewEnrichmentClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Enrichment client: %+v", err) + } + configureFunc(enrichmentClient.Client) - entityQueriesClient := entityqueries.NewEntityQueriesClientWithBaseURI(endpoint) - configureAuthFunc(&entityQueriesClient.Client) + entitiesClient, err := entities.NewEntitiesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Entities client: %+v", err) + } + configureFunc(entitiesClient.Client) - entityRelationsClient := entityrelations.NewEntityRelationsClientWithBaseURI(endpoint) - configureAuthFunc(&entityRelationsClient.Client) + entityQueriesClient, err := entityqueries.NewEntityQueriesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building EntityQueries client: %+v", err) + } + configureFunc(entityQueriesClient.Client) - entityTypesClient := entitytypes.NewEntityTypesClientWithBaseURI(endpoint) - configureAuthFunc(&entityTypesClient.Client) + entityRelationsClient, err := entityrelations.NewEntityRelationsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building EntityRelations client: %+v", err) + } + configureFunc(entityRelationsClient.Client) - fileImportsClient := fileimports.NewFileImportsClientWithBaseURI(endpoint) - configureAuthFunc(&fileImportsClient.Client) + entityTypesClient, err := entitytypes.NewEntityTypesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building EntityTypes client: %+v", err) + } + configureFunc(entityTypesClient.Client) - incidentAlertsClient := incidentalerts.NewIncidentAlertsClientWithBaseURI(endpoint) - configureAuthFunc(&incidentAlertsClient.Client) + fileImportsClient, err := fileimports.NewFileImportsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building FileImports client: %+v", err) + } + configureFunc(fileImportsClient.Client) - incidentBookmarksClient := incidentbookmarks.NewIncidentBookmarksClientWithBaseURI(endpoint) - configureAuthFunc(&incidentBookmarksClient.Client) + incidentAlertsClient, err := incidentalerts.NewIncidentAlertsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IncidentAlerts client: %+v", err) + } + configureFunc(incidentAlertsClient.Client) - incidentCommentsClient := incidentcomments.NewIncidentCommentsClientWithBaseURI(endpoint) - configureAuthFunc(&incidentCommentsClient.Client) + incidentBookmarksClient, err := incidentbookmarks.NewIncidentBookmarksClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IncidentBookmarks client: %+v", err) + } + configureFunc(incidentBookmarksClient.Client) - incidentEntitiesClient := incidententities.NewIncidentEntitiesClientWithBaseURI(endpoint) - configureAuthFunc(&incidentEntitiesClient.Client) + incidentCommentsClient, err := incidentcomments.NewIncidentCommentsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IncidentComments client: %+v", err) + } + configureFunc(incidentCommentsClient.Client) - incidentRelationsClient := incidentrelations.NewIncidentRelationsClientWithBaseURI(endpoint) - configureAuthFunc(&incidentRelationsClient.Client) + incidentEntitiesClient, err := incidententities.NewIncidentEntitiesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IncidentEntities client: %+v", err) + } + configureFunc(incidentEntitiesClient.Client) - incidentTeamClient := incidentteam.NewIncidentTeamClientWithBaseURI(endpoint) - configureAuthFunc(&incidentTeamClient.Client) + incidentRelationsClient, err := incidentrelations.NewIncidentRelationsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IncidentRelations client: %+v", err) + } + configureFunc(incidentRelationsClient.Client) - incidentsClient := incidents.NewIncidentsClientWithBaseURI(endpoint) - configureAuthFunc(&incidentsClient.Client) + incidentTeamClient, err := incidentteam.NewIncidentTeamClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IncidentTeam client: %+v", err) + } + configureFunc(incidentTeamClient.Client) - manualTriggerClient := manualtrigger.NewManualTriggerClientWithBaseURI(endpoint) - configureAuthFunc(&manualTriggerClient.Client) + incidentsClient, err := incidents.NewIncidentsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Incidents client: %+v", err) + } + configureFunc(incidentsClient.Client) - metadataClient := metadata.NewMetadataClientWithBaseURI(endpoint) - configureAuthFunc(&metadataClient.Client) + manualTriggerClient, err := manualtrigger.NewManualTriggerClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ManualTrigger client: %+v", err) + } + configureFunc(manualTriggerClient.Client) - officeConsentsClient := officeconsents.NewOfficeConsentsClientWithBaseURI(endpoint) - configureAuthFunc(&officeConsentsClient.Client) + metadataClient, err := metadata.NewMetadataClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Metadata client: %+v", err) + } + configureFunc(metadataClient.Client) - repositoriesClient := repositories.NewRepositoriesClientWithBaseURI(endpoint) - configureAuthFunc(&repositoriesClient.Client) + officeConsentsClient, err := officeconsents.NewOfficeConsentsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building OfficeConsents client: %+v", err) + } + configureFunc(officeConsentsClient.Client) - securityMLAnalyticsSettingsClient := securitymlanalyticssettings.NewSecurityMLAnalyticsSettingsClientWithBaseURI(endpoint) - configureAuthFunc(&securityMLAnalyticsSettingsClient.Client) + repositoriesClient, err := repositories.NewRepositoriesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Repositories client: %+v", err) + } + configureFunc(repositoriesClient.Client) - sentinelOnboardingStatesClient := sentinelonboardingstates.NewSentinelOnboardingStatesClientWithBaseURI(endpoint) - configureAuthFunc(&sentinelOnboardingStatesClient.Client) + securityMLAnalyticsSettingsClient, err := securitymlanalyticssettings.NewSecurityMLAnalyticsSettingsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SecurityMLAnalyticsSettings client: %+v", err) + } + configureFunc(securityMLAnalyticsSettingsClient.Client) - settingsClient := settings.NewSettingsClientWithBaseURI(endpoint) - configureAuthFunc(&settingsClient.Client) + sentinelOnboardingStatesClient, err := sentinelonboardingstates.NewSentinelOnboardingStatesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SentinelOnboardingStates client: %+v", err) + } + configureFunc(sentinelOnboardingStatesClient.Client) - sourceControlsClient := sourcecontrols.NewSourceControlsClientWithBaseURI(endpoint) - configureAuthFunc(&sourceControlsClient.Client) + settingsClient, err := settings.NewSettingsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Settings client: %+v", err) + } + configureFunc(settingsClient.Client) - threatIntelligenceClient := threatintelligence.NewThreatIntelligenceClientWithBaseURI(endpoint) - configureAuthFunc(&threatIntelligenceClient.Client) + sourceControlsClient, err := sourcecontrols.NewSourceControlsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SourceControls client: %+v", err) + } + configureFunc(sourceControlsClient.Client) - watchlistItemsClient := watchlistitems.NewWatchlistItemsClientWithBaseURI(endpoint) - configureAuthFunc(&watchlistItemsClient.Client) + threatIntelligenceClient, err := threatintelligence.NewThreatIntelligenceClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ThreatIntelligence client: %+v", err) + } + configureFunc(threatIntelligenceClient.Client) - watchlistsClient := watchlists.NewWatchlistsClientWithBaseURI(endpoint) - configureAuthFunc(&watchlistsClient.Client) + watchlistItemsClient, err := watchlistitems.NewWatchlistItemsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building WatchlistItems client: %+v", err) + } + configureFunc(watchlistItemsClient.Client) - return Client{ - Actions: &actionsClient, - AlertRuleTemplates: &alertRuleTemplatesClient, - AlertRules: &alertRulesClient, - AutomationRules: &automationRulesClient, - Bookmark: &bookmarkClient, - BookmarkRelations: &bookmarkRelationsClient, - Bookmarks: &bookmarksClient, - CheckDataConnectorRequirements: &checkDataConnectorRequirementsClient, - DataConnectors: &dataConnectorsClient, - DataConnectorsConnect: &dataConnectorsConnectClient, - DataConnectorsDisconnect: &dataConnectorsDisconnectClient, - Enrichment: &enrichmentClient, - Entities: &entitiesClient, - EntityQueries: &entityQueriesClient, - EntityRelations: &entityRelationsClient, - EntityTypes: &entityTypesClient, - FileImports: &fileImportsClient, - IncidentAlerts: &incidentAlertsClient, - IncidentBookmarks: &incidentBookmarksClient, - IncidentComments: &incidentCommentsClient, - IncidentEntities: &incidentEntitiesClient, - IncidentRelations: &incidentRelationsClient, - IncidentTeam: &incidentTeamClient, - Incidents: &incidentsClient, - ManualTrigger: &manualTriggerClient, - Metadata: &metadataClient, - OfficeConsents: &officeConsentsClient, - Repositories: &repositoriesClient, - SecurityMLAnalyticsSettings: &securityMLAnalyticsSettingsClient, - SentinelOnboardingStates: &sentinelOnboardingStatesClient, - Settings: &settingsClient, - SourceControls: &sourceControlsClient, - ThreatIntelligence: &threatIntelligenceClient, - WatchlistItems: &watchlistItemsClient, - Watchlists: &watchlistsClient, + watchlistsClient, err := watchlists.NewWatchlistsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Watchlists client: %+v", err) } + configureFunc(watchlistsClient.Client) + + return &Client{ + Actions: actionsClient, + AlertRuleTemplates: alertRuleTemplatesClient, + AlertRules: alertRulesClient, + AutomationRules: automationRulesClient, + Bookmark: bookmarkClient, + BookmarkRelations: bookmarkRelationsClient, + Bookmarks: bookmarksClient, + CheckDataConnectorRequirements: checkDataConnectorRequirementsClient, + DataConnectors: dataConnectorsClient, + DataConnectorsConnect: dataConnectorsConnectClient, + DataConnectorsDisconnect: dataConnectorsDisconnectClient, + Enrichment: enrichmentClient, + Entities: entitiesClient, + EntityQueries: entityQueriesClient, + EntityRelations: entityRelationsClient, + EntityTypes: entityTypesClient, + FileImports: fileImportsClient, + IncidentAlerts: incidentAlertsClient, + IncidentBookmarks: incidentBookmarksClient, + IncidentComments: incidentCommentsClient, + IncidentEntities: incidentEntitiesClient, + IncidentRelations: incidentRelationsClient, + IncidentTeam: incidentTeamClient, + Incidents: incidentsClient, + ManualTrigger: manualTriggerClient, + Metadata: metadataClient, + OfficeConsents: officeConsentsClient, + Repositories: repositoriesClient, + SecurityMLAnalyticsSettings: securityMLAnalyticsSettingsClient, + SentinelOnboardingStates: sentinelOnboardingStatesClient, + Settings: settingsClient, + SourceControls: sourceControlsClient, + ThreatIntelligence: threatIntelligenceClient, + WatchlistItems: watchlistItemsClient, + Watchlists: watchlistsClient, + }, nil } diff --git a/resource-manager/securityinsights/2022-10-01-preview/dataconnectors/client.go b/resource-manager/securityinsights/2022-10-01-preview/dataconnectors/client.go index cf334b72568..8ed0120c79a 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/dataconnectors/client.go +++ b/resource-manager/securityinsights/2022-10-01-preview/dataconnectors/client.go @@ -1,18 +1,26 @@ package dataconnectors -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type DataConnectorsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewDataConnectorsClientWithBaseURI(endpoint string) DataConnectorsClient { - return DataConnectorsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewDataConnectorsClientWithBaseURI(sdkApi sdkEnv.Api) (*DataConnectorsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "dataconnectors", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DataConnectorsClient: %+v", err) } + + return &DataConnectorsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-10-01-preview/dataconnectors/constants.go b/resource-manager/securityinsights/2022-10-01-preview/dataconnectors/constants.go index 1a556e835bb..ae527d22647 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/dataconnectors/constants.go +++ b/resource-manager/securityinsights/2022-10-01-preview/dataconnectors/constants.go @@ -1,6 +1,10 @@ package dataconnectors -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -29,6 +33,19 @@ func PossibleValuesForConnectivityType() []string { } } +func (s *ConnectivityType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConnectivityType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConnectivityType(input string) (*ConnectivityType, error) { vals := map[string]ConnectivityType{ "isconnectedquery": ConnectivityTypeIsConnectedQuery, @@ -92,6 +109,19 @@ func PossibleValuesForDataConnectorKind() []string { } } +func (s *DataConnectorKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataConnectorKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDataConnectorKind(input string) (*DataConnectorKind, error) { vals := map[string]DataConnectorKind{ "apipolling": DataConnectorKindAPIPolling, @@ -138,6 +168,19 @@ func PossibleValuesForDataTypeState() []string { } } +func (s *DataTypeState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataTypeState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDataTypeState(input string) (*DataTypeState, error) { vals := map[string]DataTypeState{ "disabled": DataTypeStateDisabled, @@ -168,6 +211,19 @@ func PossibleValuesForPermissionProviderScope() []string { } } +func (s *PermissionProviderScope) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePermissionProviderScope(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parsePermissionProviderScope(input string) (*PermissionProviderScope, error) { vals := map[string]PermissionProviderScope{ "resourcegroup": PermissionProviderScopeResourceGroup, @@ -199,6 +255,19 @@ func PossibleValuesForPollingFrequency() []string { } } +func (s *PollingFrequency) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePollingFrequency(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parsePollingFrequency(input string) (*PollingFrequency, error) { vals := map[string]PollingFrequency{ "onceaday": PollingFrequencyOnceADay, @@ -236,6 +305,19 @@ func PossibleValuesForProviderName() []string { } } +func (s *ProviderName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProviderName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseProviderName(input string) (*ProviderName, error) { vals := map[string]ProviderName{ "microsoft.authorization/policyassignments": ProviderNameMicrosoftPointAuthorizationPolicyAssignments, @@ -270,6 +352,19 @@ func PossibleValuesForSettingType() []string { } } +func (s *SettingType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSettingType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSettingType(input string) (*SettingType, error) { vals := map[string]SettingType{ "copyablelabel": SettingTypeCopyableLabel, diff --git a/resource-manager/securityinsights/2022-10-01-preview/dataconnectors/method_createorupdate.go b/resource-manager/securityinsights/2022-10-01-preview/dataconnectors/method_createorupdate.go new file mode 100644 index 00000000000..c5f6e5d1503 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/dataconnectors/method_createorupdate.go @@ -0,0 +1,63 @@ +package dataconnectors + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DataConnector +} + +// CreateOrUpdate ... +func (c DataConnectorsClient) CreateOrUpdate(ctx context.Context, id DataConnectorId, input DataConnector) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalDataConnectorImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/dataconnectors/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/dataconnectors/method_createorupdate_autorest.go deleted file mode 100644 index 1f259eca36c..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/dataconnectors/method_createorupdate_autorest.go +++ /dev/null @@ -1,78 +0,0 @@ -package dataconnectors - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *DataConnector -} - -// CreateOrUpdate ... -func (c DataConnectorsClient) CreateOrUpdate(ctx context.Context, id DataConnectorId, input DataConnector) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c DataConnectorsClient) preparerForCreateOrUpdate(ctx context.Context, id DataConnectorId, input DataConnector) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c DataConnectorsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalDataConnectorImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/dataconnectors/method_delete.go b/resource-manager/securityinsights/2022-10-01-preview/dataconnectors/method_delete.go new file mode 100644 index 00000000000..8461ec6d8a1 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/dataconnectors/method_delete.go @@ -0,0 +1,47 @@ +package dataconnectors + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c DataConnectorsClient) Delete(ctx context.Context, id DataConnectorId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/dataconnectors/method_delete_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/dataconnectors/method_delete_autorest.go deleted file mode 100644 index ac4ddf57441..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/dataconnectors/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package dataconnectors - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c DataConnectorsClient) Delete(ctx context.Context, id DataConnectorId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c DataConnectorsClient) preparerForDelete(ctx context.Context, id DataConnectorId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c DataConnectorsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/dataconnectors/method_get.go b/resource-manager/securityinsights/2022-10-01-preview/dataconnectors/method_get.go new file mode 100644 index 00000000000..3511ba85477 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/dataconnectors/method_get.go @@ -0,0 +1,58 @@ +package dataconnectors + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DataConnector +} + +// Get ... +func (c DataConnectorsClient) Get(ctx context.Context, id DataConnectorId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalDataConnectorImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/dataconnectors/method_get_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/dataconnectors/method_get_autorest.go deleted file mode 100644 index af56be19c9c..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/dataconnectors/method_get_autorest.go +++ /dev/null @@ -1,77 +0,0 @@ -package dataconnectors - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *DataConnector -} - -// Get ... -func (c DataConnectorsClient) Get(ctx context.Context, id DataConnectorId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c DataConnectorsClient) preparerForGet(ctx context.Context, id DataConnectorId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c DataConnectorsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalDataConnectorImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/dataconnectors/method_list.go b/resource-manager/securityinsights/2022-10-01-preview/dataconnectors/method_list.go new file mode 100644 index 00000000000..6975384fdee --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/dataconnectors/method_list.go @@ -0,0 +1,103 @@ +package dataconnectors + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DataConnector +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []DataConnector +} + +// List ... +func (c DataConnectorsClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/dataConnectors", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]DataConnector, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalDataConnectorImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for DataConnector (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// ListComplete retrieves all the results into a single object +func (c DataConnectorsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, DataConnectorOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DataConnectorsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate DataConnectorOperationPredicate) (result ListCompleteResult, err error) { + items := make([]DataConnector, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/dataconnectors/method_list_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/dataconnectors/method_list_autorest.go deleted file mode 100644 index e08d153a6eb..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/dataconnectors/method_list_autorest.go +++ /dev/null @@ -1,196 +0,0 @@ -package dataconnectors - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]DataConnector - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []DataConnector -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c DataConnectorsClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c DataConnectorsClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/dataConnectors", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c DataConnectorsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c DataConnectorsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]DataConnector, 0) - for i, v := range respObj.Values { - val, err := unmarshalDataConnectorImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for DataConnector (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c DataConnectorsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, DataConnectorOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c DataConnectorsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate DataConnectorOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]DataConnector, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/dataconnectorsconnect/client.go b/resource-manager/securityinsights/2022-10-01-preview/dataconnectorsconnect/client.go index dd44f929cc5..f4ed6b1fb50 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/dataconnectorsconnect/client.go +++ b/resource-manager/securityinsights/2022-10-01-preview/dataconnectorsconnect/client.go @@ -1,18 +1,26 @@ package dataconnectorsconnect -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type DataConnectorsConnectClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewDataConnectorsConnectClientWithBaseURI(endpoint string) DataConnectorsConnectClient { - return DataConnectorsConnectClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewDataConnectorsConnectClientWithBaseURI(sdkApi sdkEnv.Api) (*DataConnectorsConnectClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "dataconnectorsconnect", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DataConnectorsConnectClient: %+v", err) } + + return &DataConnectorsConnectClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-10-01-preview/dataconnectorsconnect/constants.go b/resource-manager/securityinsights/2022-10-01-preview/dataconnectorsconnect/constants.go index 04ec07ac553..a5b7f1713ca 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/dataconnectorsconnect/constants.go +++ b/resource-manager/securityinsights/2022-10-01-preview/dataconnectorsconnect/constants.go @@ -1,6 +1,10 @@ package dataconnectorsconnect -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -21,6 +25,19 @@ func PossibleValuesForConnectAuthKind() []string { } } +func (s *ConnectAuthKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConnectAuthKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConnectAuthKind(input string) (*ConnectAuthKind, error) { vals := map[string]ConnectAuthKind{ "apikey": ConnectAuthKindAPIKey, diff --git a/resource-manager/securityinsights/2022-10-01-preview/dataconnectorsconnect/method_dataconnectorsconnect.go b/resource-manager/securityinsights/2022-10-01-preview/dataconnectorsconnect/method_dataconnectorsconnect.go new file mode 100644 index 00000000000..50018e5b900 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/dataconnectorsconnect/method_dataconnectorsconnect.go @@ -0,0 +1,51 @@ +package dataconnectorsconnect + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataConnectorsConnectOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// DataConnectorsConnect ... +func (c DataConnectorsConnectClient) DataConnectorsConnect(ctx context.Context, id DataConnectorId, input DataConnectorConnectBody) (result DataConnectorsConnectOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/connect", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/dataconnectorsconnect/method_dataconnectorsconnect_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/dataconnectorsconnect/method_dataconnectorsconnect_autorest.go deleted file mode 100644 index 191360dda4c..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/dataconnectorsconnect/method_dataconnectorsconnect_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package dataconnectorsconnect - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DataConnectorsConnectOperationResponse struct { - HttpResponse *http.Response -} - -// DataConnectorsConnect ... -func (c DataConnectorsConnectClient) DataConnectorsConnect(ctx context.Context, id DataConnectorId, input DataConnectorConnectBody) (result DataConnectorsConnectOperationResponse, err error) { - req, err := c.preparerForDataConnectorsConnect(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectorsconnect.DataConnectorsConnectClient", "DataConnectorsConnect", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectorsconnect.DataConnectorsConnectClient", "DataConnectorsConnect", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDataConnectorsConnect(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectorsconnect.DataConnectorsConnectClient", "DataConnectorsConnect", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDataConnectorsConnect prepares the DataConnectorsConnect request. -func (c DataConnectorsConnectClient) preparerForDataConnectorsConnect(ctx context.Context, id DataConnectorId, input DataConnectorConnectBody) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/connect", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDataConnectorsConnect handles the response to the DataConnectorsConnect request. The method always -// closes the http.Response Body. -func (c DataConnectorsConnectClient) responderForDataConnectorsConnect(resp *http.Response) (result DataConnectorsConnectOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/dataconnectorsdisconnect/client.go b/resource-manager/securityinsights/2022-10-01-preview/dataconnectorsdisconnect/client.go index cd8304c370a..57ec64abb3c 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/dataconnectorsdisconnect/client.go +++ b/resource-manager/securityinsights/2022-10-01-preview/dataconnectorsdisconnect/client.go @@ -1,18 +1,26 @@ package dataconnectorsdisconnect -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type DataConnectorsDisconnectClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewDataConnectorsDisconnectClientWithBaseURI(endpoint string) DataConnectorsDisconnectClient { - return DataConnectorsDisconnectClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewDataConnectorsDisconnectClientWithBaseURI(sdkApi sdkEnv.Api) (*DataConnectorsDisconnectClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "dataconnectorsdisconnect", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DataConnectorsDisconnectClient: %+v", err) } + + return &DataConnectorsDisconnectClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-10-01-preview/dataconnectorsdisconnect/method_dataconnectorsdisconnect.go b/resource-manager/securityinsights/2022-10-01-preview/dataconnectorsdisconnect/method_dataconnectorsdisconnect.go new file mode 100644 index 00000000000..2a883a2c958 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/dataconnectorsdisconnect/method_dataconnectorsdisconnect.go @@ -0,0 +1,47 @@ +package dataconnectorsdisconnect + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataConnectorsDisconnectOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// DataConnectorsDisconnect ... +func (c DataConnectorsDisconnectClient) DataConnectorsDisconnect(ctx context.Context, id DataConnectorId) (result DataConnectorsDisconnectOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/disconnect", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/dataconnectorsdisconnect/method_dataconnectorsdisconnect_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/dataconnectorsdisconnect/method_dataconnectorsdisconnect_autorest.go deleted file mode 100644 index 61c1f036044..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/dataconnectorsdisconnect/method_dataconnectorsdisconnect_autorest.go +++ /dev/null @@ -1,67 +0,0 @@ -package dataconnectorsdisconnect - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DataConnectorsDisconnectOperationResponse struct { - HttpResponse *http.Response -} - -// DataConnectorsDisconnect ... -func (c DataConnectorsDisconnectClient) DataConnectorsDisconnect(ctx context.Context, id DataConnectorId) (result DataConnectorsDisconnectOperationResponse, err error) { - req, err := c.preparerForDataConnectorsDisconnect(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectorsdisconnect.DataConnectorsDisconnectClient", "DataConnectorsDisconnect", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectorsdisconnect.DataConnectorsDisconnectClient", "DataConnectorsDisconnect", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDataConnectorsDisconnect(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectorsdisconnect.DataConnectorsDisconnectClient", "DataConnectorsDisconnect", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDataConnectorsDisconnect prepares the DataConnectorsDisconnect request. -func (c DataConnectorsDisconnectClient) preparerForDataConnectorsDisconnect(ctx context.Context, id DataConnectorId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/disconnect", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDataConnectorsDisconnect handles the response to the DataConnectorsDisconnect request. The method always -// closes the http.Response Body. -func (c DataConnectorsDisconnectClient) responderForDataConnectorsDisconnect(resp *http.Response) (result DataConnectorsDisconnectOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/enrichment/client.go b/resource-manager/securityinsights/2022-10-01-preview/enrichment/client.go index 86c852a64d4..f60a3bef882 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/enrichment/client.go +++ b/resource-manager/securityinsights/2022-10-01-preview/enrichment/client.go @@ -1,18 +1,26 @@ package enrichment -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type EnrichmentClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewEnrichmentClientWithBaseURI(endpoint string) EnrichmentClient { - return EnrichmentClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewEnrichmentClientWithBaseURI(sdkApi sdkEnv.Api) (*EnrichmentClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "enrichment", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating EnrichmentClient: %+v", err) } + + return &EnrichmentClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-10-01-preview/enrichment/method_domainwhoisget.go b/resource-manager/securityinsights/2022-10-01-preview/enrichment/method_domainwhoisget.go new file mode 100644 index 00000000000..5598e43044b --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/enrichment/method_domainwhoisget.go @@ -0,0 +1,81 @@ +package enrichment + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DomainWhoisGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EnrichmentDomainWhois +} + +type DomainWhoisGetOperationOptions struct { + Domain *string +} + +func DefaultDomainWhoisGetOperationOptions() DomainWhoisGetOperationOptions { + return DomainWhoisGetOperationOptions{} +} + +func (o DomainWhoisGetOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o DomainWhoisGetOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DomainWhoisGetOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Domain != nil { + out.Append("domain", fmt.Sprintf("%v", *o.Domain)) + } + return &out +} + +// DomainWhoisGet ... +func (c EnrichmentClient) DomainWhoisGet(ctx context.Context, id commonids.ResourceGroupId, options DomainWhoisGetOperationOptions) (result DomainWhoisGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/enrichment/domain/whois", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/enrichment/method_domainwhoisget_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/enrichment/method_domainwhoisget_autorest.go deleted file mode 100644 index 1e0a9800903..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/enrichment/method_domainwhoisget_autorest.go +++ /dev/null @@ -1,99 +0,0 @@ -package enrichment - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DomainWhoisGetOperationResponse struct { - HttpResponse *http.Response - Model *EnrichmentDomainWhois -} - -type DomainWhoisGetOperationOptions struct { - Domain *string -} - -func DefaultDomainWhoisGetOperationOptions() DomainWhoisGetOperationOptions { - return DomainWhoisGetOperationOptions{} -} - -func (o DomainWhoisGetOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o DomainWhoisGetOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Domain != nil { - out["domain"] = *o.Domain - } - - return out -} - -// DomainWhoisGet ... -func (c EnrichmentClient) DomainWhoisGet(ctx context.Context, id commonids.ResourceGroupId, options DomainWhoisGetOperationOptions) (result DomainWhoisGetOperationResponse, err error) { - req, err := c.preparerForDomainWhoisGet(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "enrichment.EnrichmentClient", "DomainWhoisGet", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "enrichment.EnrichmentClient", "DomainWhoisGet", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDomainWhoisGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "enrichment.EnrichmentClient", "DomainWhoisGet", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDomainWhoisGet prepares the DomainWhoisGet request. -func (c EnrichmentClient) preparerForDomainWhoisGet(ctx context.Context, id commonids.ResourceGroupId, options DomainWhoisGetOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/enrichment/domain/whois", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDomainWhoisGet handles the response to the DomainWhoisGet request. The method always -// closes the http.Response Body. -func (c EnrichmentClient) responderForDomainWhoisGet(resp *http.Response) (result DomainWhoisGetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/enrichment/method_ipgeodataget.go b/resource-manager/securityinsights/2022-10-01-preview/enrichment/method_ipgeodataget.go new file mode 100644 index 00000000000..05e73d79b5c --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/enrichment/method_ipgeodataget.go @@ -0,0 +1,81 @@ +package enrichment + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IPGeodataGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EnrichmentIPGeodata +} + +type IPGeodataGetOperationOptions struct { + IPAddress *string +} + +func DefaultIPGeodataGetOperationOptions() IPGeodataGetOperationOptions { + return IPGeodataGetOperationOptions{} +} + +func (o IPGeodataGetOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o IPGeodataGetOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o IPGeodataGetOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.IPAddress != nil { + out.Append("ipAddress", fmt.Sprintf("%v", *o.IPAddress)) + } + return &out +} + +// IPGeodataGet ... +func (c EnrichmentClient) IPGeodataGet(ctx context.Context, id commonids.ResourceGroupId, options IPGeodataGetOperationOptions) (result IPGeodataGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/enrichment/ip/geodata", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/enrichment/method_ipgeodataget_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/enrichment/method_ipgeodataget_autorest.go deleted file mode 100644 index 8c489e6da71..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/enrichment/method_ipgeodataget_autorest.go +++ /dev/null @@ -1,99 +0,0 @@ -package enrichment - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IPGeodataGetOperationResponse struct { - HttpResponse *http.Response - Model *EnrichmentIPGeodata -} - -type IPGeodataGetOperationOptions struct { - IPAddress *string -} - -func DefaultIPGeodataGetOperationOptions() IPGeodataGetOperationOptions { - return IPGeodataGetOperationOptions{} -} - -func (o IPGeodataGetOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o IPGeodataGetOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.IPAddress != nil { - out["ipAddress"] = *o.IPAddress - } - - return out -} - -// IPGeodataGet ... -func (c EnrichmentClient) IPGeodataGet(ctx context.Context, id commonids.ResourceGroupId, options IPGeodataGetOperationOptions) (result IPGeodataGetOperationResponse, err error) { - req, err := c.preparerForIPGeodataGet(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "enrichment.EnrichmentClient", "IPGeodataGet", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "enrichment.EnrichmentClient", "IPGeodataGet", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIPGeodataGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "enrichment.EnrichmentClient", "IPGeodataGet", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIPGeodataGet prepares the IPGeodataGet request. -func (c EnrichmentClient) preparerForIPGeodataGet(ctx context.Context, id commonids.ResourceGroupId, options IPGeodataGetOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/enrichment/ip/geodata", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIPGeodataGet handles the response to the IPGeodataGet request. The method always -// closes the http.Response Body. -func (c EnrichmentClient) responderForIPGeodataGet(resp *http.Response) (result IPGeodataGetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/entities/client.go b/resource-manager/securityinsights/2022-10-01-preview/entities/client.go index c9a2f082154..69f26c8d7e5 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/entities/client.go +++ b/resource-manager/securityinsights/2022-10-01-preview/entities/client.go @@ -1,18 +1,26 @@ package entities -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type EntitiesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewEntitiesClientWithBaseURI(endpoint string) EntitiesClient { - return EntitiesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewEntitiesClientWithBaseURI(sdkApi sdkEnv.Api) (*EntitiesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "entities", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating EntitiesClient: %+v", err) } + + return &EntitiesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-10-01-preview/entities/constants.go b/resource-manager/securityinsights/2022-10-01-preview/entities/constants.go index ebbe9ba5469..440bec40ce5 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/entities/constants.go +++ b/resource-manager/securityinsights/2022-10-01-preview/entities/constants.go @@ -1,6 +1,10 @@ package entities -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -23,6 +27,19 @@ func PossibleValuesForAlertSeverity() []string { } } +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertSeverity(input string) (*AlertSeverity, error) { vals := map[string]AlertSeverity{ "high": AlertSeverityHigh, @@ -51,6 +68,19 @@ func PossibleValuesForEntityItemQueryKind() []string { } } +func (s *EntityItemQueryKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityItemQueryKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityItemQueryKind(input string) (*EntityItemQueryKind, error) { vals := map[string]EntityItemQueryKind{ "insight": EntityItemQueryKindInsight, @@ -118,6 +148,19 @@ func PossibleValuesForEntityKind() []string { } } +func (s *EntityKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityKind(input string) (*EntityKind, error) { vals := map[string]EntityKind{ "account": EntityKindAccount, @@ -168,6 +211,19 @@ func PossibleValuesForEntityQueryKind() []string { } } +func (s *EntityQueryKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityQueryKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityQueryKind(input string) (*EntityQueryKind, error) { vals := map[string]EntityQueryKind{ "activity": EntityQueryKindActivity, @@ -201,6 +257,19 @@ func PossibleValuesForEntityTimelineKind() []string { } } +func (s *EntityTimelineKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityTimelineKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityTimelineKind(input string) (*EntityTimelineKind, error) { vals := map[string]EntityTimelineKind{ "activity": EntityTimelineKindActivity, @@ -271,6 +340,19 @@ func PossibleValuesForEntityType() []string { } } +func (s *EntityType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityType(input string) (*EntityType, error) { vals := map[string]EntityType{ "account": EntityTypeAccount, @@ -317,6 +399,19 @@ func PossibleValuesForGetInsightsError() []string { } } +func (s *GetInsightsError) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseGetInsightsError(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseGetInsightsError(input string) (*GetInsightsError, error) { vals := map[string]GetInsightsError{ "insight": GetInsightsErrorInsight, @@ -368,6 +463,19 @@ func PossibleValuesForKillChainIntent() []string { } } +func (s *KillChainIntent) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKillChainIntent(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseKillChainIntent(input string) (*KillChainIntent, error) { vals := map[string]KillChainIntent{ "collection": KillChainIntentCollection, @@ -412,6 +520,19 @@ func PossibleValuesForOutputType() []string { } } +func (s *OutputType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOutputType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseOutputType(input string) (*OutputType, error) { vals := map[string]OutputType{ "date": OutputTypeDate, diff --git a/resource-manager/securityinsights/2022-10-01-preview/entities/method_expand.go b/resource-manager/securityinsights/2022-10-01-preview/entities/method_expand.go new file mode 100644 index 00000000000..4a41d4bd23a --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/entities/method_expand.go @@ -0,0 +1,56 @@ +package entities + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExpandOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EntityExpandResponse +} + +// Expand ... +func (c EntitiesClient) Expand(ctx context.Context, id EntityId, input EntityExpandParameters) (result ExpandOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/expand", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/entities/method_expand_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/entities/method_expand_autorest.go deleted file mode 100644 index 3b993d594dc..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/entities/method_expand_autorest.go +++ /dev/null @@ -1,70 +0,0 @@ -package entities - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ExpandOperationResponse struct { - HttpResponse *http.Response - Model *EntityExpandResponse -} - -// Expand ... -func (c EntitiesClient) Expand(ctx context.Context, id EntityId, input EntityExpandParameters) (result ExpandOperationResponse, err error) { - req, err := c.preparerForExpand(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "Expand", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "Expand", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForExpand(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "Expand", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForExpand prepares the Expand request. -func (c EntitiesClient) preparerForExpand(ctx context.Context, id EntityId, input EntityExpandParameters) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/expand", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForExpand handles the response to the Expand request. The method always -// closes the http.Response Body. -func (c EntitiesClient) responderForExpand(resp *http.Response) (result ExpandOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/entities/method_get.go b/resource-manager/securityinsights/2022-10-01-preview/entities/method_get.go new file mode 100644 index 00000000000..e3ea4abfc78 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/entities/method_get.go @@ -0,0 +1,51 @@ +package entities + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Entity +} + +// Get ... +func (c EntitiesClient) Get(ctx context.Context, id EntityId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/entities/method_get_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/entities/method_get_autorest.go deleted file mode 100644 index d77e86bbcb4..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/entities/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package entities - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *Entity -} - -// Get ... -func (c EntitiesClient) Get(ctx context.Context, id EntityId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c EntitiesClient) preparerForGet(ctx context.Context, id EntityId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c EntitiesClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/entities/method_getinsights.go b/resource-manager/securityinsights/2022-10-01-preview/entities/method_getinsights.go new file mode 100644 index 00000000000..d1422bda1ec --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/entities/method_getinsights.go @@ -0,0 +1,56 @@ +package entities + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetInsightsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EntityGetInsightsResponse +} + +// GetInsights ... +func (c EntitiesClient) GetInsights(ctx context.Context, id EntityId, input EntityGetInsightsParameters) (result GetInsightsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/getInsights", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/entities/method_getinsights_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/entities/method_getinsights_autorest.go deleted file mode 100644 index c3ae3a1ab75..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/entities/method_getinsights_autorest.go +++ /dev/null @@ -1,70 +0,0 @@ -package entities - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetInsightsOperationResponse struct { - HttpResponse *http.Response - Model *EntityGetInsightsResponse -} - -// GetInsights ... -func (c EntitiesClient) GetInsights(ctx context.Context, id EntityId, input EntityGetInsightsParameters) (result GetInsightsOperationResponse, err error) { - req, err := c.preparerForGetInsights(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "GetInsights", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "GetInsights", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGetInsights(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "GetInsights", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGetInsights prepares the GetInsights request. -func (c EntitiesClient) preparerForGetInsights(ctx context.Context, id EntityId, input EntityGetInsightsParameters) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/getInsights", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGetInsights handles the response to the GetInsights request. The method always -// closes the http.Response Body. -func (c EntitiesClient) responderForGetInsights(resp *http.Response) (result GetInsightsOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/entities/method_gettimelinelist.go b/resource-manager/securityinsights/2022-10-01-preview/entities/method_gettimelinelist.go new file mode 100644 index 00000000000..46c6b6cba26 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/entities/method_gettimelinelist.go @@ -0,0 +1,56 @@ +package entities + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetTimelinelistOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EntityTimelineResponse +} + +// GetTimelinelist ... +func (c EntitiesClient) GetTimelinelist(ctx context.Context, id EntityId, input EntityTimelineParameters) (result GetTimelinelistOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/getTimeline", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/entities/method_gettimelinelist_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/entities/method_gettimelinelist_autorest.go deleted file mode 100644 index e04da4a2b55..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/entities/method_gettimelinelist_autorest.go +++ /dev/null @@ -1,70 +0,0 @@ -package entities - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetTimelinelistOperationResponse struct { - HttpResponse *http.Response - Model *EntityTimelineResponse -} - -// GetTimelinelist ... -func (c EntitiesClient) GetTimelinelist(ctx context.Context, id EntityId, input EntityTimelineParameters) (result GetTimelinelistOperationResponse, err error) { - req, err := c.preparerForGetTimelinelist(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "GetTimelinelist", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "GetTimelinelist", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGetTimelinelist(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "GetTimelinelist", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGetTimelinelist prepares the GetTimelinelist request. -func (c EntitiesClient) preparerForGetTimelinelist(ctx context.Context, id EntityId, input EntityTimelineParameters) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/getTimeline", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGetTimelinelist handles the response to the GetTimelinelist request. The method always -// closes the http.Response Body. -func (c EntitiesClient) responderForGetTimelinelist(resp *http.Response) (result GetTimelinelistOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/entities/method_list.go b/resource-manager/securityinsights/2022-10-01-preview/entities/method_list.go new file mode 100644 index 00000000000..7bd410bbfb5 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/entities/method_list.go @@ -0,0 +1,91 @@ +package entities + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Entity +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Entity +} + +// List ... +func (c EntitiesClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/entities", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Entity `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c EntitiesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, EntityOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c EntitiesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate EntityOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Entity, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/entities/method_list_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/entities/method_list_autorest.go deleted file mode 100644 index 198d6f95594..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/entities/method_list_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package entities - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]Entity - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []Entity -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c EntitiesClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c EntitiesClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/entities", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c EntitiesClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c EntitiesClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []Entity `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c EntitiesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, EntityOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c EntitiesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate EntityOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]Entity, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/entities/method_queries.go b/resource-manager/securityinsights/2022-10-01-preview/entities/method_queries.go new file mode 100644 index 00000000000..ec05d3bd90a --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/entities/method_queries.go @@ -0,0 +1,80 @@ +package entities + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QueriesOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *GetQueriesResponse +} + +type QueriesOperationOptions struct { + Kind *EntityItemQueryKind +} + +func DefaultQueriesOperationOptions() QueriesOperationOptions { + return QueriesOperationOptions{} +} + +func (o QueriesOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o QueriesOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o QueriesOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Kind != nil { + out.Append("kind", fmt.Sprintf("%v", *o.Kind)) + } + return &out +} + +// Queries ... +func (c EntitiesClient) Queries(ctx context.Context, id EntityId, options QueriesOperationOptions) (result QueriesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/queries", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/entities/method_queries_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/entities/method_queries_autorest.go deleted file mode 100644 index 44f69f71e09..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/entities/method_queries_autorest.go +++ /dev/null @@ -1,98 +0,0 @@ -package entities - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type QueriesOperationResponse struct { - HttpResponse *http.Response - Model *GetQueriesResponse -} - -type QueriesOperationOptions struct { - Kind *EntityItemQueryKind -} - -func DefaultQueriesOperationOptions() QueriesOperationOptions { - return QueriesOperationOptions{} -} - -func (o QueriesOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o QueriesOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Kind != nil { - out["kind"] = *o.Kind - } - - return out -} - -// Queries ... -func (c EntitiesClient) Queries(ctx context.Context, id EntityId, options QueriesOperationOptions) (result QueriesOperationResponse, err error) { - req, err := c.preparerForQueries(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "Queries", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "Queries", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForQueries(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entities.EntitiesClient", "Queries", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForQueries prepares the Queries request. -func (c EntitiesClient) preparerForQueries(ctx context.Context, id EntityId, options QueriesOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/queries", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForQueries handles the response to the Queries request. The method always -// closes the http.Response Body. -func (c EntitiesClient) responderForQueries(resp *http.Response) (result QueriesOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/entityqueries/client.go b/resource-manager/securityinsights/2022-10-01-preview/entityqueries/client.go index a85c205dbc4..4a7620bff39 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/entityqueries/client.go +++ b/resource-manager/securityinsights/2022-10-01-preview/entityqueries/client.go @@ -1,18 +1,26 @@ package entityqueries -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type EntityQueriesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewEntityQueriesClientWithBaseURI(endpoint string) EntityQueriesClient { - return EntityQueriesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewEntityQueriesClientWithBaseURI(sdkApi sdkEnv.Api) (*EntityQueriesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "entityqueries", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating EntityQueriesClient: %+v", err) } + + return &EntityQueriesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-10-01-preview/entityqueries/constants.go b/resource-manager/securityinsights/2022-10-01-preview/entityqueries/constants.go index f1f3bac7251..9693ed3f519 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/entityqueries/constants.go +++ b/resource-manager/securityinsights/2022-10-01-preview/entityqueries/constants.go @@ -1,6 +1,10 @@ package entityqueries -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -17,6 +21,19 @@ func PossibleValuesForCustomEntityQueryKind() []string { } } +func (s *CustomEntityQueryKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCustomEntityQueryKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseCustomEntityQueryKind(input string) (*CustomEntityQueryKind, error) { vals := map[string]CustomEntityQueryKind{ "activity": CustomEntityQueryKindActivity, @@ -46,6 +63,19 @@ func PossibleValuesForEntityQueryKind() []string { } } +func (s *EntityQueryKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityQueryKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityQueryKind(input string) (*EntityQueryKind, error) { vals := map[string]EntityQueryKind{ "activity": EntityQueryKindActivity, @@ -73,6 +103,19 @@ func PossibleValuesForEntityQueryTemplateKind() []string { } } +func (s *EntityQueryTemplateKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityQueryTemplateKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityQueryTemplateKind(input string) (*EntityQueryTemplateKind, error) { vals := map[string]EntityQueryTemplateKind{ "activity": EntityQueryTemplateKindActivity, @@ -140,6 +183,19 @@ func PossibleValuesForEntityType() []string { } } +func (s *EntityType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityType(input string) (*EntityType, error) { vals := map[string]EntityType{ "account": EntityTypeAccount, @@ -188,6 +244,19 @@ func PossibleValuesForKind() []string { } } +func (s *Kind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseKind(input string) (*Kind, error) { vals := map[string]Kind{ "activity": KindActivity, diff --git a/resource-manager/securityinsights/2022-10-01-preview/entityqueries/method_createorupdate.go b/resource-manager/securityinsights/2022-10-01-preview/entityqueries/method_createorupdate.go new file mode 100644 index 00000000000..b9ecc82c257 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/entityqueries/method_createorupdate.go @@ -0,0 +1,63 @@ +package entityqueries + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EntityQuery +} + +// CreateOrUpdate ... +func (c EntityQueriesClient) CreateOrUpdate(ctx context.Context, id EntityQueryId, input CustomEntityQuery) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalEntityQueryImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/entityqueries/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/entityqueries/method_createorupdate_autorest.go deleted file mode 100644 index eeec49d03b4..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/entityqueries/method_createorupdate_autorest.go +++ /dev/null @@ -1,78 +0,0 @@ -package entityqueries - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *EntityQuery -} - -// CreateOrUpdate ... -func (c EntityQueriesClient) CreateOrUpdate(ctx context.Context, id EntityQueryId, input CustomEntityQuery) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c EntityQueriesClient) preparerForCreateOrUpdate(ctx context.Context, id EntityQueryId, input CustomEntityQuery) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c EntityQueriesClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalEntityQueryImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/entityqueries/method_delete.go b/resource-manager/securityinsights/2022-10-01-preview/entityqueries/method_delete.go new file mode 100644 index 00000000000..b413ad04691 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/entityqueries/method_delete.go @@ -0,0 +1,47 @@ +package entityqueries + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c EntityQueriesClient) Delete(ctx context.Context, id EntityQueryId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/entityqueries/method_delete_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/entityqueries/method_delete_autorest.go deleted file mode 100644 index 3ad079474b1..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/entityqueries/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package entityqueries - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c EntityQueriesClient) Delete(ctx context.Context, id EntityQueryId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c EntityQueriesClient) preparerForDelete(ctx context.Context, id EntityQueryId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c EntityQueriesClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/entityqueries/method_entityquerytemplatesget.go b/resource-manager/securityinsights/2022-10-01-preview/entityqueries/method_entityquerytemplatesget.go new file mode 100644 index 00000000000..2e55614c8f0 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/entityqueries/method_entityquerytemplatesget.go @@ -0,0 +1,58 @@ +package entityqueries + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EntityQueryTemplatesGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EntityQueryTemplate +} + +// EntityQueryTemplatesGet ... +func (c EntityQueriesClient) EntityQueryTemplatesGet(ctx context.Context, id EntityQueryTemplateId) (result EntityQueryTemplatesGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalEntityQueryTemplateImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/entityqueries/method_entityquerytemplatesget_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/entityqueries/method_entityquerytemplatesget_autorest.go deleted file mode 100644 index e5058178ba0..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/entityqueries/method_entityquerytemplatesget_autorest.go +++ /dev/null @@ -1,77 +0,0 @@ -package entityqueries - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type EntityQueryTemplatesGetOperationResponse struct { - HttpResponse *http.Response - Model *EntityQueryTemplate -} - -// EntityQueryTemplatesGet ... -func (c EntityQueriesClient) EntityQueryTemplatesGet(ctx context.Context, id EntityQueryTemplateId) (result EntityQueryTemplatesGetOperationResponse, err error) { - req, err := c.preparerForEntityQueryTemplatesGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "EntityQueryTemplatesGet", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "EntityQueryTemplatesGet", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForEntityQueryTemplatesGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "EntityQueryTemplatesGet", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForEntityQueryTemplatesGet prepares the EntityQueryTemplatesGet request. -func (c EntityQueriesClient) preparerForEntityQueryTemplatesGet(ctx context.Context, id EntityQueryTemplateId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForEntityQueryTemplatesGet handles the response to the EntityQueryTemplatesGet request. The method always -// closes the http.Response Body. -func (c EntityQueriesClient) responderForEntityQueryTemplatesGet(resp *http.Response) (result EntityQueryTemplatesGetOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalEntityQueryTemplateImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/entityqueries/method_entityquerytemplateslist.go b/resource-manager/securityinsights/2022-10-01-preview/entityqueries/method_entityquerytemplateslist.go new file mode 100644 index 00000000000..80a1a6ce617 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/entityqueries/method_entityquerytemplateslist.go @@ -0,0 +1,131 @@ +package entityqueries + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EntityQueryTemplatesListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]EntityQueryTemplate +} + +type EntityQueryTemplatesListCompleteResult struct { + LatestHttpResponse *http.Response + Items []EntityQueryTemplate +} + +type EntityQueryTemplatesListOperationOptions struct { + Kind *Kind +} + +func DefaultEntityQueryTemplatesListOperationOptions() EntityQueryTemplatesListOperationOptions { + return EntityQueryTemplatesListOperationOptions{} +} + +func (o EntityQueryTemplatesListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o EntityQueryTemplatesListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o EntityQueryTemplatesListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Kind != nil { + out.Append("kind", fmt.Sprintf("%v", *o.Kind)) + } + return &out +} + +// EntityQueryTemplatesList ... +func (c EntityQueriesClient) EntityQueryTemplatesList(ctx context.Context, id WorkspaceId, options EntityQueryTemplatesListOperationOptions) (result EntityQueryTemplatesListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/entityQueryTemplates", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]EntityQueryTemplate, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalEntityQueryTemplateImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for EntityQueryTemplate (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// EntityQueryTemplatesListComplete retrieves all the results into a single object +func (c EntityQueriesClient) EntityQueryTemplatesListComplete(ctx context.Context, id WorkspaceId, options EntityQueryTemplatesListOperationOptions) (EntityQueryTemplatesListCompleteResult, error) { + return c.EntityQueryTemplatesListCompleteMatchingPredicate(ctx, id, options, EntityQueryTemplateOperationPredicate{}) +} + +// EntityQueryTemplatesListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c EntityQueriesClient) EntityQueryTemplatesListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options EntityQueryTemplatesListOperationOptions, predicate EntityQueryTemplateOperationPredicate) (result EntityQueryTemplatesListCompleteResult, err error) { + items := make([]EntityQueryTemplate, 0) + + resp, err := c.EntityQueryTemplatesList(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = EntityQueryTemplatesListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/entityqueries/method_entityquerytemplateslist_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/entityqueries/method_entityquerytemplateslist_autorest.go deleted file mode 100644 index 251984e8d83..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/entityqueries/method_entityquerytemplateslist_autorest.go +++ /dev/null @@ -1,225 +0,0 @@ -package entityqueries - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type EntityQueryTemplatesListOperationResponse struct { - HttpResponse *http.Response - Model *[]EntityQueryTemplate - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (EntityQueryTemplatesListOperationResponse, error) -} - -type EntityQueryTemplatesListCompleteResult struct { - Items []EntityQueryTemplate -} - -func (r EntityQueryTemplatesListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r EntityQueryTemplatesListOperationResponse) LoadMore(ctx context.Context) (resp EntityQueryTemplatesListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type EntityQueryTemplatesListOperationOptions struct { - Kind *Kind -} - -func DefaultEntityQueryTemplatesListOperationOptions() EntityQueryTemplatesListOperationOptions { - return EntityQueryTemplatesListOperationOptions{} -} - -func (o EntityQueryTemplatesListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o EntityQueryTemplatesListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Kind != nil { - out["kind"] = *o.Kind - } - - return out -} - -// EntityQueryTemplatesList ... -func (c EntityQueriesClient) EntityQueryTemplatesList(ctx context.Context, id WorkspaceId, options EntityQueryTemplatesListOperationOptions) (resp EntityQueryTemplatesListOperationResponse, err error) { - req, err := c.preparerForEntityQueryTemplatesList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "EntityQueryTemplatesList", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "EntityQueryTemplatesList", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForEntityQueryTemplatesList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "EntityQueryTemplatesList", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForEntityQueryTemplatesList prepares the EntityQueryTemplatesList request. -func (c EntityQueriesClient) preparerForEntityQueryTemplatesList(ctx context.Context, id WorkspaceId, options EntityQueryTemplatesListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/entityQueryTemplates", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForEntityQueryTemplatesListWithNextLink prepares the EntityQueryTemplatesList request with the given nextLink token. -func (c EntityQueriesClient) preparerForEntityQueryTemplatesListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForEntityQueryTemplatesList handles the response to the EntityQueryTemplatesList request. The method always -// closes the http.Response Body. -func (c EntityQueriesClient) responderForEntityQueryTemplatesList(resp *http.Response) (result EntityQueryTemplatesListOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]EntityQueryTemplate, 0) - for i, v := range respObj.Values { - val, err := unmarshalEntityQueryTemplateImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for EntityQueryTemplate (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result EntityQueryTemplatesListOperationResponse, err error) { - req, err := c.preparerForEntityQueryTemplatesListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "EntityQueryTemplatesList", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "EntityQueryTemplatesList", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForEntityQueryTemplatesList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "EntityQueryTemplatesList", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// EntityQueryTemplatesListComplete retrieves all of the results into a single object -func (c EntityQueriesClient) EntityQueryTemplatesListComplete(ctx context.Context, id WorkspaceId, options EntityQueryTemplatesListOperationOptions) (EntityQueryTemplatesListCompleteResult, error) { - return c.EntityQueryTemplatesListCompleteMatchingPredicate(ctx, id, options, EntityQueryTemplateOperationPredicate{}) -} - -// EntityQueryTemplatesListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c EntityQueriesClient) EntityQueryTemplatesListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options EntityQueryTemplatesListOperationOptions, predicate EntityQueryTemplateOperationPredicate) (resp EntityQueryTemplatesListCompleteResult, err error) { - items := make([]EntityQueryTemplate, 0) - - page, err := c.EntityQueryTemplatesList(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := EntityQueryTemplatesListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/entityqueries/method_get.go b/resource-manager/securityinsights/2022-10-01-preview/entityqueries/method_get.go new file mode 100644 index 00000000000..4a7022fa713 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/entityqueries/method_get.go @@ -0,0 +1,58 @@ +package entityqueries + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EntityQuery +} + +// Get ... +func (c EntityQueriesClient) Get(ctx context.Context, id EntityQueryId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalEntityQueryImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/entityqueries/method_get_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/entityqueries/method_get_autorest.go deleted file mode 100644 index ad9e794be03..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/entityqueries/method_get_autorest.go +++ /dev/null @@ -1,77 +0,0 @@ -package entityqueries - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *EntityQuery -} - -// Get ... -func (c EntityQueriesClient) Get(ctx context.Context, id EntityQueryId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c EntityQueriesClient) preparerForGet(ctx context.Context, id EntityQueryId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c EntityQueriesClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalEntityQueryImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/entityqueries/method_list.go b/resource-manager/securityinsights/2022-10-01-preview/entityqueries/method_list.go new file mode 100644 index 00000000000..5cf5f6c7631 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/entityqueries/method_list.go @@ -0,0 +1,131 @@ +package entityqueries + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]EntityQuery +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []EntityQuery +} + +type ListOperationOptions struct { + Kind *Kind +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Kind != nil { + out.Append("kind", fmt.Sprintf("%v", *o.Kind)) + } + return &out +} + +// List ... +func (c EntityQueriesClient) List(ctx context.Context, id WorkspaceId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/entityQueries", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]EntityQuery, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalEntityQueryImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for EntityQuery (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// ListComplete retrieves all the results into a single object +func (c EntityQueriesClient) ListComplete(ctx context.Context, id WorkspaceId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, EntityQueryOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c EntityQueriesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ListOperationOptions, predicate EntityQueryOperationPredicate) (result ListCompleteResult, err error) { + items := make([]EntityQuery, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/entityqueries/method_list_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/entityqueries/method_list_autorest.go deleted file mode 100644 index be9cadd1c8f..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/entityqueries/method_list_autorest.go +++ /dev/null @@ -1,225 +0,0 @@ -package entityqueries - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]EntityQuery - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []EntityQuery -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ListOperationOptions struct { - Kind *Kind -} - -func DefaultListOperationOptions() ListOperationOptions { - return ListOperationOptions{} -} - -func (o ListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Kind != nil { - out["kind"] = *o.Kind - } - - return out -} - -// List ... -func (c EntityQueriesClient) List(ctx context.Context, id WorkspaceId, options ListOperationOptions) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c EntityQueriesClient) preparerForList(ctx context.Context, id WorkspaceId, options ListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/entityQueries", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c EntityQueriesClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c EntityQueriesClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]EntityQuery, 0) - for i, v := range respObj.Values { - val, err := unmarshalEntityQueryImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for EntityQuery (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entityqueries.EntityQueriesClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c EntityQueriesClient) ListComplete(ctx context.Context, id WorkspaceId, options ListOperationOptions) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, options, EntityQueryOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c EntityQueriesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ListOperationOptions, predicate EntityQueryOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]EntityQuery, 0) - - page, err := c.List(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/entityrelations/client.go b/resource-manager/securityinsights/2022-10-01-preview/entityrelations/client.go index ac243fa003e..85b6978e574 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/entityrelations/client.go +++ b/resource-manager/securityinsights/2022-10-01-preview/entityrelations/client.go @@ -1,18 +1,26 @@ package entityrelations -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type EntityRelationsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewEntityRelationsClientWithBaseURI(endpoint string) EntityRelationsClient { - return EntityRelationsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewEntityRelationsClientWithBaseURI(sdkApi sdkEnv.Api) (*EntityRelationsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "entityrelations", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating EntityRelationsClient: %+v", err) } + + return &EntityRelationsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-10-01-preview/entityrelations/method_entitiesrelationslist.go b/resource-manager/securityinsights/2022-10-01-preview/entityrelations/method_entitiesrelationslist.go new file mode 100644 index 00000000000..ffe62e84ee3 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/entityrelations/method_entitiesrelationslist.go @@ -0,0 +1,127 @@ +package entityrelations + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EntitiesRelationsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Relation +} + +type EntitiesRelationsListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Relation +} + +type EntitiesRelationsListOperationOptions struct { + Filter *string + Orderby *string + Top *int64 +} + +func DefaultEntitiesRelationsListOperationOptions() EntitiesRelationsListOperationOptions { + return EntitiesRelationsListOperationOptions{} +} + +func (o EntitiesRelationsListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o EntitiesRelationsListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o EntitiesRelationsListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// EntitiesRelationsList ... +func (c EntityRelationsClient) EntitiesRelationsList(ctx context.Context, id EntityId, options EntitiesRelationsListOperationOptions) (result EntitiesRelationsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/relations", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Relation `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// EntitiesRelationsListComplete retrieves all the results into a single object +func (c EntityRelationsClient) EntitiesRelationsListComplete(ctx context.Context, id EntityId, options EntitiesRelationsListOperationOptions) (EntitiesRelationsListCompleteResult, error) { + return c.EntitiesRelationsListCompleteMatchingPredicate(ctx, id, options, RelationOperationPredicate{}) +} + +// EntitiesRelationsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c EntityRelationsClient) EntitiesRelationsListCompleteMatchingPredicate(ctx context.Context, id EntityId, options EntitiesRelationsListOperationOptions, predicate RelationOperationPredicate) (result EntitiesRelationsListCompleteResult, err error) { + items := make([]Relation, 0) + + resp, err := c.EntitiesRelationsList(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = EntitiesRelationsListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/entityrelations/method_entitiesrelationslist_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/entityrelations/method_entitiesrelationslist_autorest.go deleted file mode 100644 index 7cb48eb2ac6..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/entityrelations/method_entitiesrelationslist_autorest.go +++ /dev/null @@ -1,225 +0,0 @@ -package entityrelations - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type EntitiesRelationsListOperationResponse struct { - HttpResponse *http.Response - Model *[]Relation - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (EntitiesRelationsListOperationResponse, error) -} - -type EntitiesRelationsListCompleteResult struct { - Items []Relation -} - -func (r EntitiesRelationsListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r EntitiesRelationsListOperationResponse) LoadMore(ctx context.Context) (resp EntitiesRelationsListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type EntitiesRelationsListOperationOptions struct { - Filter *string - Orderby *string - Top *int64 -} - -func DefaultEntitiesRelationsListOperationOptions() EntitiesRelationsListOperationOptions { - return EntitiesRelationsListOperationOptions{} -} - -func (o EntitiesRelationsListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o EntitiesRelationsListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Filter != nil { - out["$filter"] = *o.Filter - } - - if o.Orderby != nil { - out["$orderby"] = *o.Orderby - } - - if o.Top != nil { - out["$top"] = *o.Top - } - - return out -} - -// EntitiesRelationsList ... -func (c EntityRelationsClient) EntitiesRelationsList(ctx context.Context, id EntityId, options EntitiesRelationsListOperationOptions) (resp EntitiesRelationsListOperationResponse, err error) { - req, err := c.preparerForEntitiesRelationsList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "entityrelations.EntityRelationsClient", "EntitiesRelationsList", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entityrelations.EntityRelationsClient", "EntitiesRelationsList", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForEntitiesRelationsList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entityrelations.EntityRelationsClient", "EntitiesRelationsList", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForEntitiesRelationsList prepares the EntitiesRelationsList request. -func (c EntityRelationsClient) preparerForEntitiesRelationsList(ctx context.Context, id EntityId, options EntitiesRelationsListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/relations", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForEntitiesRelationsListWithNextLink prepares the EntitiesRelationsList request with the given nextLink token. -func (c EntityRelationsClient) preparerForEntitiesRelationsListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForEntitiesRelationsList handles the response to the EntitiesRelationsList request. The method always -// closes the http.Response Body. -func (c EntityRelationsClient) responderForEntitiesRelationsList(resp *http.Response) (result EntitiesRelationsListOperationResponse, err error) { - type page struct { - Values []Relation `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result EntitiesRelationsListOperationResponse, err error) { - req, err := c.preparerForEntitiesRelationsListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "entityrelations.EntityRelationsClient", "EntitiesRelationsList", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entityrelations.EntityRelationsClient", "EntitiesRelationsList", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForEntitiesRelationsList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entityrelations.EntityRelationsClient", "EntitiesRelationsList", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// EntitiesRelationsListComplete retrieves all of the results into a single object -func (c EntityRelationsClient) EntitiesRelationsListComplete(ctx context.Context, id EntityId, options EntitiesRelationsListOperationOptions) (EntitiesRelationsListCompleteResult, error) { - return c.EntitiesRelationsListCompleteMatchingPredicate(ctx, id, options, RelationOperationPredicate{}) -} - -// EntitiesRelationsListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c EntityRelationsClient) EntitiesRelationsListCompleteMatchingPredicate(ctx context.Context, id EntityId, options EntitiesRelationsListOperationOptions, predicate RelationOperationPredicate) (resp EntitiesRelationsListCompleteResult, err error) { - items := make([]Relation, 0) - - page, err := c.EntitiesRelationsList(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := EntitiesRelationsListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/entityrelations/method_getrelation.go b/resource-manager/securityinsights/2022-10-01-preview/entityrelations/method_getrelation.go new file mode 100644 index 00000000000..e81337d733b --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/entityrelations/method_getrelation.go @@ -0,0 +1,51 @@ +package entityrelations + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetRelationOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Relation +} + +// GetRelation ... +func (c EntityRelationsClient) GetRelation(ctx context.Context, id RelationId) (result GetRelationOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/entityrelations/method_getrelation_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/entityrelations/method_getrelation_autorest.go deleted file mode 100644 index d400c162968..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/entityrelations/method_getrelation_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package entityrelations - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetRelationOperationResponse struct { - HttpResponse *http.Response - Model *Relation -} - -// GetRelation ... -func (c EntityRelationsClient) GetRelation(ctx context.Context, id RelationId) (result GetRelationOperationResponse, err error) { - req, err := c.preparerForGetRelation(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "entityrelations.EntityRelationsClient", "GetRelation", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "entityrelations.EntityRelationsClient", "GetRelation", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGetRelation(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "entityrelations.EntityRelationsClient", "GetRelation", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGetRelation prepares the GetRelation request. -func (c EntityRelationsClient) preparerForGetRelation(ctx context.Context, id RelationId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGetRelation handles the response to the GetRelation request. The method always -// closes the http.Response Body. -func (c EntityRelationsClient) responderForGetRelation(resp *http.Response) (result GetRelationOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/entitytypes/client.go b/resource-manager/securityinsights/2022-10-01-preview/entitytypes/client.go index 60583ea834f..bcdd09e4029 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/entitytypes/client.go +++ b/resource-manager/securityinsights/2022-10-01-preview/entitytypes/client.go @@ -1,18 +1,26 @@ package entitytypes -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type EntityTypesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewEntityTypesClientWithBaseURI(endpoint string) EntityTypesClient { - return EntityTypesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewEntityTypesClientWithBaseURI(sdkApi sdkEnv.Api) (*EntityTypesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "entitytypes", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating EntityTypesClient: %+v", err) } + + return &EntityTypesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-10-01-preview/entitytypes/constants.go b/resource-manager/securityinsights/2022-10-01-preview/entitytypes/constants.go index 92df052e0f7..83bedfbe6a8 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/entitytypes/constants.go +++ b/resource-manager/securityinsights/2022-10-01-preview/entitytypes/constants.go @@ -1,6 +1,10 @@ package entitytypes -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -23,6 +27,19 @@ func PossibleValuesForAlertSeverity() []string { } } +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertSeverity(input string) (*AlertSeverity, error) { vals := map[string]AlertSeverity{ "high": AlertSeverityHigh, @@ -59,6 +76,19 @@ func PossibleValuesForAlertStatus() []string { } } +func (s *AlertStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertStatus(input string) (*AlertStatus, error) { vals := map[string]AlertStatus{ "dismissed": AlertStatusDismissed, @@ -94,6 +124,19 @@ func PossibleValuesForAntispamMailDirection() []string { } } +func (s *AntispamMailDirection) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAntispamMailDirection(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAntispamMailDirection(input string) (*AntispamMailDirection, error) { vals := map[string]AntispamMailDirection{ "inbound": AntispamMailDirectionInbound, @@ -154,6 +197,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -199,6 +255,19 @@ func PossibleValuesForConfidenceLevel() []string { } } +func (s *ConfidenceLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceLevel(input string) (*ConfidenceLevel, error) { vals := map[string]ConfidenceLevel{ "high": ConfidenceLevelHigh, @@ -232,6 +301,19 @@ func PossibleValuesForConfidenceScoreStatus() []string { } } +func (s *ConfidenceScoreStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceScoreStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceScoreStatus(input string) (*ConfidenceScoreStatus, error) { vals := map[string]ConfidenceScoreStatus{ "final": ConfidenceScoreStatusFinal, @@ -266,6 +348,19 @@ func PossibleValuesForCreatedByType() []string { } } +func (s *CreatedByType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCreatedByType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseCreatedByType(input string) (*CreatedByType, error) { vals := map[string]CreatedByType{ "application": CreatedByTypeApplication, @@ -302,6 +397,19 @@ func PossibleValuesForDeliveryAction() []string { } } +func (s *DeliveryAction) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeliveryAction(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDeliveryAction(input string) (*DeliveryAction, error) { vals := map[string]DeliveryAction{ "blocked": DeliveryActionBlocked, @@ -347,6 +455,19 @@ func PossibleValuesForDeliveryLocation() []string { } } +func (s *DeliveryLocation) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeliveryLocation(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDeliveryLocation(input string) (*DeliveryLocation, error) { vals := map[string]DeliveryLocation{ "deletedfolder": DeliveryLocationDeletedFolder, @@ -386,6 +507,19 @@ func PossibleValuesForDeviceImportance() []string { } } +func (s *DeviceImportance) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeviceImportance(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDeviceImportance(input string) (*DeviceImportance, error) { vals := map[string]DeviceImportance{ "high": DeviceImportanceHigh, @@ -418,6 +552,19 @@ func PossibleValuesForElevationToken() []string { } } +func (s *ElevationToken) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseElevationToken(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseElevationToken(input string) (*ElevationToken, error) { vals := map[string]ElevationToken{ "default": ElevationTokenDefault, @@ -487,6 +634,19 @@ func PossibleValuesForEntityKind() []string { } } +func (s *EntityKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityKind(input string) (*EntityKind, error) { vals := map[string]EntityKind{ "account": EntityKindAccount, @@ -541,6 +701,19 @@ func PossibleValuesForFileHashAlgorithm() []string { } } +func (s *FileHashAlgorithm) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseFileHashAlgorithm(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseFileHashAlgorithm(input string) (*FileHashAlgorithm, error) { vals := map[string]FileHashAlgorithm{ "md5": FileHashAlgorithmMDFive, @@ -576,6 +749,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, @@ -630,6 +816,19 @@ func PossibleValuesForKillChainIntent() []string { } } +func (s *KillChainIntent) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKillChainIntent(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseKillChainIntent(input string) (*KillChainIntent, error) { vals := map[string]KillChainIntent{ "collection": KillChainIntentCollection, @@ -676,6 +875,19 @@ func PossibleValuesForOSFamily() []string { } } +func (s *OSFamily) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOSFamily(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseOSFamily(input string) (*OSFamily, error) { vals := map[string]OSFamily{ "android": OSFamilyAndroid, @@ -723,6 +935,19 @@ func PossibleValuesForRegistryHive() []string { } } +func (s *RegistryHive) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRegistryHive(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseRegistryHive(input string) (*RegistryHive, error) { vals := map[string]RegistryHive{ "hkey_a": RegistryHiveHKEYA, @@ -771,6 +996,19 @@ func PossibleValuesForRegistryValueKind() []string { } } +func (s *RegistryValueKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRegistryValueKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseRegistryValueKind(input string) (*RegistryValueKind, error) { vals := map[string]RegistryValueKind{ "binary": RegistryValueKindBinary, diff --git a/resource-manager/securityinsights/2022-10-01-preview/fileimports/client.go b/resource-manager/securityinsights/2022-10-01-preview/fileimports/client.go index 42192ed9644..84e12ee17a6 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/fileimports/client.go +++ b/resource-manager/securityinsights/2022-10-01-preview/fileimports/client.go @@ -1,18 +1,26 @@ package fileimports -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type FileImportsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewFileImportsClientWithBaseURI(endpoint string) FileImportsClient { - return FileImportsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewFileImportsClientWithBaseURI(sdkApi sdkEnv.Api) (*FileImportsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "fileimports", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating FileImportsClient: %+v", err) } + + return &FileImportsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-10-01-preview/fileimports/constants.go b/resource-manager/securityinsights/2022-10-01-preview/fileimports/constants.go index 78002b5d0a9..b902f49dca0 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/fileimports/constants.go +++ b/resource-manager/securityinsights/2022-10-01-preview/fileimports/constants.go @@ -1,6 +1,10 @@ package fileimports -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -21,6 +25,19 @@ func PossibleValuesForDeleteStatus() []string { } } +func (s *DeleteStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeleteStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDeleteStatus(input string) (*DeleteStatus, error) { vals := map[string]DeleteStatus{ "deleted": DeleteStatusDeleted, @@ -52,6 +69,19 @@ func PossibleValuesForFileFormat() []string { } } +func (s *FileFormat) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseFileFormat(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseFileFormat(input string) (*FileFormat, error) { vals := map[string]FileFormat{ "csv": FileFormatCSV, @@ -83,6 +113,19 @@ func PossibleValuesForFileImportContentType() []string { } } +func (s *FileImportContentType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseFileImportContentType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseFileImportContentType(input string) (*FileImportContentType, error) { vals := map[string]FileImportContentType{ "basicindicator": FileImportContentTypeBasicIndicator, @@ -122,6 +165,19 @@ func PossibleValuesForFileImportState() []string { } } +func (s *FileImportState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseFileImportState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseFileImportState(input string) (*FileImportState, error) { vals := map[string]FileImportState{ "fatalerror": FileImportStateFatalError, @@ -157,6 +213,19 @@ func PossibleValuesForIngestionMode() []string { } } +func (s *IngestionMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIngestionMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIngestionMode(input string) (*IngestionMode, error) { vals := map[string]IngestionMode{ "ingestanyvalidrecords": IngestionModeIngestAnyValidRecords, diff --git a/resource-manager/securityinsights/2022-10-01-preview/fileimports/method_create.go b/resource-manager/securityinsights/2022-10-01-preview/fileimports/method_create.go new file mode 100644 index 00000000000..b846cd9a31f --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/fileimports/method_create.go @@ -0,0 +1,55 @@ +package fileimports + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *FileImport +} + +// Create ... +func (c FileImportsClient) Create(ctx context.Context, id FileImportId, input FileImport) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/fileimports/method_create_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/fileimports/method_create_autorest.go deleted file mode 100644 index bf1882dca39..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/fileimports/method_create_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package fileimports - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOperationResponse struct { - HttpResponse *http.Response - Model *FileImport -} - -// Create ... -func (c FileImportsClient) Create(ctx context.Context, id FileImportId, input FileImport) (result CreateOperationResponse, err error) { - req, err := c.preparerForCreate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "fileimports.FileImportsClient", "Create", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "fileimports.FileImportsClient", "Create", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "fileimports.FileImportsClient", "Create", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreate prepares the Create request. -func (c FileImportsClient) preparerForCreate(ctx context.Context, id FileImportId, input FileImport) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreate handles the response to the Create request. The method always -// closes the http.Response Body. -func (c FileImportsClient) responderForCreate(resp *http.Response) (result CreateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/fileimports/method_delete.go b/resource-manager/securityinsights/2022-10-01-preview/fileimports/method_delete.go new file mode 100644 index 00000000000..66fc327d959 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/fileimports/method_delete.go @@ -0,0 +1,71 @@ +package fileimports + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *FileImport +} + +// Delete ... +func (c FileImportsClient) Delete(ctx context.Context, id FileImportId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c FileImportsClient) DeleteThenPoll(ctx context.Context, id FileImportId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/fileimports/method_delete_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/fileimports/method_delete_autorest.go deleted file mode 100644 index 4e5e808de01..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/fileimports/method_delete_autorest.go +++ /dev/null @@ -1,79 +0,0 @@ -package fileimports - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/hashicorp/go-azure-helpers/polling" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - Poller polling.LongRunningPoller - HttpResponse *http.Response - Model *FileImport -} - -// Delete ... -func (c FileImportsClient) Delete(ctx context.Context, id FileImportId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "fileimports.FileImportsClient", "Delete", nil, "Failure preparing request") - return - } - - result, err = c.senderForDelete(ctx, req) - if err != nil { - err = autorest.NewErrorWithError(err, "fileimports.FileImportsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - return -} - -// DeleteThenPoll performs Delete then polls until it's completed -func (c FileImportsClient) DeleteThenPoll(ctx context.Context, id FileImportId) error { - result, err := c.Delete(ctx, id) - if err != nil { - return fmt.Errorf("performing Delete: %+v", err) - } - - if err := result.Poller.PollUntilDone(); err != nil { - return fmt.Errorf("polling after Delete: %+v", err) - } - - return nil -} - -// preparerForDelete prepares the Delete request. -func (c FileImportsClient) preparerForDelete(ctx context.Context, id FileImportId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// senderForDelete sends the Delete request. The method will close the -// http.Response Body if it receives an error. -func (c FileImportsClient) senderForDelete(ctx context.Context, req *http.Request) (future DeleteOperationResponse, err error) { - var resp *http.Response - resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - return - } - - future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/fileimports/method_get.go b/resource-manager/securityinsights/2022-10-01-preview/fileimports/method_get.go new file mode 100644 index 00000000000..a6990711bb3 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/fileimports/method_get.go @@ -0,0 +1,51 @@ +package fileimports + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *FileImport +} + +// Get ... +func (c FileImportsClient) Get(ctx context.Context, id FileImportId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/fileimports/method_get_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/fileimports/method_get_autorest.go deleted file mode 100644 index cbd9ed02bdb..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/fileimports/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package fileimports - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *FileImport -} - -// Get ... -func (c FileImportsClient) Get(ctx context.Context, id FileImportId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "fileimports.FileImportsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "fileimports.FileImportsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "fileimports.FileImportsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c FileImportsClient) preparerForGet(ctx context.Context, id FileImportId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c FileImportsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/fileimports/method_list.go b/resource-manager/securityinsights/2022-10-01-preview/fileimports/method_list.go new file mode 100644 index 00000000000..975ae67b660 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/fileimports/method_list.go @@ -0,0 +1,127 @@ +package fileimports + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]FileImport +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []FileImport +} + +type ListOperationOptions struct { + Filter *string + Orderby *string + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c FileImportsClient) List(ctx context.Context, id WorkspaceId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/fileImports", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]FileImport `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c FileImportsClient) ListComplete(ctx context.Context, id WorkspaceId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, FileImportOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c FileImportsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ListOperationOptions, predicate FileImportOperationPredicate) (result ListCompleteResult, err error) { + items := make([]FileImport, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/fileimports/method_list_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/fileimports/method_list_autorest.go deleted file mode 100644 index 448b291d1b7..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/fileimports/method_list_autorest.go +++ /dev/null @@ -1,225 +0,0 @@ -package fileimports - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]FileImport - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []FileImport -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ListOperationOptions struct { - Filter *string - Orderby *string - Top *int64 -} - -func DefaultListOperationOptions() ListOperationOptions { - return ListOperationOptions{} -} - -func (o ListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Filter != nil { - out["$filter"] = *o.Filter - } - - if o.Orderby != nil { - out["$orderby"] = *o.Orderby - } - - if o.Top != nil { - out["$top"] = *o.Top - } - - return out -} - -// List ... -func (c FileImportsClient) List(ctx context.Context, id WorkspaceId, options ListOperationOptions) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "fileimports.FileImportsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "fileimports.FileImportsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "fileimports.FileImportsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c FileImportsClient) preparerForList(ctx context.Context, id WorkspaceId, options ListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/fileImports", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c FileImportsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c FileImportsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []FileImport `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "fileimports.FileImportsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "fileimports.FileImportsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "fileimports.FileImportsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c FileImportsClient) ListComplete(ctx context.Context, id WorkspaceId, options ListOperationOptions) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, options, FileImportOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c FileImportsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ListOperationOptions, predicate FileImportOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]FileImport, 0) - - page, err := c.List(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/incidentalerts/client.go b/resource-manager/securityinsights/2022-10-01-preview/incidentalerts/client.go index ae19637d473..53dc2b4cd4e 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/incidentalerts/client.go +++ b/resource-manager/securityinsights/2022-10-01-preview/incidentalerts/client.go @@ -1,18 +1,26 @@ package incidentalerts -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type IncidentAlertsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewIncidentAlertsClientWithBaseURI(endpoint string) IncidentAlertsClient { - return IncidentAlertsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewIncidentAlertsClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentAlertsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidentalerts", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentAlertsClient: %+v", err) } + + return &IncidentAlertsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-10-01-preview/incidentalerts/constants.go b/resource-manager/securityinsights/2022-10-01-preview/incidentalerts/constants.go index 9f5d1a09992..5d286095967 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/incidentalerts/constants.go +++ b/resource-manager/securityinsights/2022-10-01-preview/incidentalerts/constants.go @@ -1,6 +1,10 @@ package incidentalerts -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -23,6 +27,19 @@ func PossibleValuesForAlertSeverity() []string { } } +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertSeverity(input string) (*AlertSeverity, error) { vals := map[string]AlertSeverity{ "high": AlertSeverityHigh, @@ -59,6 +76,19 @@ func PossibleValuesForAlertStatus() []string { } } +func (s *AlertStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertStatus(input string) (*AlertStatus, error) { vals := map[string]AlertStatus{ "dismissed": AlertStatusDismissed, @@ -120,6 +150,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -165,6 +208,19 @@ func PossibleValuesForConfidenceLevel() []string { } } +func (s *ConfidenceLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceLevel(input string) (*ConfidenceLevel, error) { vals := map[string]ConfidenceLevel{ "high": ConfidenceLevelHigh, @@ -198,6 +254,19 @@ func PossibleValuesForConfidenceScoreStatus() []string { } } +func (s *ConfidenceScoreStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceScoreStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceScoreStatus(input string) (*ConfidenceScoreStatus, error) { vals := map[string]ConfidenceScoreStatus{ "final": ConfidenceScoreStatusFinal, @@ -268,6 +337,19 @@ func PossibleValuesForEntityKind() []string { } } +func (s *EntityKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityKind(input string) (*EntityKind, error) { vals := map[string]EntityKind{ "account": EntityKindAccount, @@ -320,6 +402,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, @@ -374,6 +469,19 @@ func PossibleValuesForKillChainIntent() []string { } } +func (s *KillChainIntent) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKillChainIntent(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseKillChainIntent(input string) (*KillChainIntent, error) { vals := map[string]KillChainIntent{ "collection": KillChainIntentCollection, diff --git a/resource-manager/securityinsights/2022-10-01-preview/incidentalerts/method_incidentslistalerts.go b/resource-manager/securityinsights/2022-10-01-preview/incidentalerts/method_incidentslistalerts.go new file mode 100644 index 00000000000..fe83693eae2 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/incidentalerts/method_incidentslistalerts.go @@ -0,0 +1,52 @@ +package incidentalerts + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentsListAlertsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IncidentAlertList +} + +// IncidentsListAlerts ... +func (c IncidentAlertsClient) IncidentsListAlerts(ctx context.Context, id IncidentId) (result IncidentsListAlertsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/alerts", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/incidentalerts/method_incidentslistalerts_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/incidentalerts/method_incidentslistalerts_autorest.go deleted file mode 100644 index de6c08e09a2..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/incidentalerts/method_incidentslistalerts_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package incidentalerts - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IncidentsListAlertsOperationResponse struct { - HttpResponse *http.Response - Model *IncidentAlertList -} - -// IncidentsListAlerts ... -func (c IncidentAlertsClient) IncidentsListAlerts(ctx context.Context, id IncidentId) (result IncidentsListAlertsOperationResponse, err error) { - req, err := c.preparerForIncidentsListAlerts(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentalerts.IncidentAlertsClient", "IncidentsListAlerts", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentalerts.IncidentAlertsClient", "IncidentsListAlerts", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIncidentsListAlerts(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentalerts.IncidentAlertsClient", "IncidentsListAlerts", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIncidentsListAlerts prepares the IncidentsListAlerts request. -func (c IncidentAlertsClient) preparerForIncidentsListAlerts(ctx context.Context, id IncidentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/alerts", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIncidentsListAlerts handles the response to the IncidentsListAlerts request. The method always -// closes the http.Response Body. -func (c IncidentAlertsClient) responderForIncidentsListAlerts(resp *http.Response) (result IncidentsListAlertsOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/incidentbookmarks/client.go b/resource-manager/securityinsights/2022-10-01-preview/incidentbookmarks/client.go index e2fcca6728b..e6a60ede52d 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/incidentbookmarks/client.go +++ b/resource-manager/securityinsights/2022-10-01-preview/incidentbookmarks/client.go @@ -1,18 +1,26 @@ package incidentbookmarks -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type IncidentBookmarksClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewIncidentBookmarksClientWithBaseURI(endpoint string) IncidentBookmarksClient { - return IncidentBookmarksClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewIncidentBookmarksClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentBookmarksClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidentbookmarks", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentBookmarksClient: %+v", err) } + + return &IncidentBookmarksClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-10-01-preview/incidentbookmarks/constants.go b/resource-manager/securityinsights/2022-10-01-preview/incidentbookmarks/constants.go index 4f910b4f6bc..1731dc01ffe 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/incidentbookmarks/constants.go +++ b/resource-manager/securityinsights/2022-10-01-preview/incidentbookmarks/constants.go @@ -1,6 +1,10 @@ package incidentbookmarks -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -23,6 +27,19 @@ func PossibleValuesForAlertSeverity() []string { } } +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertSeverity(input string) (*AlertSeverity, error) { vals := map[string]AlertSeverity{ "high": AlertSeverityHigh, @@ -59,6 +76,19 @@ func PossibleValuesForAlertStatus() []string { } } +func (s *AlertStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertStatus(input string) (*AlertStatus, error) { vals := map[string]AlertStatus{ "dismissed": AlertStatusDismissed, @@ -120,6 +150,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -165,6 +208,19 @@ func PossibleValuesForConfidenceLevel() []string { } } +func (s *ConfidenceLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceLevel(input string) (*ConfidenceLevel, error) { vals := map[string]ConfidenceLevel{ "high": ConfidenceLevelHigh, @@ -198,6 +254,19 @@ func PossibleValuesForConfidenceScoreStatus() []string { } } +func (s *ConfidenceScoreStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceScoreStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceScoreStatus(input string) (*ConfidenceScoreStatus, error) { vals := map[string]ConfidenceScoreStatus{ "final": ConfidenceScoreStatusFinal, @@ -268,6 +337,19 @@ func PossibleValuesForEntityKind() []string { } } +func (s *EntityKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityKind(input string) (*EntityKind, error) { vals := map[string]EntityKind{ "account": EntityKindAccount, @@ -320,6 +402,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, @@ -374,6 +469,19 @@ func PossibleValuesForKillChainIntent() []string { } } +func (s *KillChainIntent) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKillChainIntent(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseKillChainIntent(input string) (*KillChainIntent, error) { vals := map[string]KillChainIntent{ "collection": KillChainIntentCollection, diff --git a/resource-manager/securityinsights/2022-10-01-preview/incidentbookmarks/method_incidentslistbookmarks.go b/resource-manager/securityinsights/2022-10-01-preview/incidentbookmarks/method_incidentslistbookmarks.go new file mode 100644 index 00000000000..3ac7b9e8b2e --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/incidentbookmarks/method_incidentslistbookmarks.go @@ -0,0 +1,52 @@ +package incidentbookmarks + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentsListBookmarksOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IncidentBookmarkList +} + +// IncidentsListBookmarks ... +func (c IncidentBookmarksClient) IncidentsListBookmarks(ctx context.Context, id IncidentId) (result IncidentsListBookmarksOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/bookmarks", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/incidentbookmarks/method_incidentslistbookmarks_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/incidentbookmarks/method_incidentslistbookmarks_autorest.go deleted file mode 100644 index a5c3a89a09c..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/incidentbookmarks/method_incidentslistbookmarks_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package incidentbookmarks - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IncidentsListBookmarksOperationResponse struct { - HttpResponse *http.Response - Model *IncidentBookmarkList -} - -// IncidentsListBookmarks ... -func (c IncidentBookmarksClient) IncidentsListBookmarks(ctx context.Context, id IncidentId) (result IncidentsListBookmarksOperationResponse, err error) { - req, err := c.preparerForIncidentsListBookmarks(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentbookmarks.IncidentBookmarksClient", "IncidentsListBookmarks", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentbookmarks.IncidentBookmarksClient", "IncidentsListBookmarks", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIncidentsListBookmarks(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentbookmarks.IncidentBookmarksClient", "IncidentsListBookmarks", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIncidentsListBookmarks prepares the IncidentsListBookmarks request. -func (c IncidentBookmarksClient) preparerForIncidentsListBookmarks(ctx context.Context, id IncidentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/bookmarks", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIncidentsListBookmarks handles the response to the IncidentsListBookmarks request. The method always -// closes the http.Response Body. -func (c IncidentBookmarksClient) responderForIncidentsListBookmarks(resp *http.Response) (result IncidentsListBookmarksOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/incidentcomments/client.go b/resource-manager/securityinsights/2022-10-01-preview/incidentcomments/client.go index 4006779247d..981e6f75216 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/incidentcomments/client.go +++ b/resource-manager/securityinsights/2022-10-01-preview/incidentcomments/client.go @@ -1,18 +1,26 @@ package incidentcomments -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type IncidentCommentsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewIncidentCommentsClientWithBaseURI(endpoint string) IncidentCommentsClient { - return IncidentCommentsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewIncidentCommentsClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentCommentsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidentcomments", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentCommentsClient: %+v", err) } + + return &IncidentCommentsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-10-01-preview/incidentcomments/method_createorupdate.go b/resource-manager/securityinsights/2022-10-01-preview/incidentcomments/method_createorupdate.go new file mode 100644 index 00000000000..5c59b2be8d3 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/incidentcomments/method_createorupdate.go @@ -0,0 +1,56 @@ +package incidentcomments + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IncidentComment +} + +// CreateOrUpdate ... +func (c IncidentCommentsClient) CreateOrUpdate(ctx context.Context, id CommentId, input IncidentComment) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/incidentcomments/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/incidentcomments/method_createorupdate_autorest.go deleted file mode 100644 index b27777aad2c..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/incidentcomments/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package incidentcomments - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *IncidentComment -} - -// CreateOrUpdate ... -func (c IncidentCommentsClient) CreateOrUpdate(ctx context.Context, id CommentId, input IncidentComment) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c IncidentCommentsClient) preparerForCreateOrUpdate(ctx context.Context, id CommentId, input IncidentComment) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c IncidentCommentsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/incidentcomments/method_delete.go b/resource-manager/securityinsights/2022-10-01-preview/incidentcomments/method_delete.go new file mode 100644 index 00000000000..78412a13e76 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/incidentcomments/method_delete.go @@ -0,0 +1,47 @@ +package incidentcomments + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c IncidentCommentsClient) Delete(ctx context.Context, id CommentId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/incidentcomments/method_delete_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/incidentcomments/method_delete_autorest.go deleted file mode 100644 index 6bbb4c92cbf..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/incidentcomments/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package incidentcomments - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c IncidentCommentsClient) Delete(ctx context.Context, id CommentId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c IncidentCommentsClient) preparerForDelete(ctx context.Context, id CommentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c IncidentCommentsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/incidentcomments/method_get.go b/resource-manager/securityinsights/2022-10-01-preview/incidentcomments/method_get.go new file mode 100644 index 00000000000..e8d11306ddb --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/incidentcomments/method_get.go @@ -0,0 +1,51 @@ +package incidentcomments + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IncidentComment +} + +// Get ... +func (c IncidentCommentsClient) Get(ctx context.Context, id CommentId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/incidentcomments/method_get_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/incidentcomments/method_get_autorest.go deleted file mode 100644 index 8402ed77e94..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/incidentcomments/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package incidentcomments - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *IncidentComment -} - -// Get ... -func (c IncidentCommentsClient) Get(ctx context.Context, id CommentId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c IncidentCommentsClient) preparerForGet(ctx context.Context, id CommentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c IncidentCommentsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/incidentcomments/method_list.go b/resource-manager/securityinsights/2022-10-01-preview/incidentcomments/method_list.go new file mode 100644 index 00000000000..b4c16058b38 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/incidentcomments/method_list.go @@ -0,0 +1,127 @@ +package incidentcomments + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]IncidentComment +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []IncidentComment +} + +type ListOperationOptions struct { + Filter *string + Orderby *string + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c IncidentCommentsClient) List(ctx context.Context, id IncidentId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/comments", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]IncidentComment `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c IncidentCommentsClient) ListComplete(ctx context.Context, id IncidentId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, IncidentCommentOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c IncidentCommentsClient) ListCompleteMatchingPredicate(ctx context.Context, id IncidentId, options ListOperationOptions, predicate IncidentCommentOperationPredicate) (result ListCompleteResult, err error) { + items := make([]IncidentComment, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/incidentcomments/method_list_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/incidentcomments/method_list_autorest.go deleted file mode 100644 index 24fb8d1d7e7..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/incidentcomments/method_list_autorest.go +++ /dev/null @@ -1,225 +0,0 @@ -package incidentcomments - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]IncidentComment - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []IncidentComment -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ListOperationOptions struct { - Filter *string - Orderby *string - Top *int64 -} - -func DefaultListOperationOptions() ListOperationOptions { - return ListOperationOptions{} -} - -func (o ListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Filter != nil { - out["$filter"] = *o.Filter - } - - if o.Orderby != nil { - out["$orderby"] = *o.Orderby - } - - if o.Top != nil { - out["$top"] = *o.Top - } - - return out -} - -// List ... -func (c IncidentCommentsClient) List(ctx context.Context, id IncidentId, options ListOperationOptions) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c IncidentCommentsClient) preparerForList(ctx context.Context, id IncidentId, options ListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/comments", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c IncidentCommentsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c IncidentCommentsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []IncidentComment `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c IncidentCommentsClient) ListComplete(ctx context.Context, id IncidentId, options ListOperationOptions) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, options, IncidentCommentOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c IncidentCommentsClient) ListCompleteMatchingPredicate(ctx context.Context, id IncidentId, options ListOperationOptions, predicate IncidentCommentOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]IncidentComment, 0) - - page, err := c.List(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/incidententities/client.go b/resource-manager/securityinsights/2022-10-01-preview/incidententities/client.go index 5f0eaf07782..740e7b81755 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/incidententities/client.go +++ b/resource-manager/securityinsights/2022-10-01-preview/incidententities/client.go @@ -1,18 +1,26 @@ package incidententities -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type IncidentEntitiesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewIncidentEntitiesClientWithBaseURI(endpoint string) IncidentEntitiesClient { - return IncidentEntitiesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewIncidentEntitiesClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentEntitiesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidententities", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentEntitiesClient: %+v", err) } + + return &IncidentEntitiesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-10-01-preview/incidententities/constants.go b/resource-manager/securityinsights/2022-10-01-preview/incidententities/constants.go index 53a786bdda5..996bca7e8dc 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/incidententities/constants.go +++ b/resource-manager/securityinsights/2022-10-01-preview/incidententities/constants.go @@ -1,6 +1,10 @@ package incidententities -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -23,6 +27,19 @@ func PossibleValuesForAlertSeverity() []string { } } +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertSeverity(input string) (*AlertSeverity, error) { vals := map[string]AlertSeverity{ "high": AlertSeverityHigh, @@ -59,6 +76,19 @@ func PossibleValuesForAlertStatus() []string { } } +func (s *AlertStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertStatus(input string) (*AlertStatus, error) { vals := map[string]AlertStatus{ "dismissed": AlertStatusDismissed, @@ -120,6 +150,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -165,6 +208,19 @@ func PossibleValuesForConfidenceLevel() []string { } } +func (s *ConfidenceLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceLevel(input string) (*ConfidenceLevel, error) { vals := map[string]ConfidenceLevel{ "high": ConfidenceLevelHigh, @@ -198,6 +254,19 @@ func PossibleValuesForConfidenceScoreStatus() []string { } } +func (s *ConfidenceScoreStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceScoreStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceScoreStatus(input string) (*ConfidenceScoreStatus, error) { vals := map[string]ConfidenceScoreStatus{ "final": ConfidenceScoreStatusFinal, @@ -268,6 +337,19 @@ func PossibleValuesForEntityKind() []string { } } +func (s *EntityKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityKind(input string) (*EntityKind, error) { vals := map[string]EntityKind{ "account": EntityKindAccount, @@ -320,6 +402,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, @@ -374,6 +469,19 @@ func PossibleValuesForKillChainIntent() []string { } } +func (s *KillChainIntent) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKillChainIntent(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseKillChainIntent(input string) (*KillChainIntent, error) { vals := map[string]KillChainIntent{ "collection": KillChainIntentCollection, diff --git a/resource-manager/securityinsights/2022-10-01-preview/incidententities/method_incidentslistentities.go b/resource-manager/securityinsights/2022-10-01-preview/incidententities/method_incidentslistentities.go new file mode 100644 index 00000000000..36ec8f0c75b --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/incidententities/method_incidentslistentities.go @@ -0,0 +1,52 @@ +package incidententities + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentsListEntitiesOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IncidentEntitiesResponse +} + +// IncidentsListEntities ... +func (c IncidentEntitiesClient) IncidentsListEntities(ctx context.Context, id IncidentId) (result IncidentsListEntitiesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/entities", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/incidententities/method_incidentslistentities_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/incidententities/method_incidentslistentities_autorest.go deleted file mode 100644 index 9d796d431cb..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/incidententities/method_incidentslistentities_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package incidententities - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IncidentsListEntitiesOperationResponse struct { - HttpResponse *http.Response - Model *IncidentEntitiesResponse -} - -// IncidentsListEntities ... -func (c IncidentEntitiesClient) IncidentsListEntities(ctx context.Context, id IncidentId) (result IncidentsListEntitiesOperationResponse, err error) { - req, err := c.preparerForIncidentsListEntities(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidententities.IncidentEntitiesClient", "IncidentsListEntities", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidententities.IncidentEntitiesClient", "IncidentsListEntities", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIncidentsListEntities(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidententities.IncidentEntitiesClient", "IncidentsListEntities", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIncidentsListEntities prepares the IncidentsListEntities request. -func (c IncidentEntitiesClient) preparerForIncidentsListEntities(ctx context.Context, id IncidentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/entities", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIncidentsListEntities handles the response to the IncidentsListEntities request. The method always -// closes the http.Response Body. -func (c IncidentEntitiesClient) responderForIncidentsListEntities(resp *http.Response) (result IncidentsListEntitiesOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/incidentrelations/client.go b/resource-manager/securityinsights/2022-10-01-preview/incidentrelations/client.go index 58aa27c43e8..4e8fbfeb71d 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/incidentrelations/client.go +++ b/resource-manager/securityinsights/2022-10-01-preview/incidentrelations/client.go @@ -1,18 +1,26 @@ package incidentrelations -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type IncidentRelationsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewIncidentRelationsClientWithBaseURI(endpoint string) IncidentRelationsClient { - return IncidentRelationsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewIncidentRelationsClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentRelationsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidentrelations", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentRelationsClient: %+v", err) } + + return &IncidentRelationsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-10-01-preview/incidentrelations/method_createorupdate.go b/resource-manager/securityinsights/2022-10-01-preview/incidentrelations/method_createorupdate.go new file mode 100644 index 00000000000..e87f1b4b752 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/incidentrelations/method_createorupdate.go @@ -0,0 +1,56 @@ +package incidentrelations + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Relation +} + +// CreateOrUpdate ... +func (c IncidentRelationsClient) CreateOrUpdate(ctx context.Context, id IncidentRelationId, input Relation) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/incidentrelations/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/incidentrelations/method_createorupdate_autorest.go deleted file mode 100644 index 26334017af9..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/incidentrelations/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package incidentrelations - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *Relation -} - -// CreateOrUpdate ... -func (c IncidentRelationsClient) CreateOrUpdate(ctx context.Context, id IncidentRelationId, input Relation) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c IncidentRelationsClient) preparerForCreateOrUpdate(ctx context.Context, id IncidentRelationId, input Relation) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c IncidentRelationsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/incidentrelations/method_delete.go b/resource-manager/securityinsights/2022-10-01-preview/incidentrelations/method_delete.go new file mode 100644 index 00000000000..7206ac26d08 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/incidentrelations/method_delete.go @@ -0,0 +1,47 @@ +package incidentrelations + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c IncidentRelationsClient) Delete(ctx context.Context, id IncidentRelationId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/incidentrelations/method_delete_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/incidentrelations/method_delete_autorest.go deleted file mode 100644 index d288fdf5e60..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/incidentrelations/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package incidentrelations - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c IncidentRelationsClient) Delete(ctx context.Context, id IncidentRelationId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c IncidentRelationsClient) preparerForDelete(ctx context.Context, id IncidentRelationId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c IncidentRelationsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/incidentrelations/method_get.go b/resource-manager/securityinsights/2022-10-01-preview/incidentrelations/method_get.go new file mode 100644 index 00000000000..a6e7333f2e6 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/incidentrelations/method_get.go @@ -0,0 +1,51 @@ +package incidentrelations + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Relation +} + +// Get ... +func (c IncidentRelationsClient) Get(ctx context.Context, id IncidentRelationId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/incidentrelations/method_get_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/incidentrelations/method_get_autorest.go deleted file mode 100644 index 4cb22a2ba53..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/incidentrelations/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package incidentrelations - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *Relation -} - -// Get ... -func (c IncidentRelationsClient) Get(ctx context.Context, id IncidentRelationId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c IncidentRelationsClient) preparerForGet(ctx context.Context, id IncidentRelationId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c IncidentRelationsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/incidentrelations/method_list.go b/resource-manager/securityinsights/2022-10-01-preview/incidentrelations/method_list.go new file mode 100644 index 00000000000..80873d441b4 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/incidentrelations/method_list.go @@ -0,0 +1,127 @@ +package incidentrelations + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Relation +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Relation +} + +type ListOperationOptions struct { + Filter *string + Orderby *string + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c IncidentRelationsClient) List(ctx context.Context, id IncidentId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/relations", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Relation `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c IncidentRelationsClient) ListComplete(ctx context.Context, id IncidentId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, RelationOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c IncidentRelationsClient) ListCompleteMatchingPredicate(ctx context.Context, id IncidentId, options ListOperationOptions, predicate RelationOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Relation, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/incidentrelations/method_list_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/incidentrelations/method_list_autorest.go deleted file mode 100644 index a270a442886..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/incidentrelations/method_list_autorest.go +++ /dev/null @@ -1,225 +0,0 @@ -package incidentrelations - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]Relation - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []Relation -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ListOperationOptions struct { - Filter *string - Orderby *string - Top *int64 -} - -func DefaultListOperationOptions() ListOperationOptions { - return ListOperationOptions{} -} - -func (o ListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Filter != nil { - out["$filter"] = *o.Filter - } - - if o.Orderby != nil { - out["$orderby"] = *o.Orderby - } - - if o.Top != nil { - out["$top"] = *o.Top - } - - return out -} - -// List ... -func (c IncidentRelationsClient) List(ctx context.Context, id IncidentId, options ListOperationOptions) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c IncidentRelationsClient) preparerForList(ctx context.Context, id IncidentId, options ListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/relations", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c IncidentRelationsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c IncidentRelationsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []Relation `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c IncidentRelationsClient) ListComplete(ctx context.Context, id IncidentId, options ListOperationOptions) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, options, RelationOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c IncidentRelationsClient) ListCompleteMatchingPredicate(ctx context.Context, id IncidentId, options ListOperationOptions, predicate RelationOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]Relation, 0) - - page, err := c.List(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/incidents/client.go b/resource-manager/securityinsights/2022-10-01-preview/incidents/client.go index 659897d18d7..aaf38071c39 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/incidents/client.go +++ b/resource-manager/securityinsights/2022-10-01-preview/incidents/client.go @@ -1,18 +1,26 @@ package incidents -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type IncidentsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewIncidentsClientWithBaseURI(endpoint string) IncidentsClient { - return IncidentsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewIncidentsClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidents", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentsClient: %+v", err) } + + return &IncidentsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-10-01-preview/incidents/constants.go b/resource-manager/securityinsights/2022-10-01-preview/incidents/constants.go index 82782d4107f..ce046b9edba 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/incidents/constants.go +++ b/resource-manager/securityinsights/2022-10-01-preview/incidents/constants.go @@ -1,6 +1,10 @@ package incidents -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -49,6 +53,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -96,6 +113,19 @@ func PossibleValuesForIncidentClassification() []string { } } +func (s *IncidentClassification) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentClassification(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentClassification(input string) (*IncidentClassification, error) { vals := map[string]IncidentClassification{ "benignpositive": IncidentClassificationBenignPositive, @@ -130,6 +160,19 @@ func PossibleValuesForIncidentClassificationReason() []string { } } +func (s *IncidentClassificationReason) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentClassificationReason(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentClassificationReason(input string) (*IncidentClassificationReason, error) { vals := map[string]IncidentClassificationReason{ "inaccuratedata": IncidentClassificationReasonInaccurateData, @@ -160,6 +203,19 @@ func PossibleValuesForIncidentLabelType() []string { } } +func (s *IncidentLabelType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentLabelType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentLabelType(input string) (*IncidentLabelType, error) { vals := map[string]IncidentLabelType{ "autoassigned": IncidentLabelTypeAutoAssigned, @@ -192,6 +248,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, @@ -224,6 +293,19 @@ func PossibleValuesForIncidentStatus() []string { } } +func (s *IncidentStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentStatus(input string) (*IncidentStatus, error) { vals := map[string]IncidentStatus{ "active": IncidentStatusActive, @@ -255,6 +337,19 @@ func PossibleValuesForOwnerType() []string { } } +func (s *OwnerType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOwnerType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseOwnerType(input string) (*OwnerType, error) { vals := map[string]OwnerType{ "group": OwnerTypeGroup, diff --git a/resource-manager/securityinsights/2022-10-01-preview/incidents/method_createorupdate.go b/resource-manager/securityinsights/2022-10-01-preview/incidents/method_createorupdate.go new file mode 100644 index 00000000000..3fcc110ed02 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/incidents/method_createorupdate.go @@ -0,0 +1,56 @@ +package incidents + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Incident +} + +// CreateOrUpdate ... +func (c IncidentsClient) CreateOrUpdate(ctx context.Context, id IncidentId, input Incident) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/incidents/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/incidents/method_createorupdate_autorest.go deleted file mode 100644 index 837aa7c92a0..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/incidents/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package incidents - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *Incident -} - -// CreateOrUpdate ... -func (c IncidentsClient) CreateOrUpdate(ctx context.Context, id IncidentId, input Incident) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c IncidentsClient) preparerForCreateOrUpdate(ctx context.Context, id IncidentId, input Incident) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c IncidentsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/incidents/method_delete.go b/resource-manager/securityinsights/2022-10-01-preview/incidents/method_delete.go new file mode 100644 index 00000000000..9b3205af5fc --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/incidents/method_delete.go @@ -0,0 +1,47 @@ +package incidents + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c IncidentsClient) Delete(ctx context.Context, id IncidentId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/incidents/method_delete_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/incidents/method_delete_autorest.go deleted file mode 100644 index 280832422f8..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/incidents/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package incidents - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c IncidentsClient) Delete(ctx context.Context, id IncidentId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c IncidentsClient) preparerForDelete(ctx context.Context, id IncidentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c IncidentsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/incidents/method_get.go b/resource-manager/securityinsights/2022-10-01-preview/incidents/method_get.go new file mode 100644 index 00000000000..e6d4e9e933b --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/incidents/method_get.go @@ -0,0 +1,51 @@ +package incidents + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Incident +} + +// Get ... +func (c IncidentsClient) Get(ctx context.Context, id IncidentId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/incidents/method_get_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/incidents/method_get_autorest.go deleted file mode 100644 index d8d2b7debeb..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/incidents/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package incidents - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *Incident -} - -// Get ... -func (c IncidentsClient) Get(ctx context.Context, id IncidentId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c IncidentsClient) preparerForGet(ctx context.Context, id IncidentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c IncidentsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/incidents/method_list.go b/resource-manager/securityinsights/2022-10-01-preview/incidents/method_list.go new file mode 100644 index 00000000000..fe19cd4d9ff --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/incidents/method_list.go @@ -0,0 +1,127 @@ +package incidents + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Incident +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Incident +} + +type ListOperationOptions struct { + Filter *string + Orderby *string + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c IncidentsClient) List(ctx context.Context, id WorkspaceId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/incidents", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Incident `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c IncidentsClient) ListComplete(ctx context.Context, id WorkspaceId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, IncidentOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c IncidentsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ListOperationOptions, predicate IncidentOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Incident, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/incidents/method_list_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/incidents/method_list_autorest.go deleted file mode 100644 index 8d2f5acc547..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/incidents/method_list_autorest.go +++ /dev/null @@ -1,225 +0,0 @@ -package incidents - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]Incident - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []Incident -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ListOperationOptions struct { - Filter *string - Orderby *string - Top *int64 -} - -func DefaultListOperationOptions() ListOperationOptions { - return ListOperationOptions{} -} - -func (o ListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Filter != nil { - out["$filter"] = *o.Filter - } - - if o.Orderby != nil { - out["$orderby"] = *o.Orderby - } - - if o.Top != nil { - out["$top"] = *o.Top - } - - return out -} - -// List ... -func (c IncidentsClient) List(ctx context.Context, id WorkspaceId, options ListOperationOptions) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c IncidentsClient) preparerForList(ctx context.Context, id WorkspaceId, options ListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/incidents", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c IncidentsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c IncidentsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []Incident `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c IncidentsClient) ListComplete(ctx context.Context, id WorkspaceId, options ListOperationOptions) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, options, IncidentOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c IncidentsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ListOperationOptions, predicate IncidentOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]Incident, 0) - - page, err := c.List(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/incidentteam/client.go b/resource-manager/securityinsights/2022-10-01-preview/incidentteam/client.go index c48730b50ab..75ab2cfb3b1 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/incidentteam/client.go +++ b/resource-manager/securityinsights/2022-10-01-preview/incidentteam/client.go @@ -1,18 +1,26 @@ package incidentteam -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type IncidentTeamClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewIncidentTeamClientWithBaseURI(endpoint string) IncidentTeamClient { - return IncidentTeamClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewIncidentTeamClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentTeamClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidentteam", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentTeamClient: %+v", err) } + + return &IncidentTeamClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-10-01-preview/incidentteam/method_incidentscreateteam.go b/resource-manager/securityinsights/2022-10-01-preview/incidentteam/method_incidentscreateteam.go new file mode 100644 index 00000000000..934052e83a4 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/incidentteam/method_incidentscreateteam.go @@ -0,0 +1,56 @@ +package incidentteam + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentsCreateTeamOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *TeamInformation +} + +// IncidentsCreateTeam ... +func (c IncidentTeamClient) IncidentsCreateTeam(ctx context.Context, id IncidentId, input TeamProperties) (result IncidentsCreateTeamOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/createTeam", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/incidentteam/method_incidentscreateteam_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/incidentteam/method_incidentscreateteam_autorest.go deleted file mode 100644 index 028fc51c6a2..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/incidentteam/method_incidentscreateteam_autorest.go +++ /dev/null @@ -1,70 +0,0 @@ -package incidentteam - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IncidentsCreateTeamOperationResponse struct { - HttpResponse *http.Response - Model *TeamInformation -} - -// IncidentsCreateTeam ... -func (c IncidentTeamClient) IncidentsCreateTeam(ctx context.Context, id IncidentId, input TeamProperties) (result IncidentsCreateTeamOperationResponse, err error) { - req, err := c.preparerForIncidentsCreateTeam(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentteam.IncidentTeamClient", "IncidentsCreateTeam", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentteam.IncidentTeamClient", "IncidentsCreateTeam", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIncidentsCreateTeam(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentteam.IncidentTeamClient", "IncidentsCreateTeam", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIncidentsCreateTeam prepares the IncidentsCreateTeam request. -func (c IncidentTeamClient) preparerForIncidentsCreateTeam(ctx context.Context, id IncidentId, input TeamProperties) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/createTeam", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIncidentsCreateTeam handles the response to the IncidentsCreateTeam request. The method always -// closes the http.Response Body. -func (c IncidentTeamClient) responderForIncidentsCreateTeam(resp *http.Response) (result IncidentsCreateTeamOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/manualtrigger/client.go b/resource-manager/securityinsights/2022-10-01-preview/manualtrigger/client.go index e34b6854084..da5817ede95 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/manualtrigger/client.go +++ b/resource-manager/securityinsights/2022-10-01-preview/manualtrigger/client.go @@ -1,18 +1,26 @@ package manualtrigger -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type ManualTriggerClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewManualTriggerClientWithBaseURI(endpoint string) ManualTriggerClient { - return ManualTriggerClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewManualTriggerClientWithBaseURI(sdkApi sdkEnv.Api) (*ManualTriggerClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "manualtrigger", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ManualTriggerClient: %+v", err) } + + return &ManualTriggerClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-10-01-preview/manualtrigger/method_incidentsrunplaybook.go b/resource-manager/securityinsights/2022-10-01-preview/manualtrigger/method_incidentsrunplaybook.go new file mode 100644 index 00000000000..5c95680f507 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/manualtrigger/method_incidentsrunplaybook.go @@ -0,0 +1,56 @@ +package manualtrigger + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentsRunPlaybookOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *interface{} +} + +// IncidentsRunPlaybook ... +func (c ManualTriggerClient) IncidentsRunPlaybook(ctx context.Context, id IncidentId, input ManualTriggerRequestBody) (result IncidentsRunPlaybookOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/runPlaybook", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/manualtrigger/method_incidentsrunplaybook_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/manualtrigger/method_incidentsrunplaybook_autorest.go deleted file mode 100644 index 2c7b4d5c710..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/manualtrigger/method_incidentsrunplaybook_autorest.go +++ /dev/null @@ -1,70 +0,0 @@ -package manualtrigger - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IncidentsRunPlaybookOperationResponse struct { - HttpResponse *http.Response - Model *interface{} -} - -// IncidentsRunPlaybook ... -func (c ManualTriggerClient) IncidentsRunPlaybook(ctx context.Context, id IncidentId, input ManualTriggerRequestBody) (result IncidentsRunPlaybookOperationResponse, err error) { - req, err := c.preparerForIncidentsRunPlaybook(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "manualtrigger.ManualTriggerClient", "IncidentsRunPlaybook", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "manualtrigger.ManualTriggerClient", "IncidentsRunPlaybook", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIncidentsRunPlaybook(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "manualtrigger.ManualTriggerClient", "IncidentsRunPlaybook", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIncidentsRunPlaybook prepares the IncidentsRunPlaybook request. -func (c ManualTriggerClient) preparerForIncidentsRunPlaybook(ctx context.Context, id IncidentId, input ManualTriggerRequestBody) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/runPlaybook", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIncidentsRunPlaybook handles the response to the IncidentsRunPlaybook request. The method always -// closes the http.Response Body. -func (c ManualTriggerClient) responderForIncidentsRunPlaybook(resp *http.Response) (result IncidentsRunPlaybookOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/metadata/client.go b/resource-manager/securityinsights/2022-10-01-preview/metadata/client.go index 05f0e7940c0..59e4192159f 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/metadata/client.go +++ b/resource-manager/securityinsights/2022-10-01-preview/metadata/client.go @@ -1,18 +1,26 @@ package metadata -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type MetadataClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewMetadataClientWithBaseURI(endpoint string) MetadataClient { - return MetadataClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewMetadataClientWithBaseURI(sdkApi sdkEnv.Api) (*MetadataClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "metadata", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating MetadataClient: %+v", err) } + + return &MetadataClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-10-01-preview/metadata/constants.go b/resource-manager/securityinsights/2022-10-01-preview/metadata/constants.go index d64c8db1b25..e1a5d1b92ff 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/metadata/constants.go +++ b/resource-manager/securityinsights/2022-10-01-preview/metadata/constants.go @@ -1,6 +1,10 @@ package metadata -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -49,6 +53,19 @@ func PossibleValuesForKind() []string { } } +func (s *Kind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseKind(input string) (*Kind, error) { vals := map[string]Kind{ "analyticsrule": KindAnalyticsRule, @@ -92,6 +109,19 @@ func PossibleValuesForOperator() []string { } } +func (s *Operator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseOperator(input string) (*Operator, error) { vals := map[string]Operator{ "and": OperatorAND, @@ -124,6 +154,19 @@ func PossibleValuesForSourceKind() []string { } } +func (s *SourceKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSourceKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSourceKind(input string) (*SourceKind, error) { vals := map[string]SourceKind{ "community": SourceKindCommunity, @@ -156,6 +199,19 @@ func PossibleValuesForSupportTier() []string { } } +func (s *SupportTier) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSupportTier(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSupportTier(input string) (*SupportTier, error) { vals := map[string]SupportTier{ "community": SupportTierCommunity, diff --git a/resource-manager/securityinsights/2022-10-01-preview/metadata/method_create.go b/resource-manager/securityinsights/2022-10-01-preview/metadata/method_create.go new file mode 100644 index 00000000000..36522e6397c --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/metadata/method_create.go @@ -0,0 +1,56 @@ +package metadata + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *MetadataModel +} + +// Create ... +func (c MetadataClient) Create(ctx context.Context, id MetadataId, input MetadataModel) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/metadata/method_create_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/metadata/method_create_autorest.go deleted file mode 100644 index 1ae47584687..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/metadata/method_create_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package metadata - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOperationResponse struct { - HttpResponse *http.Response - Model *MetadataModel -} - -// Create ... -func (c MetadataClient) Create(ctx context.Context, id MetadataId, input MetadataModel) (result CreateOperationResponse, err error) { - req, err := c.preparerForCreate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Create", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Create", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Create", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreate prepares the Create request. -func (c MetadataClient) preparerForCreate(ctx context.Context, id MetadataId, input MetadataModel) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreate handles the response to the Create request. The method always -// closes the http.Response Body. -func (c MetadataClient) responderForCreate(resp *http.Response) (result CreateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/metadata/method_delete.go b/resource-manager/securityinsights/2022-10-01-preview/metadata/method_delete.go new file mode 100644 index 00000000000..559f479cb03 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/metadata/method_delete.go @@ -0,0 +1,47 @@ +package metadata + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c MetadataClient) Delete(ctx context.Context, id MetadataId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/metadata/method_delete_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/metadata/method_delete_autorest.go deleted file mode 100644 index 3a151eefd21..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/metadata/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package metadata - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c MetadataClient) Delete(ctx context.Context, id MetadataId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c MetadataClient) preparerForDelete(ctx context.Context, id MetadataId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c MetadataClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/metadata/method_get.go b/resource-manager/securityinsights/2022-10-01-preview/metadata/method_get.go new file mode 100644 index 00000000000..a687bafec62 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/metadata/method_get.go @@ -0,0 +1,51 @@ +package metadata + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *MetadataModel +} + +// Get ... +func (c MetadataClient) Get(ctx context.Context, id MetadataId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/metadata/method_get_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/metadata/method_get_autorest.go deleted file mode 100644 index 25827d74702..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/metadata/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package metadata - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *MetadataModel -} - -// Get ... -func (c MetadataClient) Get(ctx context.Context, id MetadataId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c MetadataClient) preparerForGet(ctx context.Context, id MetadataId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c MetadataClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/metadata/method_list.go b/resource-manager/securityinsights/2022-10-01-preview/metadata/method_list.go new file mode 100644 index 00000000000..58267143629 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/metadata/method_list.go @@ -0,0 +1,131 @@ +package metadata + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]MetadataModel +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []MetadataModel +} + +type ListOperationOptions struct { + Filter *string + Orderby *string + Skip *int64 + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c MetadataClient) List(ctx context.Context, id WorkspaceId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/metadata", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]MetadataModel `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c MetadataClient) ListComplete(ctx context.Context, id WorkspaceId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, MetadataModelOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c MetadataClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ListOperationOptions, predicate MetadataModelOperationPredicate) (result ListCompleteResult, err error) { + items := make([]MetadataModel, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/metadata/method_list_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/metadata/method_list_autorest.go deleted file mode 100644 index e5f025d62ee..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/metadata/method_list_autorest.go +++ /dev/null @@ -1,230 +0,0 @@ -package metadata - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]MetadataModel - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []MetadataModel -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ListOperationOptions struct { - Filter *string - Orderby *string - Skip *int64 - Top *int64 -} - -func DefaultListOperationOptions() ListOperationOptions { - return ListOperationOptions{} -} - -func (o ListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Filter != nil { - out["$filter"] = *o.Filter - } - - if o.Orderby != nil { - out["$orderby"] = *o.Orderby - } - - if o.Skip != nil { - out["$skip"] = *o.Skip - } - - if o.Top != nil { - out["$top"] = *o.Top - } - - return out -} - -// List ... -func (c MetadataClient) List(ctx context.Context, id WorkspaceId, options ListOperationOptions) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c MetadataClient) preparerForList(ctx context.Context, id WorkspaceId, options ListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/metadata", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c MetadataClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c MetadataClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []MetadataModel `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c MetadataClient) ListComplete(ctx context.Context, id WorkspaceId, options ListOperationOptions) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, options, MetadataModelOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c MetadataClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ListOperationOptions, predicate MetadataModelOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]MetadataModel, 0) - - page, err := c.List(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/metadata/method_update.go b/resource-manager/securityinsights/2022-10-01-preview/metadata/method_update.go new file mode 100644 index 00000000000..47f777cee27 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/metadata/method_update.go @@ -0,0 +1,55 @@ +package metadata + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *MetadataModel +} + +// Update ... +func (c MetadataClient) Update(ctx context.Context, id MetadataId, input MetadataPatch) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/metadata/method_update_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/metadata/method_update_autorest.go deleted file mode 100644 index a4bd18d08d6..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/metadata/method_update_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package metadata - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type UpdateOperationResponse struct { - HttpResponse *http.Response - Model *MetadataModel -} - -// Update ... -func (c MetadataClient) Update(ctx context.Context, id MetadataId, input MetadataPatch) (result UpdateOperationResponse, err error) { - req, err := c.preparerForUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Update", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Update", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Update", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForUpdate prepares the Update request. -func (c MetadataClient) preparerForUpdate(ctx context.Context, id MetadataId, input MetadataPatch) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPatch(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForUpdate handles the response to the Update request. The method always -// closes the http.Response Body. -func (c MetadataClient) responderForUpdate(resp *http.Response) (result UpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/officeconsents/client.go b/resource-manager/securityinsights/2022-10-01-preview/officeconsents/client.go index 7f0466f7160..2c2efc37d3d 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/officeconsents/client.go +++ b/resource-manager/securityinsights/2022-10-01-preview/officeconsents/client.go @@ -1,18 +1,26 @@ package officeconsents -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type OfficeConsentsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewOfficeConsentsClientWithBaseURI(endpoint string) OfficeConsentsClient { - return OfficeConsentsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewOfficeConsentsClientWithBaseURI(sdkApi sdkEnv.Api) (*OfficeConsentsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "officeconsents", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating OfficeConsentsClient: %+v", err) } + + return &OfficeConsentsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-10-01-preview/officeconsents/method_delete.go b/resource-manager/securityinsights/2022-10-01-preview/officeconsents/method_delete.go new file mode 100644 index 00000000000..3c098e73784 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/officeconsents/method_delete.go @@ -0,0 +1,47 @@ +package officeconsents + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c OfficeConsentsClient) Delete(ctx context.Context, id OfficeConsentId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/officeconsents/method_delete_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/officeconsents/method_delete_autorest.go deleted file mode 100644 index 231f4a35afd..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/officeconsents/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package officeconsents - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c OfficeConsentsClient) Delete(ctx context.Context, id OfficeConsentId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "officeconsents.OfficeConsentsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "officeconsents.OfficeConsentsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "officeconsents.OfficeConsentsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c OfficeConsentsClient) preparerForDelete(ctx context.Context, id OfficeConsentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c OfficeConsentsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/officeconsents/method_get.go b/resource-manager/securityinsights/2022-10-01-preview/officeconsents/method_get.go new file mode 100644 index 00000000000..4d81ae6bf20 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/officeconsents/method_get.go @@ -0,0 +1,51 @@ +package officeconsents + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *OfficeConsent +} + +// Get ... +func (c OfficeConsentsClient) Get(ctx context.Context, id OfficeConsentId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/officeconsents/method_get_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/officeconsents/method_get_autorest.go deleted file mode 100644 index bb10097614d..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/officeconsents/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package officeconsents - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *OfficeConsent -} - -// Get ... -func (c OfficeConsentsClient) Get(ctx context.Context, id OfficeConsentId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "officeconsents.OfficeConsentsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "officeconsents.OfficeConsentsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "officeconsents.OfficeConsentsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c OfficeConsentsClient) preparerForGet(ctx context.Context, id OfficeConsentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c OfficeConsentsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/officeconsents/method_list.go b/resource-manager/securityinsights/2022-10-01-preview/officeconsents/method_list.go new file mode 100644 index 00000000000..e23bd7dddfb --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/officeconsents/method_list.go @@ -0,0 +1,91 @@ +package officeconsents + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]OfficeConsent +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []OfficeConsent +} + +// List ... +func (c OfficeConsentsClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/officeConsents", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]OfficeConsent `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c OfficeConsentsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, OfficeConsentOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c OfficeConsentsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate OfficeConsentOperationPredicate) (result ListCompleteResult, err error) { + items := make([]OfficeConsent, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/officeconsents/method_list_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/officeconsents/method_list_autorest.go deleted file mode 100644 index d306e76d443..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/officeconsents/method_list_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package officeconsents - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]OfficeConsent - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []OfficeConsent -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c OfficeConsentsClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "officeconsents.OfficeConsentsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "officeconsents.OfficeConsentsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "officeconsents.OfficeConsentsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c OfficeConsentsClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/officeConsents", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c OfficeConsentsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c OfficeConsentsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []OfficeConsent `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "officeconsents.OfficeConsentsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "officeconsents.OfficeConsentsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "officeconsents.OfficeConsentsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c OfficeConsentsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, OfficeConsentOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c OfficeConsentsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate OfficeConsentOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]OfficeConsent, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/repositories/client.go b/resource-manager/securityinsights/2022-10-01-preview/repositories/client.go index 562953712b0..62b7be88387 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/repositories/client.go +++ b/resource-manager/securityinsights/2022-10-01-preview/repositories/client.go @@ -1,18 +1,26 @@ package repositories -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type RepositoriesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewRepositoriesClientWithBaseURI(endpoint string) RepositoriesClient { - return RepositoriesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewRepositoriesClientWithBaseURI(sdkApi sdkEnv.Api) (*RepositoriesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "repositories", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating RepositoriesClient: %+v", err) } + + return &RepositoriesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-10-01-preview/repositories/constants.go b/resource-manager/securityinsights/2022-10-01-preview/repositories/constants.go index b8d5b729aae..828121b73be 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/repositories/constants.go +++ b/resource-manager/securityinsights/2022-10-01-preview/repositories/constants.go @@ -1,6 +1,10 @@ package repositories -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -19,6 +23,19 @@ func PossibleValuesForRepoType() []string { } } +func (s *RepoType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRepoType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseRepoType(input string) (*RepoType, error) { vals := map[string]RepoType{ "devops": RepoTypeDevOps, diff --git a/resource-manager/securityinsights/2022-10-01-preview/repositories/method_sourcecontrollistrepositories.go b/resource-manager/securityinsights/2022-10-01-preview/repositories/method_sourcecontrollistrepositories.go new file mode 100644 index 00000000000..3a007266273 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/repositories/method_sourcecontrollistrepositories.go @@ -0,0 +1,91 @@ +package repositories + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SourceControllistRepositoriesOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Repo +} + +type SourceControllistRepositoriesCompleteResult struct { + LatestHttpResponse *http.Response + Items []Repo +} + +// SourceControllistRepositories ... +func (c RepositoriesClient) SourceControllistRepositories(ctx context.Context, id WorkspaceId, input RepoType) (result SourceControllistRepositoriesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/listRepositories", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Repo `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// SourceControllistRepositoriesComplete retrieves all the results into a single object +func (c RepositoriesClient) SourceControllistRepositoriesComplete(ctx context.Context, id WorkspaceId, input RepoType) (SourceControllistRepositoriesCompleteResult, error) { + return c.SourceControllistRepositoriesCompleteMatchingPredicate(ctx, id, input, RepoOperationPredicate{}) +} + +// SourceControllistRepositoriesCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c RepositoriesClient) SourceControllistRepositoriesCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, input RepoType, predicate RepoOperationPredicate) (result SourceControllistRepositoriesCompleteResult, err error) { + items := make([]Repo, 0) + + resp, err := c.SourceControllistRepositories(ctx, id, input) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = SourceControllistRepositoriesCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/repositories/method_sourcecontrollistrepositories_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/repositories/method_sourcecontrollistrepositories_autorest.go deleted file mode 100644 index 1bbe7743728..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/repositories/method_sourcecontrollistrepositories_autorest.go +++ /dev/null @@ -1,187 +0,0 @@ -package repositories - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type SourceControllistRepositoriesOperationResponse struct { - HttpResponse *http.Response - Model *[]Repo - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (SourceControllistRepositoriesOperationResponse, error) -} - -type SourceControllistRepositoriesCompleteResult struct { - Items []Repo -} - -func (r SourceControllistRepositoriesOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r SourceControllistRepositoriesOperationResponse) LoadMore(ctx context.Context) (resp SourceControllistRepositoriesOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// SourceControllistRepositories ... -func (c RepositoriesClient) SourceControllistRepositories(ctx context.Context, id WorkspaceId, input RepoType) (resp SourceControllistRepositoriesOperationResponse, err error) { - req, err := c.preparerForSourceControllistRepositories(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "repositories.RepositoriesClient", "SourceControllistRepositories", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "repositories.RepositoriesClient", "SourceControllistRepositories", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForSourceControllistRepositories(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "repositories.RepositoriesClient", "SourceControllistRepositories", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForSourceControllistRepositories prepares the SourceControllistRepositories request. -func (c RepositoriesClient) preparerForSourceControllistRepositories(ctx context.Context, id WorkspaceId, input RepoType) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/listRepositories", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForSourceControllistRepositoriesWithNextLink prepares the SourceControllistRepositories request with the given nextLink token. -func (c RepositoriesClient) preparerForSourceControllistRepositoriesWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForSourceControllistRepositories handles the response to the SourceControllistRepositories request. The method always -// closes the http.Response Body. -func (c RepositoriesClient) responderForSourceControllistRepositories(resp *http.Response) (result SourceControllistRepositoriesOperationResponse, err error) { - type page struct { - Values []Repo `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result SourceControllistRepositoriesOperationResponse, err error) { - req, err := c.preparerForSourceControllistRepositoriesWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "repositories.RepositoriesClient", "SourceControllistRepositories", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "repositories.RepositoriesClient", "SourceControllistRepositories", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForSourceControllistRepositories(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "repositories.RepositoriesClient", "SourceControllistRepositories", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// SourceControllistRepositoriesComplete retrieves all of the results into a single object -func (c RepositoriesClient) SourceControllistRepositoriesComplete(ctx context.Context, id WorkspaceId, input RepoType) (SourceControllistRepositoriesCompleteResult, error) { - return c.SourceControllistRepositoriesCompleteMatchingPredicate(ctx, id, input, RepoOperationPredicate{}) -} - -// SourceControllistRepositoriesCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c RepositoriesClient) SourceControllistRepositoriesCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, input RepoType, predicate RepoOperationPredicate) (resp SourceControllistRepositoriesCompleteResult, err error) { - items := make([]Repo, 0) - - page, err := c.SourceControllistRepositories(ctx, id, input) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := SourceControllistRepositoriesCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/securitymlanalyticssettings/client.go b/resource-manager/securityinsights/2022-10-01-preview/securitymlanalyticssettings/client.go index 50d64fb429c..65b248a41f5 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/securitymlanalyticssettings/client.go +++ b/resource-manager/securityinsights/2022-10-01-preview/securitymlanalyticssettings/client.go @@ -1,18 +1,26 @@ package securitymlanalyticssettings -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type SecurityMLAnalyticsSettingsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewSecurityMLAnalyticsSettingsClientWithBaseURI(endpoint string) SecurityMLAnalyticsSettingsClient { - return SecurityMLAnalyticsSettingsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewSecurityMLAnalyticsSettingsClientWithBaseURI(sdkApi sdkEnv.Api) (*SecurityMLAnalyticsSettingsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "securitymlanalyticssettings", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SecurityMLAnalyticsSettingsClient: %+v", err) } + + return &SecurityMLAnalyticsSettingsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-10-01-preview/securitymlanalyticssettings/constants.go b/resource-manager/securityinsights/2022-10-01-preview/securitymlanalyticssettings/constants.go index 47b13b875e2..e32d4d9875f 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/securitymlanalyticssettings/constants.go +++ b/resource-manager/securityinsights/2022-10-01-preview/securitymlanalyticssettings/constants.go @@ -1,6 +1,10 @@ package securitymlanalyticssettings -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -49,6 +53,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -90,6 +107,19 @@ func PossibleValuesForSecurityMLAnalyticsSettingsKind() []string { } } +func (s *SecurityMLAnalyticsSettingsKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSecurityMLAnalyticsSettingsKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSecurityMLAnalyticsSettingsKind(input string) (*SecurityMLAnalyticsSettingsKind, error) { vals := map[string]SecurityMLAnalyticsSettingsKind{ "anomaly": SecurityMLAnalyticsSettingsKindAnomaly, @@ -117,6 +147,19 @@ func PossibleValuesForSettingsStatus() []string { } } +func (s *SettingsStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSettingsStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSettingsStatus(input string) (*SettingsStatus, error) { vals := map[string]SettingsStatus{ "flighting": SettingsStatusFlighting, diff --git a/resource-manager/securityinsights/2022-10-01-preview/securitymlanalyticssettings/method_createorupdate.go b/resource-manager/securityinsights/2022-10-01-preview/securitymlanalyticssettings/method_createorupdate.go new file mode 100644 index 00000000000..f08267b7fac --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/securitymlanalyticssettings/method_createorupdate.go @@ -0,0 +1,63 @@ +package securitymlanalyticssettings + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SecurityMLAnalyticsSetting +} + +// CreateOrUpdate ... +func (c SecurityMLAnalyticsSettingsClient) CreateOrUpdate(ctx context.Context, id SecurityMLAnalyticsSettingId, input SecurityMLAnalyticsSetting) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalSecurityMLAnalyticsSettingImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/securitymlanalyticssettings/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/securitymlanalyticssettings/method_createorupdate_autorest.go deleted file mode 100644 index e72d9bcb79b..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/securitymlanalyticssettings/method_createorupdate_autorest.go +++ /dev/null @@ -1,78 +0,0 @@ -package securitymlanalyticssettings - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *SecurityMLAnalyticsSetting -} - -// CreateOrUpdate ... -func (c SecurityMLAnalyticsSettingsClient) CreateOrUpdate(ctx context.Context, id SecurityMLAnalyticsSettingId, input SecurityMLAnalyticsSetting) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c SecurityMLAnalyticsSettingsClient) preparerForCreateOrUpdate(ctx context.Context, id SecurityMLAnalyticsSettingId, input SecurityMLAnalyticsSetting) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c SecurityMLAnalyticsSettingsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalSecurityMLAnalyticsSettingImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/securitymlanalyticssettings/method_delete.go b/resource-manager/securityinsights/2022-10-01-preview/securitymlanalyticssettings/method_delete.go new file mode 100644 index 00000000000..36309ecb138 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/securitymlanalyticssettings/method_delete.go @@ -0,0 +1,47 @@ +package securitymlanalyticssettings + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c SecurityMLAnalyticsSettingsClient) Delete(ctx context.Context, id SecurityMLAnalyticsSettingId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/securitymlanalyticssettings/method_delete_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/securitymlanalyticssettings/method_delete_autorest.go deleted file mode 100644 index a2b0d18f72f..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/securitymlanalyticssettings/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package securitymlanalyticssettings - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c SecurityMLAnalyticsSettingsClient) Delete(ctx context.Context, id SecurityMLAnalyticsSettingId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c SecurityMLAnalyticsSettingsClient) preparerForDelete(ctx context.Context, id SecurityMLAnalyticsSettingId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c SecurityMLAnalyticsSettingsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/securitymlanalyticssettings/method_get.go b/resource-manager/securityinsights/2022-10-01-preview/securitymlanalyticssettings/method_get.go new file mode 100644 index 00000000000..9be89fdf974 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/securitymlanalyticssettings/method_get.go @@ -0,0 +1,58 @@ +package securitymlanalyticssettings + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SecurityMLAnalyticsSetting +} + +// Get ... +func (c SecurityMLAnalyticsSettingsClient) Get(ctx context.Context, id SecurityMLAnalyticsSettingId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalSecurityMLAnalyticsSettingImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/securitymlanalyticssettings/method_get_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/securitymlanalyticssettings/method_get_autorest.go deleted file mode 100644 index 0157220a0eb..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/securitymlanalyticssettings/method_get_autorest.go +++ /dev/null @@ -1,77 +0,0 @@ -package securitymlanalyticssettings - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *SecurityMLAnalyticsSetting -} - -// Get ... -func (c SecurityMLAnalyticsSettingsClient) Get(ctx context.Context, id SecurityMLAnalyticsSettingId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c SecurityMLAnalyticsSettingsClient) preparerForGet(ctx context.Context, id SecurityMLAnalyticsSettingId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c SecurityMLAnalyticsSettingsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalSecurityMLAnalyticsSettingImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/securitymlanalyticssettings/method_list.go b/resource-manager/securityinsights/2022-10-01-preview/securitymlanalyticssettings/method_list.go new file mode 100644 index 00000000000..49878345af3 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/securitymlanalyticssettings/method_list.go @@ -0,0 +1,103 @@ +package securitymlanalyticssettings + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SecurityMLAnalyticsSetting +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []SecurityMLAnalyticsSetting +} + +// List ... +func (c SecurityMLAnalyticsSettingsClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/securityMLAnalyticsSettings", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]SecurityMLAnalyticsSetting, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalSecurityMLAnalyticsSettingImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for SecurityMLAnalyticsSetting (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// ListComplete retrieves all the results into a single object +func (c SecurityMLAnalyticsSettingsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, SecurityMLAnalyticsSettingOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SecurityMLAnalyticsSettingsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate SecurityMLAnalyticsSettingOperationPredicate) (result ListCompleteResult, err error) { + items := make([]SecurityMLAnalyticsSetting, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/securitymlanalyticssettings/method_list_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/securitymlanalyticssettings/method_list_autorest.go deleted file mode 100644 index 127297aa869..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/securitymlanalyticssettings/method_list_autorest.go +++ /dev/null @@ -1,196 +0,0 @@ -package securitymlanalyticssettings - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]SecurityMLAnalyticsSetting - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []SecurityMLAnalyticsSetting -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c SecurityMLAnalyticsSettingsClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c SecurityMLAnalyticsSettingsClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/securityMLAnalyticsSettings", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c SecurityMLAnalyticsSettingsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c SecurityMLAnalyticsSettingsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]SecurityMLAnalyticsSetting, 0) - for i, v := range respObj.Values { - val, err := unmarshalSecurityMLAnalyticsSettingImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for SecurityMLAnalyticsSetting (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c SecurityMLAnalyticsSettingsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, SecurityMLAnalyticsSettingOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c SecurityMLAnalyticsSettingsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate SecurityMLAnalyticsSettingOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]SecurityMLAnalyticsSetting, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/sentinelonboardingstates/client.go b/resource-manager/securityinsights/2022-10-01-preview/sentinelonboardingstates/client.go index 0ae442ba3fa..94701ed853a 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/sentinelonboardingstates/client.go +++ b/resource-manager/securityinsights/2022-10-01-preview/sentinelonboardingstates/client.go @@ -1,18 +1,26 @@ package sentinelonboardingstates -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type SentinelOnboardingStatesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewSentinelOnboardingStatesClientWithBaseURI(endpoint string) SentinelOnboardingStatesClient { - return SentinelOnboardingStatesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewSentinelOnboardingStatesClientWithBaseURI(sdkApi sdkEnv.Api) (*SentinelOnboardingStatesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sentinelonboardingstates", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SentinelOnboardingStatesClient: %+v", err) } + + return &SentinelOnboardingStatesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-10-01-preview/sentinelonboardingstates/method_create.go b/resource-manager/securityinsights/2022-10-01-preview/sentinelonboardingstates/method_create.go new file mode 100644 index 00000000000..af163a9d66b --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/sentinelonboardingstates/method_create.go @@ -0,0 +1,56 @@ +package sentinelonboardingstates + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SentinelOnboardingState +} + +// Create ... +func (c SentinelOnboardingStatesClient) Create(ctx context.Context, id OnboardingStateId, input SentinelOnboardingState) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/sentinelonboardingstates/method_create_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/sentinelonboardingstates/method_create_autorest.go deleted file mode 100644 index 9ad88e95157..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/sentinelonboardingstates/method_create_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package sentinelonboardingstates - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOperationResponse struct { - HttpResponse *http.Response - Model *SentinelOnboardingState -} - -// Create ... -func (c SentinelOnboardingStatesClient) Create(ctx context.Context, id OnboardingStateId, input SentinelOnboardingState) (result CreateOperationResponse, err error) { - req, err := c.preparerForCreate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Create", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Create", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Create", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreate prepares the Create request. -func (c SentinelOnboardingStatesClient) preparerForCreate(ctx context.Context, id OnboardingStateId, input SentinelOnboardingState) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreate handles the response to the Create request. The method always -// closes the http.Response Body. -func (c SentinelOnboardingStatesClient) responderForCreate(resp *http.Response) (result CreateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/sentinelonboardingstates/method_delete.go b/resource-manager/securityinsights/2022-10-01-preview/sentinelonboardingstates/method_delete.go new file mode 100644 index 00000000000..1c6c5e372d7 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/sentinelonboardingstates/method_delete.go @@ -0,0 +1,47 @@ +package sentinelonboardingstates + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c SentinelOnboardingStatesClient) Delete(ctx context.Context, id OnboardingStateId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/sentinelonboardingstates/method_delete_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/sentinelonboardingstates/method_delete_autorest.go deleted file mode 100644 index 65fa74282f7..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/sentinelonboardingstates/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package sentinelonboardingstates - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c SentinelOnboardingStatesClient) Delete(ctx context.Context, id OnboardingStateId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c SentinelOnboardingStatesClient) preparerForDelete(ctx context.Context, id OnboardingStateId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c SentinelOnboardingStatesClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/sentinelonboardingstates/method_get.go b/resource-manager/securityinsights/2022-10-01-preview/sentinelonboardingstates/method_get.go new file mode 100644 index 00000000000..82165662910 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/sentinelonboardingstates/method_get.go @@ -0,0 +1,51 @@ +package sentinelonboardingstates + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SentinelOnboardingState +} + +// Get ... +func (c SentinelOnboardingStatesClient) Get(ctx context.Context, id OnboardingStateId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/sentinelonboardingstates/method_get_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/sentinelonboardingstates/method_get_autorest.go deleted file mode 100644 index d6174a7522a..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/sentinelonboardingstates/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package sentinelonboardingstates - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *SentinelOnboardingState -} - -// Get ... -func (c SentinelOnboardingStatesClient) Get(ctx context.Context, id OnboardingStateId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c SentinelOnboardingStatesClient) preparerForGet(ctx context.Context, id OnboardingStateId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c SentinelOnboardingStatesClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/sentinelonboardingstates/method_list.go b/resource-manager/securityinsights/2022-10-01-preview/sentinelonboardingstates/method_list.go new file mode 100644 index 00000000000..2efd1d41230 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/sentinelonboardingstates/method_list.go @@ -0,0 +1,52 @@ +package sentinelonboardingstates + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SentinelOnboardingStatesList +} + +// List ... +func (c SentinelOnboardingStatesClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/onboardingStates", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/sentinelonboardingstates/method_list_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/sentinelonboardingstates/method_list_autorest.go deleted file mode 100644 index 6a00bb3d3fd..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/sentinelonboardingstates/method_list_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package sentinelonboardingstates - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *SentinelOnboardingStatesList -} - -// List ... -func (c SentinelOnboardingStatesClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForList prepares the List request. -func (c SentinelOnboardingStatesClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/onboardingStates", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c SentinelOnboardingStatesClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/settings/client.go b/resource-manager/securityinsights/2022-10-01-preview/settings/client.go index fe7a909262c..7a9bd9ec8a1 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/settings/client.go +++ b/resource-manager/securityinsights/2022-10-01-preview/settings/client.go @@ -1,18 +1,26 @@ package settings -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type SettingsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewSettingsClientWithBaseURI(endpoint string) SettingsClient { - return SettingsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewSettingsClientWithBaseURI(sdkApi sdkEnv.Api) (*SettingsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "settings", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SettingsClient: %+v", err) } + + return &SettingsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-10-01-preview/settings/constants.go b/resource-manager/securityinsights/2022-10-01-preview/settings/constants.go index c3028cb8436..22f9ec6323d 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/settings/constants.go +++ b/resource-manager/securityinsights/2022-10-01-preview/settings/constants.go @@ -1,6 +1,10 @@ package settings -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -19,6 +23,19 @@ func PossibleValuesForEntityProviders() []string { } } +func (s *EntityProviders) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityProviders(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityProviders(input string) (*EntityProviders, error) { vals := map[string]EntityProviders{ "activedirectory": EntityProvidersActiveDirectory, @@ -51,6 +68,19 @@ func PossibleValuesForSettingKind() []string { } } +func (s *SettingKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSettingKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSettingKind(input string) (*SettingKind, error) { vals := map[string]SettingKind{ "anomalies": SettingKindAnomalies, @@ -85,6 +115,19 @@ func PossibleValuesForUebaDataSources() []string { } } +func (s *UebaDataSources) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseUebaDataSources(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseUebaDataSources(input string) (*UebaDataSources, error) { vals := map[string]UebaDataSources{ "auditlogs": UebaDataSourcesAuditLogs, diff --git a/resource-manager/securityinsights/2022-10-01-preview/settings/method_productsettingsdelete.go b/resource-manager/securityinsights/2022-10-01-preview/settings/method_productsettingsdelete.go new file mode 100644 index 00000000000..3306b03a761 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/settings/method_productsettingsdelete.go @@ -0,0 +1,47 @@ +package settings + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProductSettingsDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// ProductSettingsDelete ... +func (c SettingsClient) ProductSettingsDelete(ctx context.Context, id SettingId) (result ProductSettingsDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/settings/method_productsettingsdelete_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/settings/method_productsettingsdelete_autorest.go deleted file mode 100644 index 820be252b48..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/settings/method_productsettingsdelete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package settings - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ProductSettingsDeleteOperationResponse struct { - HttpResponse *http.Response -} - -// ProductSettingsDelete ... -func (c SettingsClient) ProductSettingsDelete(ctx context.Context, id SettingId) (result ProductSettingsDeleteOperationResponse, err error) { - req, err := c.preparerForProductSettingsDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "settings.SettingsClient", "ProductSettingsDelete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "settings.SettingsClient", "ProductSettingsDelete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForProductSettingsDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "settings.SettingsClient", "ProductSettingsDelete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForProductSettingsDelete prepares the ProductSettingsDelete request. -func (c SettingsClient) preparerForProductSettingsDelete(ctx context.Context, id SettingId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForProductSettingsDelete handles the response to the ProductSettingsDelete request. The method always -// closes the http.Response Body. -func (c SettingsClient) responderForProductSettingsDelete(resp *http.Response) (result ProductSettingsDeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/settings/method_productsettingsget.go b/resource-manager/securityinsights/2022-10-01-preview/settings/method_productsettingsget.go new file mode 100644 index 00000000000..3d546bae766 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/settings/method_productsettingsget.go @@ -0,0 +1,58 @@ +package settings + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProductSettingsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Settings +} + +// ProductSettingsGet ... +func (c SettingsClient) ProductSettingsGet(ctx context.Context, id SettingId) (result ProductSettingsGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalSettingsImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/settings/method_productsettingsget_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/settings/method_productsettingsget_autorest.go deleted file mode 100644 index bcaeab3e1a3..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/settings/method_productsettingsget_autorest.go +++ /dev/null @@ -1,77 +0,0 @@ -package settings - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ProductSettingsGetOperationResponse struct { - HttpResponse *http.Response - Model *Settings -} - -// ProductSettingsGet ... -func (c SettingsClient) ProductSettingsGet(ctx context.Context, id SettingId) (result ProductSettingsGetOperationResponse, err error) { - req, err := c.preparerForProductSettingsGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "settings.SettingsClient", "ProductSettingsGet", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "settings.SettingsClient", "ProductSettingsGet", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForProductSettingsGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "settings.SettingsClient", "ProductSettingsGet", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForProductSettingsGet prepares the ProductSettingsGet request. -func (c SettingsClient) preparerForProductSettingsGet(ctx context.Context, id SettingId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForProductSettingsGet handles the response to the ProductSettingsGet request. The method always -// closes the http.Response Body. -func (c SettingsClient) responderForProductSettingsGet(resp *http.Response) (result ProductSettingsGetOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalSettingsImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/settings/method_productsettingslist.go b/resource-manager/securityinsights/2022-10-01-preview/settings/method_productsettingslist.go new file mode 100644 index 00000000000..55114738bc5 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/settings/method_productsettingslist.go @@ -0,0 +1,52 @@ +package settings + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProductSettingsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SettingList +} + +// ProductSettingsList ... +func (c SettingsClient) ProductSettingsList(ctx context.Context, id WorkspaceId) (result ProductSettingsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/settings", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/settings/method_productsettingslist_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/settings/method_productsettingslist_autorest.go deleted file mode 100644 index 1242ef0a94b..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/settings/method_productsettingslist_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package settings - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ProductSettingsListOperationResponse struct { - HttpResponse *http.Response - Model *SettingList -} - -// ProductSettingsList ... -func (c SettingsClient) ProductSettingsList(ctx context.Context, id WorkspaceId) (result ProductSettingsListOperationResponse, err error) { - req, err := c.preparerForProductSettingsList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "settings.SettingsClient", "ProductSettingsList", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "settings.SettingsClient", "ProductSettingsList", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForProductSettingsList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "settings.SettingsClient", "ProductSettingsList", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForProductSettingsList prepares the ProductSettingsList request. -func (c SettingsClient) preparerForProductSettingsList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/settings", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForProductSettingsList handles the response to the ProductSettingsList request. The method always -// closes the http.Response Body. -func (c SettingsClient) responderForProductSettingsList(resp *http.Response) (result ProductSettingsListOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/settings/method_productsettingsupdate.go b/resource-manager/securityinsights/2022-10-01-preview/settings/method_productsettingsupdate.go new file mode 100644 index 00000000000..1f33013bb47 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/settings/method_productsettingsupdate.go @@ -0,0 +1,62 @@ +package settings + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProductSettingsUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Settings +} + +// ProductSettingsUpdate ... +func (c SettingsClient) ProductSettingsUpdate(ctx context.Context, id SettingId, input Settings) (result ProductSettingsUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalSettingsImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/settings/method_productsettingsupdate_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/settings/method_productsettingsupdate_autorest.go deleted file mode 100644 index 1b7573688b3..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/settings/method_productsettingsupdate_autorest.go +++ /dev/null @@ -1,78 +0,0 @@ -package settings - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ProductSettingsUpdateOperationResponse struct { - HttpResponse *http.Response - Model *Settings -} - -// ProductSettingsUpdate ... -func (c SettingsClient) ProductSettingsUpdate(ctx context.Context, id SettingId, input Settings) (result ProductSettingsUpdateOperationResponse, err error) { - req, err := c.preparerForProductSettingsUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "settings.SettingsClient", "ProductSettingsUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "settings.SettingsClient", "ProductSettingsUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForProductSettingsUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "settings.SettingsClient", "ProductSettingsUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForProductSettingsUpdate prepares the ProductSettingsUpdate request. -func (c SettingsClient) preparerForProductSettingsUpdate(ctx context.Context, id SettingId, input Settings) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForProductSettingsUpdate handles the response to the ProductSettingsUpdate request. The method always -// closes the http.Response Body. -func (c SettingsClient) responderForProductSettingsUpdate(resp *http.Response) (result ProductSettingsUpdateOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalSettingsImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/sourcecontrols/client.go b/resource-manager/securityinsights/2022-10-01-preview/sourcecontrols/client.go index c0d5d5424c2..9bfd651a63a 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/sourcecontrols/client.go +++ b/resource-manager/securityinsights/2022-10-01-preview/sourcecontrols/client.go @@ -1,18 +1,26 @@ package sourcecontrols -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type SourceControlsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewSourceControlsClientWithBaseURI(endpoint string) SourceControlsClient { - return SourceControlsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewSourceControlsClientWithBaseURI(sdkApi sdkEnv.Api) (*SourceControlsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sourcecontrols", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SourceControlsClient: %+v", err) } + + return &SourceControlsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-10-01-preview/sourcecontrols/constants.go b/resource-manager/securityinsights/2022-10-01-preview/sourcecontrols/constants.go index 7b6518175f0..d134677e70c 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/sourcecontrols/constants.go +++ b/resource-manager/securityinsights/2022-10-01-preview/sourcecontrols/constants.go @@ -1,6 +1,10 @@ package sourcecontrols -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -19,6 +23,19 @@ func PossibleValuesForContentType() []string { } } +func (s *ContentType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseContentType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseContentType(input string) (*ContentType, error) { vals := map[string]ContentType{ "analyticrule": ContentTypeAnalyticRule, @@ -49,6 +66,19 @@ func PossibleValuesForDeploymentFetchStatus() []string { } } +func (s *DeploymentFetchStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeploymentFetchStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDeploymentFetchStatus(input string) (*DeploymentFetchStatus, error) { vals := map[string]DeploymentFetchStatus{ "notfound": DeploymentFetchStatusNotFound, @@ -80,6 +110,19 @@ func PossibleValuesForDeploymentResult() []string { } } +func (s *DeploymentResult) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeploymentResult(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDeploymentResult(input string) (*DeploymentResult, error) { vals := map[string]DeploymentResult{ "canceled": DeploymentResultCanceled, @@ -113,6 +156,19 @@ func PossibleValuesForDeploymentState() []string { } } +func (s *DeploymentState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeploymentState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDeploymentState(input string) (*DeploymentState, error) { vals := map[string]DeploymentState{ "canceling": DeploymentStateCanceling, @@ -143,6 +199,19 @@ func PossibleValuesForRepoType() []string { } } +func (s *RepoType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRepoType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseRepoType(input string) (*RepoType, error) { vals := map[string]RepoType{ "devops": RepoTypeDevOps, @@ -171,6 +240,19 @@ func PossibleValuesForVersion() []string { } } +func (s *Version) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVersion(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseVersion(input string) (*Version, error) { vals := map[string]Version{ "v1": VersionVOne, diff --git a/resource-manager/securityinsights/2022-10-01-preview/sourcecontrols/method_create.go b/resource-manager/securityinsights/2022-10-01-preview/sourcecontrols/method_create.go new file mode 100644 index 00000000000..ee70a7cb64f --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/sourcecontrols/method_create.go @@ -0,0 +1,56 @@ +package sourcecontrols + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SourceControl +} + +// Create ... +func (c SourceControlsClient) Create(ctx context.Context, id SourceControlId, input SourceControl) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/sourcecontrols/method_create_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/sourcecontrols/method_create_autorest.go deleted file mode 100644 index fbf91a3cc21..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/sourcecontrols/method_create_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package sourcecontrols - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOperationResponse struct { - HttpResponse *http.Response - Model *SourceControl -} - -// Create ... -func (c SourceControlsClient) Create(ctx context.Context, id SourceControlId, input SourceControl) (result CreateOperationResponse, err error) { - req, err := c.preparerForCreate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "Create", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "Create", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "Create", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreate prepares the Create request. -func (c SourceControlsClient) preparerForCreate(ctx context.Context, id SourceControlId, input SourceControl) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreate handles the response to the Create request. The method always -// closes the http.Response Body. -func (c SourceControlsClient) responderForCreate(resp *http.Response) (result CreateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/sourcecontrols/method_delete.go b/resource-manager/securityinsights/2022-10-01-preview/sourcecontrols/method_delete.go new file mode 100644 index 00000000000..579d919b3df --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/sourcecontrols/method_delete.go @@ -0,0 +1,47 @@ +package sourcecontrols + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c SourceControlsClient) Delete(ctx context.Context, id SourceControlId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/sourcecontrols/method_delete_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/sourcecontrols/method_delete_autorest.go deleted file mode 100644 index 44699d5360d..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/sourcecontrols/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package sourcecontrols - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c SourceControlsClient) Delete(ctx context.Context, id SourceControlId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c SourceControlsClient) preparerForDelete(ctx context.Context, id SourceControlId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c SourceControlsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/sourcecontrols/method_get.go b/resource-manager/securityinsights/2022-10-01-preview/sourcecontrols/method_get.go new file mode 100644 index 00000000000..3a1cb1bf276 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/sourcecontrols/method_get.go @@ -0,0 +1,51 @@ +package sourcecontrols + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SourceControl +} + +// Get ... +func (c SourceControlsClient) Get(ctx context.Context, id SourceControlId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/sourcecontrols/method_get_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/sourcecontrols/method_get_autorest.go deleted file mode 100644 index 80b8d99a662..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/sourcecontrols/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package sourcecontrols - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *SourceControl -} - -// Get ... -func (c SourceControlsClient) Get(ctx context.Context, id SourceControlId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c SourceControlsClient) preparerForGet(ctx context.Context, id SourceControlId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c SourceControlsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/sourcecontrols/method_list.go b/resource-manager/securityinsights/2022-10-01-preview/sourcecontrols/method_list.go new file mode 100644 index 00000000000..f058d0ec61e --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/sourcecontrols/method_list.go @@ -0,0 +1,91 @@ +package sourcecontrols + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SourceControl +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []SourceControl +} + +// List ... +func (c SourceControlsClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/sourceControls", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]SourceControl `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c SourceControlsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, SourceControlOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SourceControlsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate SourceControlOperationPredicate) (result ListCompleteResult, err error) { + items := make([]SourceControl, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/sourcecontrols/method_list_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/sourcecontrols/method_list_autorest.go deleted file mode 100644 index 04f2a205623..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/sourcecontrols/method_list_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package sourcecontrols - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]SourceControl - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []SourceControl -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c SourceControlsClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c SourceControlsClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/sourceControls", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c SourceControlsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c SourceControlsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []SourceControl `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c SourceControlsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, SourceControlOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c SourceControlsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate SourceControlOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]SourceControl, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/client.go b/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/client.go index 35caff31357..edf96c3143f 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/client.go +++ b/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/client.go @@ -1,18 +1,26 @@ package threatintelligence -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type ThreatIntelligenceClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewThreatIntelligenceClientWithBaseURI(endpoint string) ThreatIntelligenceClient { - return ThreatIntelligenceClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewThreatIntelligenceClientWithBaseURI(sdkApi sdkEnv.Api) (*ThreatIntelligenceClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "threatintelligence", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ThreatIntelligenceClient: %+v", err) } + + return &ThreatIntelligenceClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/constants.go b/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/constants.go index 3549cbffe94..3047e7d6d68 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/constants.go +++ b/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/constants.go @@ -1,6 +1,10 @@ package threatintelligence -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -17,6 +21,19 @@ func PossibleValuesForThreatIntelligenceResourceKindEnum() []string { } } +func (s *ThreatIntelligenceResourceKindEnum) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseThreatIntelligenceResourceKindEnum(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseThreatIntelligenceResourceKindEnum(input string) (*ThreatIntelligenceResourceKindEnum, error) { vals := map[string]ThreatIntelligenceResourceKindEnum{ "indicator": ThreatIntelligenceResourceKindEnumIndicator, @@ -46,6 +63,19 @@ func PossibleValuesForThreatIntelligenceSortingCriteriaEnum() []string { } } +func (s *ThreatIntelligenceSortingCriteriaEnum) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseThreatIntelligenceSortingCriteriaEnum(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseThreatIntelligenceSortingCriteriaEnum(input string) (*ThreatIntelligenceSortingCriteriaEnum, error) { vals := map[string]ThreatIntelligenceSortingCriteriaEnum{ "ascending": ThreatIntelligenceSortingCriteriaEnumAscending, diff --git a/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatorappendtags.go b/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatorappendtags.go new file mode 100644 index 00000000000..4384327485d --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatorappendtags.go @@ -0,0 +1,51 @@ +package threatintelligence + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorAppendTagsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// IndicatorAppendTags ... +func (c ThreatIntelligenceClient) IndicatorAppendTags(ctx context.Context, id IndicatorId, input ThreatIntelligenceAppendTags) (result IndicatorAppendTagsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/appendTags", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatorappendtags_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatorappendtags_autorest.go deleted file mode 100644 index 18b86a166fe..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatorappendtags_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package threatintelligence - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorAppendTagsOperationResponse struct { - HttpResponse *http.Response -} - -// IndicatorAppendTags ... -func (c ThreatIntelligenceClient) IndicatorAppendTags(ctx context.Context, id IndicatorId, input ThreatIntelligenceAppendTags) (result IndicatorAppendTagsOperationResponse, err error) { - req, err := c.preparerForIndicatorAppendTags(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorAppendTags", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorAppendTags", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorAppendTags(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorAppendTags", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorAppendTags prepares the IndicatorAppendTags request. -func (c ThreatIntelligenceClient) preparerForIndicatorAppendTags(ctx context.Context, id IndicatorId, input ThreatIntelligenceAppendTags) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/appendTags", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorAppendTags handles the response to the IndicatorAppendTags request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorAppendTags(resp *http.Response) (result IndicatorAppendTagsOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatorcreate.go b/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatorcreate.go new file mode 100644 index 00000000000..3cee598931c --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatorcreate.go @@ -0,0 +1,63 @@ +package threatintelligence + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorCreateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ThreatIntelligenceInformation +} + +// IndicatorCreate ... +func (c ThreatIntelligenceClient) IndicatorCreate(ctx context.Context, id IndicatorId, input ThreatIntelligenceIndicatorModel) (result IndicatorCreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatorcreate_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatorcreate_autorest.go deleted file mode 100644 index 98609062b7f..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatorcreate_autorest.go +++ /dev/null @@ -1,78 +0,0 @@ -package threatintelligence - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorCreateOperationResponse struct { - HttpResponse *http.Response - Model *ThreatIntelligenceInformation -} - -// IndicatorCreate ... -func (c ThreatIntelligenceClient) IndicatorCreate(ctx context.Context, id IndicatorId, input ThreatIntelligenceIndicatorModel) (result IndicatorCreateOperationResponse, err error) { - req, err := c.preparerForIndicatorCreate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorCreate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorCreate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorCreate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorCreate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorCreate prepares the IndicatorCreate request. -func (c ThreatIntelligenceClient) preparerForIndicatorCreate(ctx context.Context, id IndicatorId, input ThreatIntelligenceIndicatorModel) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorCreate handles the response to the IndicatorCreate request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorCreate(resp *http.Response) (result IndicatorCreateOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatorcreateindicator.go b/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatorcreateindicator.go new file mode 100644 index 00000000000..0f3ab94c4f5 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatorcreateindicator.go @@ -0,0 +1,63 @@ +package threatintelligence + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorCreateIndicatorOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ThreatIntelligenceInformation +} + +// IndicatorCreateIndicator ... +func (c ThreatIntelligenceClient) IndicatorCreateIndicator(ctx context.Context, id WorkspaceId, input ThreatIntelligenceIndicatorModel) (result IndicatorCreateIndicatorOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/createIndicator", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatorcreateindicator_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatorcreateindicator_autorest.go deleted file mode 100644 index ecc76b88f5c..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatorcreateindicator_autorest.go +++ /dev/null @@ -1,79 +0,0 @@ -package threatintelligence - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorCreateIndicatorOperationResponse struct { - HttpResponse *http.Response - Model *ThreatIntelligenceInformation -} - -// IndicatorCreateIndicator ... -func (c ThreatIntelligenceClient) IndicatorCreateIndicator(ctx context.Context, id WorkspaceId, input ThreatIntelligenceIndicatorModel) (result IndicatorCreateIndicatorOperationResponse, err error) { - req, err := c.preparerForIndicatorCreateIndicator(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorCreateIndicator", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorCreateIndicator", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorCreateIndicator(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorCreateIndicator", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorCreateIndicator prepares the IndicatorCreateIndicator request. -func (c ThreatIntelligenceClient) preparerForIndicatorCreateIndicator(ctx context.Context, id WorkspaceId, input ThreatIntelligenceIndicatorModel) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/createIndicator", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorCreateIndicator handles the response to the IndicatorCreateIndicator request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorCreateIndicator(resp *http.Response) (result IndicatorCreateIndicatorOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatordelete.go b/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatordelete.go new file mode 100644 index 00000000000..4de264524d5 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatordelete.go @@ -0,0 +1,47 @@ +package threatintelligence + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// IndicatorDelete ... +func (c ThreatIntelligenceClient) IndicatorDelete(ctx context.Context, id IndicatorId) (result IndicatorDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatordelete_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatordelete_autorest.go deleted file mode 100644 index 825d3b911ce..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatordelete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package threatintelligence - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorDeleteOperationResponse struct { - HttpResponse *http.Response -} - -// IndicatorDelete ... -func (c ThreatIntelligenceClient) IndicatorDelete(ctx context.Context, id IndicatorId) (result IndicatorDeleteOperationResponse, err error) { - req, err := c.preparerForIndicatorDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorDelete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorDelete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorDelete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorDelete prepares the IndicatorDelete request. -func (c ThreatIntelligenceClient) preparerForIndicatorDelete(ctx context.Context, id IndicatorId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorDelete handles the response to the IndicatorDelete request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorDelete(resp *http.Response) (result IndicatorDeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatorget.go b/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatorget.go new file mode 100644 index 00000000000..3358363f139 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatorget.go @@ -0,0 +1,58 @@ +package threatintelligence + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ThreatIntelligenceInformation +} + +// IndicatorGet ... +func (c ThreatIntelligenceClient) IndicatorGet(ctx context.Context, id IndicatorId) (result IndicatorGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatorget_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatorget_autorest.go deleted file mode 100644 index ac1187fb285..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatorget_autorest.go +++ /dev/null @@ -1,77 +0,0 @@ -package threatintelligence - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorGetOperationResponse struct { - HttpResponse *http.Response - Model *ThreatIntelligenceInformation -} - -// IndicatorGet ... -func (c ThreatIntelligenceClient) IndicatorGet(ctx context.Context, id IndicatorId) (result IndicatorGetOperationResponse, err error) { - req, err := c.preparerForIndicatorGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorGet", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorGet", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorGet", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorGet prepares the IndicatorGet request. -func (c ThreatIntelligenceClient) preparerForIndicatorGet(ctx context.Context, id IndicatorId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorGet handles the response to the IndicatorGet request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorGet(resp *http.Response) (result IndicatorGetOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatormetricslist.go b/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatormetricslist.go new file mode 100644 index 00000000000..688ff3c16d1 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatormetricslist.go @@ -0,0 +1,52 @@ +package threatintelligence + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorMetricsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ThreatIntelligenceMetricsList +} + +// IndicatorMetricsList ... +func (c ThreatIntelligenceClient) IndicatorMetricsList(ctx context.Context, id WorkspaceId) (result IndicatorMetricsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/metrics", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatormetricslist_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatormetricslist_autorest.go deleted file mode 100644 index 1835c26ed96..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatormetricslist_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package threatintelligence - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorMetricsListOperationResponse struct { - HttpResponse *http.Response - Model *ThreatIntelligenceMetricsList -} - -// IndicatorMetricsList ... -func (c ThreatIntelligenceClient) IndicatorMetricsList(ctx context.Context, id WorkspaceId) (result IndicatorMetricsListOperationResponse, err error) { - req, err := c.preparerForIndicatorMetricsList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorMetricsList", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorMetricsList", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorMetricsList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorMetricsList", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorMetricsList prepares the IndicatorMetricsList request. -func (c ThreatIntelligenceClient) preparerForIndicatorMetricsList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/metrics", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorMetricsList handles the response to the IndicatorMetricsList request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorMetricsList(resp *http.Response) (result IndicatorMetricsListOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatorqueryindicators.go b/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatorqueryindicators.go new file mode 100644 index 00000000000..8ce639f2623 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatorqueryindicators.go @@ -0,0 +1,103 @@ +package threatintelligence + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorQueryIndicatorsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ThreatIntelligenceInformation +} + +type IndicatorQueryIndicatorsCompleteResult struct { + LatestHttpResponse *http.Response + Items []ThreatIntelligenceInformation +} + +// IndicatorQueryIndicators ... +func (c ThreatIntelligenceClient) IndicatorQueryIndicators(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria) (result IndicatorQueryIndicatorsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/queryIndicators", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]ThreatIntelligenceInformation, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalThreatIntelligenceInformationImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for ThreatIntelligenceInformation (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// IndicatorQueryIndicatorsComplete retrieves all the results into a single object +func (c ThreatIntelligenceClient) IndicatorQueryIndicatorsComplete(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria) (IndicatorQueryIndicatorsCompleteResult, error) { + return c.IndicatorQueryIndicatorsCompleteMatchingPredicate(ctx, id, input, ThreatIntelligenceInformationOperationPredicate{}) +} + +// IndicatorQueryIndicatorsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ThreatIntelligenceClient) IndicatorQueryIndicatorsCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria, predicate ThreatIntelligenceInformationOperationPredicate) (result IndicatorQueryIndicatorsCompleteResult, err error) { + items := make([]ThreatIntelligenceInformation, 0) + + resp, err := c.IndicatorQueryIndicators(ctx, id, input) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = IndicatorQueryIndicatorsCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatorqueryindicators_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatorqueryindicators_autorest.go deleted file mode 100644 index fcbe7c74758..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatorqueryindicators_autorest.go +++ /dev/null @@ -1,197 +0,0 @@ -package threatintelligence - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorQueryIndicatorsOperationResponse struct { - HttpResponse *http.Response - Model *[]ThreatIntelligenceInformation - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (IndicatorQueryIndicatorsOperationResponse, error) -} - -type IndicatorQueryIndicatorsCompleteResult struct { - Items []ThreatIntelligenceInformation -} - -func (r IndicatorQueryIndicatorsOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r IndicatorQueryIndicatorsOperationResponse) LoadMore(ctx context.Context) (resp IndicatorQueryIndicatorsOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// IndicatorQueryIndicators ... -func (c ThreatIntelligenceClient) IndicatorQueryIndicators(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria) (resp IndicatorQueryIndicatorsOperationResponse, err error) { - req, err := c.preparerForIndicatorQueryIndicators(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorQueryIndicators", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorQueryIndicators", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForIndicatorQueryIndicators(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorQueryIndicators", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForIndicatorQueryIndicators prepares the IndicatorQueryIndicators request. -func (c ThreatIntelligenceClient) preparerForIndicatorQueryIndicators(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/queryIndicators", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForIndicatorQueryIndicatorsWithNextLink prepares the IndicatorQueryIndicators request with the given nextLink token. -func (c ThreatIntelligenceClient) preparerForIndicatorQueryIndicatorsWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorQueryIndicators handles the response to the IndicatorQueryIndicators request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorQueryIndicators(resp *http.Response) (result IndicatorQueryIndicatorsOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]ThreatIntelligenceInformation, 0) - for i, v := range respObj.Values { - val, err := unmarshalThreatIntelligenceInformationImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for ThreatIntelligenceInformation (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result IndicatorQueryIndicatorsOperationResponse, err error) { - req, err := c.preparerForIndicatorQueryIndicatorsWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorQueryIndicators", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorQueryIndicators", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorQueryIndicators(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorQueryIndicators", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// IndicatorQueryIndicatorsComplete retrieves all of the results into a single object -func (c ThreatIntelligenceClient) IndicatorQueryIndicatorsComplete(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria) (IndicatorQueryIndicatorsCompleteResult, error) { - return c.IndicatorQueryIndicatorsCompleteMatchingPredicate(ctx, id, input, ThreatIntelligenceInformationOperationPredicate{}) -} - -// IndicatorQueryIndicatorsCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c ThreatIntelligenceClient) IndicatorQueryIndicatorsCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria, predicate ThreatIntelligenceInformationOperationPredicate) (resp IndicatorQueryIndicatorsCompleteResult, err error) { - items := make([]ThreatIntelligenceInformation, 0) - - page, err := c.IndicatorQueryIndicators(ctx, id, input) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := IndicatorQueryIndicatorsCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatorreplacetags.go b/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatorreplacetags.go new file mode 100644 index 00000000000..052bbe7b66a --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatorreplacetags.go @@ -0,0 +1,63 @@ +package threatintelligence + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorReplaceTagsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ThreatIntelligenceInformation +} + +// IndicatorReplaceTags ... +func (c ThreatIntelligenceClient) IndicatorReplaceTags(ctx context.Context, id IndicatorId, input ThreatIntelligenceIndicatorModel) (result IndicatorReplaceTagsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/replaceTags", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatorreplacetags_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatorreplacetags_autorest.go deleted file mode 100644 index 01efbe5b778..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatorreplacetags_autorest.go +++ /dev/null @@ -1,79 +0,0 @@ -package threatintelligence - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorReplaceTagsOperationResponse struct { - HttpResponse *http.Response - Model *ThreatIntelligenceInformation -} - -// IndicatorReplaceTags ... -func (c ThreatIntelligenceClient) IndicatorReplaceTags(ctx context.Context, id IndicatorId, input ThreatIntelligenceIndicatorModel) (result IndicatorReplaceTagsOperationResponse, err error) { - req, err := c.preparerForIndicatorReplaceTags(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorReplaceTags", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorReplaceTags", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorReplaceTags(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorReplaceTags", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorReplaceTags prepares the IndicatorReplaceTags request. -func (c ThreatIntelligenceClient) preparerForIndicatorReplaceTags(ctx context.Context, id IndicatorId, input ThreatIntelligenceIndicatorModel) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/replaceTags", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorReplaceTags handles the response to the IndicatorReplaceTags request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorReplaceTags(resp *http.Response) (result IndicatorReplaceTagsOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatorslist.go b/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatorslist.go new file mode 100644 index 00000000000..860ecd26255 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatorslist.go @@ -0,0 +1,139 @@ +package threatintelligence + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ThreatIntelligenceInformation +} + +type IndicatorsListCompleteResult struct { + LatestHttpResponse *http.Response + Items []ThreatIntelligenceInformation +} + +type IndicatorsListOperationOptions struct { + Filter *string + Orderby *string + Top *int64 +} + +func DefaultIndicatorsListOperationOptions() IndicatorsListOperationOptions { + return IndicatorsListOperationOptions{} +} + +func (o IndicatorsListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o IndicatorsListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o IndicatorsListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// IndicatorsList ... +func (c ThreatIntelligenceClient) IndicatorsList(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions) (result IndicatorsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/indicators", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]ThreatIntelligenceInformation, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalThreatIntelligenceInformationImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for ThreatIntelligenceInformation (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// IndicatorsListComplete retrieves all the results into a single object +func (c ThreatIntelligenceClient) IndicatorsListComplete(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions) (IndicatorsListCompleteResult, error) { + return c.IndicatorsListCompleteMatchingPredicate(ctx, id, options, ThreatIntelligenceInformationOperationPredicate{}) +} + +// IndicatorsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ThreatIntelligenceClient) IndicatorsListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions, predicate ThreatIntelligenceInformationOperationPredicate) (result IndicatorsListCompleteResult, err error) { + items := make([]ThreatIntelligenceInformation, 0) + + resp, err := c.IndicatorsList(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = IndicatorsListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatorslist_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatorslist_autorest.go deleted file mode 100644 index 22ef9d7b193..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/threatintelligence/method_indicatorslist_autorest.go +++ /dev/null @@ -1,235 +0,0 @@ -package threatintelligence - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorsListOperationResponse struct { - HttpResponse *http.Response - Model *[]ThreatIntelligenceInformation - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (IndicatorsListOperationResponse, error) -} - -type IndicatorsListCompleteResult struct { - Items []ThreatIntelligenceInformation -} - -func (r IndicatorsListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r IndicatorsListOperationResponse) LoadMore(ctx context.Context) (resp IndicatorsListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type IndicatorsListOperationOptions struct { - Filter *string - Orderby *string - Top *int64 -} - -func DefaultIndicatorsListOperationOptions() IndicatorsListOperationOptions { - return IndicatorsListOperationOptions{} -} - -func (o IndicatorsListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o IndicatorsListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Filter != nil { - out["$filter"] = *o.Filter - } - - if o.Orderby != nil { - out["$orderby"] = *o.Orderby - } - - if o.Top != nil { - out["$top"] = *o.Top - } - - return out -} - -// IndicatorsList ... -func (c ThreatIntelligenceClient) IndicatorsList(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions) (resp IndicatorsListOperationResponse, err error) { - req, err := c.preparerForIndicatorsList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForIndicatorsList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForIndicatorsList prepares the IndicatorsList request. -func (c ThreatIntelligenceClient) preparerForIndicatorsList(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/indicators", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForIndicatorsListWithNextLink prepares the IndicatorsList request with the given nextLink token. -func (c ThreatIntelligenceClient) preparerForIndicatorsListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorsList handles the response to the IndicatorsList request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorsList(resp *http.Response) (result IndicatorsListOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]ThreatIntelligenceInformation, 0) - for i, v := range respObj.Values { - val, err := unmarshalThreatIntelligenceInformationImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for ThreatIntelligenceInformation (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result IndicatorsListOperationResponse, err error) { - req, err := c.preparerForIndicatorsListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorsList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// IndicatorsListComplete retrieves all of the results into a single object -func (c ThreatIntelligenceClient) IndicatorsListComplete(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions) (IndicatorsListCompleteResult, error) { - return c.IndicatorsListCompleteMatchingPredicate(ctx, id, options, ThreatIntelligenceInformationOperationPredicate{}) -} - -// IndicatorsListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c ThreatIntelligenceClient) IndicatorsListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions, predicate ThreatIntelligenceInformationOperationPredicate) (resp IndicatorsListCompleteResult, err error) { - items := make([]ThreatIntelligenceInformation, 0) - - page, err := c.IndicatorsList(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := IndicatorsListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/watchlistitems/client.go b/resource-manager/securityinsights/2022-10-01-preview/watchlistitems/client.go index 9403755456e..d3193694a48 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/watchlistitems/client.go +++ b/resource-manager/securityinsights/2022-10-01-preview/watchlistitems/client.go @@ -1,18 +1,26 @@ package watchlistitems -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type WatchlistItemsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewWatchlistItemsClientWithBaseURI(endpoint string) WatchlistItemsClient { - return WatchlistItemsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewWatchlistItemsClientWithBaseURI(sdkApi sdkEnv.Api) (*WatchlistItemsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "watchlistitems", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating WatchlistItemsClient: %+v", err) } + + return &WatchlistItemsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-10-01-preview/watchlistitems/method_createorupdate.go b/resource-manager/securityinsights/2022-10-01-preview/watchlistitems/method_createorupdate.go new file mode 100644 index 00000000000..d02782f71bc --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/watchlistitems/method_createorupdate.go @@ -0,0 +1,56 @@ +package watchlistitems + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *WatchlistItem +} + +// CreateOrUpdate ... +func (c WatchlistItemsClient) CreateOrUpdate(ctx context.Context, id WatchlistItemId, input WatchlistItem) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/watchlistitems/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/watchlistitems/method_createorupdate_autorest.go deleted file mode 100644 index 15d8fdcc2be..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/watchlistitems/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package watchlistitems - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *WatchlistItem -} - -// CreateOrUpdate ... -func (c WatchlistItemsClient) CreateOrUpdate(ctx context.Context, id WatchlistItemId, input WatchlistItem) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c WatchlistItemsClient) preparerForCreateOrUpdate(ctx context.Context, id WatchlistItemId, input WatchlistItem) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c WatchlistItemsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/watchlistitems/method_delete.go b/resource-manager/securityinsights/2022-10-01-preview/watchlistitems/method_delete.go new file mode 100644 index 00000000000..5565b767fa5 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/watchlistitems/method_delete.go @@ -0,0 +1,47 @@ +package watchlistitems + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c WatchlistItemsClient) Delete(ctx context.Context, id WatchlistItemId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/watchlistitems/method_delete_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/watchlistitems/method_delete_autorest.go deleted file mode 100644 index c9b8c46f9e5..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/watchlistitems/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package watchlistitems - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c WatchlistItemsClient) Delete(ctx context.Context, id WatchlistItemId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c WatchlistItemsClient) preparerForDelete(ctx context.Context, id WatchlistItemId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c WatchlistItemsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/watchlistitems/method_get.go b/resource-manager/securityinsights/2022-10-01-preview/watchlistitems/method_get.go new file mode 100644 index 00000000000..ff9a8e143fa --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/watchlistitems/method_get.go @@ -0,0 +1,51 @@ +package watchlistitems + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *WatchlistItem +} + +// Get ... +func (c WatchlistItemsClient) Get(ctx context.Context, id WatchlistItemId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/watchlistitems/method_get_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/watchlistitems/method_get_autorest.go deleted file mode 100644 index b294f999f64..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/watchlistitems/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package watchlistitems - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *WatchlistItem -} - -// Get ... -func (c WatchlistItemsClient) Get(ctx context.Context, id WatchlistItemId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c WatchlistItemsClient) preparerForGet(ctx context.Context, id WatchlistItemId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c WatchlistItemsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/watchlistitems/method_list.go b/resource-manager/securityinsights/2022-10-01-preview/watchlistitems/method_list.go new file mode 100644 index 00000000000..8a4d418ea0b --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/watchlistitems/method_list.go @@ -0,0 +1,91 @@ +package watchlistitems + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]WatchlistItem +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []WatchlistItem +} + +// List ... +func (c WatchlistItemsClient) List(ctx context.Context, id WatchlistId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/watchlistItems", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]WatchlistItem `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c WatchlistItemsClient) ListComplete(ctx context.Context, id WatchlistId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, WatchlistItemOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c WatchlistItemsClient) ListCompleteMatchingPredicate(ctx context.Context, id WatchlistId, predicate WatchlistItemOperationPredicate) (result ListCompleteResult, err error) { + items := make([]WatchlistItem, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/watchlistitems/method_list_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/watchlistitems/method_list_autorest.go deleted file mode 100644 index d8e4bf85bf1..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/watchlistitems/method_list_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package watchlistitems - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]WatchlistItem - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []WatchlistItem -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c WatchlistItemsClient) List(ctx context.Context, id WatchlistId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c WatchlistItemsClient) preparerForList(ctx context.Context, id WatchlistId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/watchlistItems", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c WatchlistItemsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c WatchlistItemsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []WatchlistItem `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c WatchlistItemsClient) ListComplete(ctx context.Context, id WatchlistId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, WatchlistItemOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c WatchlistItemsClient) ListCompleteMatchingPredicate(ctx context.Context, id WatchlistId, predicate WatchlistItemOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]WatchlistItem, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/watchlists/client.go b/resource-manager/securityinsights/2022-10-01-preview/watchlists/client.go index 61cfa3d0ac3..45211175054 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/watchlists/client.go +++ b/resource-manager/securityinsights/2022-10-01-preview/watchlists/client.go @@ -1,18 +1,26 @@ package watchlists -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type WatchlistsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewWatchlistsClientWithBaseURI(endpoint string) WatchlistsClient { - return WatchlistsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewWatchlistsClientWithBaseURI(sdkApi sdkEnv.Api) (*WatchlistsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "watchlists", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating WatchlistsClient: %+v", err) } + + return &WatchlistsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-10-01-preview/watchlists/constants.go b/resource-manager/securityinsights/2022-10-01-preview/watchlists/constants.go index 21534a9bfa6..6a9873135b3 100644 --- a/resource-manager/securityinsights/2022-10-01-preview/watchlists/constants.go +++ b/resource-manager/securityinsights/2022-10-01-preview/watchlists/constants.go @@ -1,6 +1,10 @@ package watchlists -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -19,6 +23,19 @@ func PossibleValuesForSourceType() []string { } } +func (s *SourceType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSourceType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSourceType(input string) (*SourceType, error) { vals := map[string]SourceType{ "local file": SourceTypeLocalFile, diff --git a/resource-manager/securityinsights/2022-10-01-preview/watchlists/method_createorupdate.go b/resource-manager/securityinsights/2022-10-01-preview/watchlists/method_createorupdate.go new file mode 100644 index 00000000000..cf0dc47e9d7 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/watchlists/method_createorupdate.go @@ -0,0 +1,56 @@ +package watchlists + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Watchlist +} + +// CreateOrUpdate ... +func (c WatchlistsClient) CreateOrUpdate(ctx context.Context, id WatchlistId, input Watchlist) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/watchlists/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/watchlists/method_createorupdate_autorest.go deleted file mode 100644 index e6d8a5976b8..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/watchlists/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package watchlists - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *Watchlist -} - -// CreateOrUpdate ... -func (c WatchlistsClient) CreateOrUpdate(ctx context.Context, id WatchlistId, input Watchlist) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c WatchlistsClient) preparerForCreateOrUpdate(ctx context.Context, id WatchlistId, input Watchlist) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c WatchlistsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/watchlists/method_delete.go b/resource-manager/securityinsights/2022-10-01-preview/watchlists/method_delete.go new file mode 100644 index 00000000000..9d495f99c57 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/watchlists/method_delete.go @@ -0,0 +1,47 @@ +package watchlists + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c WatchlistsClient) Delete(ctx context.Context, id WatchlistId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/watchlists/method_delete_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/watchlists/method_delete_autorest.go deleted file mode 100644 index 56234124b82..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/watchlists/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package watchlists - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c WatchlistsClient) Delete(ctx context.Context, id WatchlistId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c WatchlistsClient) preparerForDelete(ctx context.Context, id WatchlistId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c WatchlistsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/watchlists/method_get.go b/resource-manager/securityinsights/2022-10-01-preview/watchlists/method_get.go new file mode 100644 index 00000000000..39ec92feaeb --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/watchlists/method_get.go @@ -0,0 +1,51 @@ +package watchlists + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Watchlist +} + +// Get ... +func (c WatchlistsClient) Get(ctx context.Context, id WatchlistId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/watchlists/method_get_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/watchlists/method_get_autorest.go deleted file mode 100644 index d7253f62215..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/watchlists/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package watchlists - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *Watchlist -} - -// Get ... -func (c WatchlistsClient) Get(ctx context.Context, id WatchlistId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c WatchlistsClient) preparerForGet(ctx context.Context, id WatchlistId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c WatchlistsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-10-01-preview/watchlists/method_list.go b/resource-manager/securityinsights/2022-10-01-preview/watchlists/method_list.go new file mode 100644 index 00000000000..9122b014815 --- /dev/null +++ b/resource-manager/securityinsights/2022-10-01-preview/watchlists/method_list.go @@ -0,0 +1,91 @@ +package watchlists + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Watchlist +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Watchlist +} + +// List ... +func (c WatchlistsClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/watchlists", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Watchlist `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c WatchlistsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, WatchlistOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c WatchlistsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate WatchlistOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Watchlist, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-10-01-preview/watchlists/method_list_autorest.go b/resource-manager/securityinsights/2022-10-01-preview/watchlists/method_list_autorest.go deleted file mode 100644 index a3a2c27c15e..00000000000 --- a/resource-manager/securityinsights/2022-10-01-preview/watchlists/method_list_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package watchlists - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]Watchlist - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []Watchlist -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c WatchlistsClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c WatchlistsClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/watchlists", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c WatchlistsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c WatchlistsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []Watchlist `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c WatchlistsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, WatchlistOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c WatchlistsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate WatchlistOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]Watchlist, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-11-01/actions/client.go b/resource-manager/securityinsights/2022-11-01/actions/client.go index 9a66b55eb82..a2b7d01bfe1 100644 --- a/resource-manager/securityinsights/2022-11-01/actions/client.go +++ b/resource-manager/securityinsights/2022-11-01/actions/client.go @@ -1,18 +1,26 @@ package actions -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type ActionsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewActionsClientWithBaseURI(endpoint string) ActionsClient { - return ActionsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewActionsClientWithBaseURI(sdkApi sdkEnv.Api) (*ActionsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "actions", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ActionsClient: %+v", err) } + + return &ActionsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-11-01/actions/method_createorupdate.go b/resource-manager/securityinsights/2022-11-01/actions/method_createorupdate.go new file mode 100644 index 00000000000..1672bf99a0f --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/actions/method_createorupdate.go @@ -0,0 +1,56 @@ +package actions + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ActionResponse +} + +// CreateOrUpdate ... +func (c ActionsClient) CreateOrUpdate(ctx context.Context, id ActionId, input ActionRequest) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/actions/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-11-01/actions/method_createorupdate_autorest.go deleted file mode 100644 index f5145e1a555..00000000000 --- a/resource-manager/securityinsights/2022-11-01/actions/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package actions - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *ActionResponse -} - -// CreateOrUpdate ... -func (c ActionsClient) CreateOrUpdate(ctx context.Context, id ActionId, input ActionRequest) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c ActionsClient) preparerForCreateOrUpdate(ctx context.Context, id ActionId, input ActionRequest) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c ActionsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-11-01/actions/method_delete.go b/resource-manager/securityinsights/2022-11-01/actions/method_delete.go new file mode 100644 index 00000000000..0f8a28307c2 --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/actions/method_delete.go @@ -0,0 +1,47 @@ +package actions + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c ActionsClient) Delete(ctx context.Context, id ActionId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/actions/method_delete_autorest.go b/resource-manager/securityinsights/2022-11-01/actions/method_delete_autorest.go deleted file mode 100644 index d142f9f3054..00000000000 --- a/resource-manager/securityinsights/2022-11-01/actions/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package actions - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c ActionsClient) Delete(ctx context.Context, id ActionId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c ActionsClient) preparerForDelete(ctx context.Context, id ActionId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c ActionsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-11-01/actions/method_get.go b/resource-manager/securityinsights/2022-11-01/actions/method_get.go new file mode 100644 index 00000000000..76d3593e1f1 --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/actions/method_get.go @@ -0,0 +1,51 @@ +package actions + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ActionResponse +} + +// Get ... +func (c ActionsClient) Get(ctx context.Context, id ActionId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/actions/method_get_autorest.go b/resource-manager/securityinsights/2022-11-01/actions/method_get_autorest.go deleted file mode 100644 index aa1388a0c31..00000000000 --- a/resource-manager/securityinsights/2022-11-01/actions/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package actions - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *ActionResponse -} - -// Get ... -func (c ActionsClient) Get(ctx context.Context, id ActionId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c ActionsClient) preparerForGet(ctx context.Context, id ActionId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c ActionsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-11-01/actions/method_listbyalertrule.go b/resource-manager/securityinsights/2022-11-01/actions/method_listbyalertrule.go new file mode 100644 index 00000000000..09d32b9d82d --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/actions/method_listbyalertrule.go @@ -0,0 +1,91 @@ +package actions + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByAlertRuleOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ActionResponse +} + +type ListByAlertRuleCompleteResult struct { + LatestHttpResponse *http.Response + Items []ActionResponse +} + +// ListByAlertRule ... +func (c ActionsClient) ListByAlertRule(ctx context.Context, id AlertRuleId) (result ListByAlertRuleOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/actions", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ActionResponse `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByAlertRuleComplete retrieves all the results into a single object +func (c ActionsClient) ListByAlertRuleComplete(ctx context.Context, id AlertRuleId) (ListByAlertRuleCompleteResult, error) { + return c.ListByAlertRuleCompleteMatchingPredicate(ctx, id, ActionResponseOperationPredicate{}) +} + +// ListByAlertRuleCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ActionsClient) ListByAlertRuleCompleteMatchingPredicate(ctx context.Context, id AlertRuleId, predicate ActionResponseOperationPredicate) (result ListByAlertRuleCompleteResult, err error) { + items := make([]ActionResponse, 0) + + resp, err := c.ListByAlertRule(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByAlertRuleCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-11-01/actions/method_listbyalertrule_autorest.go b/resource-manager/securityinsights/2022-11-01/actions/method_listbyalertrule_autorest.go deleted file mode 100644 index a58a9738f1f..00000000000 --- a/resource-manager/securityinsights/2022-11-01/actions/method_listbyalertrule_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package actions - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListByAlertRuleOperationResponse struct { - HttpResponse *http.Response - Model *[]ActionResponse - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListByAlertRuleOperationResponse, error) -} - -type ListByAlertRuleCompleteResult struct { - Items []ActionResponse -} - -func (r ListByAlertRuleOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListByAlertRuleOperationResponse) LoadMore(ctx context.Context) (resp ListByAlertRuleOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// ListByAlertRule ... -func (c ActionsClient) ListByAlertRule(ctx context.Context, id AlertRuleId) (resp ListByAlertRuleOperationResponse, err error) { - req, err := c.preparerForListByAlertRule(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "ListByAlertRule", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "ListByAlertRule", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForListByAlertRule(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "ListByAlertRule", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForListByAlertRule prepares the ListByAlertRule request. -func (c ActionsClient) preparerForListByAlertRule(ctx context.Context, id AlertRuleId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/actions", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListByAlertRuleWithNextLink prepares the ListByAlertRule request with the given nextLink token. -func (c ActionsClient) preparerForListByAlertRuleWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForListByAlertRule handles the response to the ListByAlertRule request. The method always -// closes the http.Response Body. -func (c ActionsClient) responderForListByAlertRule(resp *http.Response) (result ListByAlertRuleOperationResponse, err error) { - type page struct { - Values []ActionResponse `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByAlertRuleOperationResponse, err error) { - req, err := c.preparerForListByAlertRuleWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "ListByAlertRule", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "ListByAlertRule", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForListByAlertRule(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "ListByAlertRule", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListByAlertRuleComplete retrieves all of the results into a single object -func (c ActionsClient) ListByAlertRuleComplete(ctx context.Context, id AlertRuleId) (ListByAlertRuleCompleteResult, error) { - return c.ListByAlertRuleCompleteMatchingPredicate(ctx, id, ActionResponseOperationPredicate{}) -} - -// ListByAlertRuleCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c ActionsClient) ListByAlertRuleCompleteMatchingPredicate(ctx context.Context, id AlertRuleId, predicate ActionResponseOperationPredicate) (resp ListByAlertRuleCompleteResult, err error) { - items := make([]ActionResponse, 0) - - page, err := c.ListByAlertRule(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListByAlertRuleCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-11-01/alertrules/client.go b/resource-manager/securityinsights/2022-11-01/alertrules/client.go index 6e34bca2ce3..e6ca04af9da 100644 --- a/resource-manager/securityinsights/2022-11-01/alertrules/client.go +++ b/resource-manager/securityinsights/2022-11-01/alertrules/client.go @@ -1,18 +1,26 @@ package alertrules -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type AlertRulesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewAlertRulesClientWithBaseURI(endpoint string) AlertRulesClient { - return AlertRulesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewAlertRulesClientWithBaseURI(sdkApi sdkEnv.Api) (*AlertRulesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "alertrules", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AlertRulesClient: %+v", err) } + + return &AlertRulesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-11-01/alertrules/constants.go b/resource-manager/securityinsights/2022-11-01/alertrules/constants.go index 91178a52cc5..8c0d36ec74b 100644 --- a/resource-manager/securityinsights/2022-11-01/alertrules/constants.go +++ b/resource-manager/securityinsights/2022-11-01/alertrules/constants.go @@ -1,6 +1,10 @@ package alertrules -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -19,6 +23,19 @@ func PossibleValuesForAlertDetail() []string { } } +func (s *AlertDetail) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertDetail(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertDetail(input string) (*AlertDetail, error) { vals := map[string]AlertDetail{ "displayname": AlertDetailDisplayName, @@ -49,6 +66,19 @@ func PossibleValuesForAlertRuleKind() []string { } } +func (s *AlertRuleKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertRuleKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertRuleKind(input string) (*AlertRuleKind, error) { vals := map[string]AlertRuleKind{ "fusion": AlertRuleKindFusion, @@ -82,6 +112,19 @@ func PossibleValuesForAlertSeverity() []string { } } +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertSeverity(input string) (*AlertSeverity, error) { vals := map[string]AlertSeverity{ "high": AlertSeverityHigh, @@ -142,6 +185,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -217,6 +273,19 @@ func PossibleValuesForEntityMappingType() []string { } } +func (s *EntityMappingType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityMappingType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityMappingType(input string) (*EntityMappingType, error) { vals := map[string]EntityMappingType{ "account": EntityMappingTypeAccount, @@ -261,6 +330,19 @@ func PossibleValuesForEventGroupingAggregationKind() []string { } } +func (s *EventGroupingAggregationKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEventGroupingAggregationKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEventGroupingAggregationKind(input string) (*EventGroupingAggregationKind, error) { vals := map[string]EventGroupingAggregationKind{ "alertperresult": EventGroupingAggregationKindAlertPerResult, @@ -291,6 +373,19 @@ func PossibleValuesForMatchingMethod() []string { } } +func (s *MatchingMethod) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMatchingMethod(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseMatchingMethod(input string) (*MatchingMethod, error) { vals := map[string]MatchingMethod{ "allentities": MatchingMethodAllEntities, @@ -326,6 +421,19 @@ func PossibleValuesForMicrosoftSecurityProductName() []string { } } +func (s *MicrosoftSecurityProductName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMicrosoftSecurityProductName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseMicrosoftSecurityProductName(input string) (*MicrosoftSecurityProductName, error) { vals := map[string]MicrosoftSecurityProductName{ "azure active directory identity protection": MicrosoftSecurityProductNameAzureActiveDirectoryIdentityProtection, @@ -361,6 +469,19 @@ func PossibleValuesForTriggerOperator() []string { } } +func (s *TriggerOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTriggerOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseTriggerOperator(input string) (*TriggerOperator, error) { vals := map[string]TriggerOperator{ "equal": TriggerOperatorEqual, diff --git a/resource-manager/securityinsights/2022-11-01/alertrules/method_createorupdate.go b/resource-manager/securityinsights/2022-11-01/alertrules/method_createorupdate.go new file mode 100644 index 00000000000..f77c7558d09 --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/alertrules/method_createorupdate.go @@ -0,0 +1,63 @@ +package alertrules + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AlertRule +} + +// CreateOrUpdate ... +func (c AlertRulesClient) CreateOrUpdate(ctx context.Context, id AlertRuleId, input AlertRule) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalAlertRuleImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/alertrules/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-11-01/alertrules/method_createorupdate_autorest.go deleted file mode 100644 index 548f6c4ef37..00000000000 --- a/resource-manager/securityinsights/2022-11-01/alertrules/method_createorupdate_autorest.go +++ /dev/null @@ -1,78 +0,0 @@ -package alertrules - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *AlertRule -} - -// CreateOrUpdate ... -func (c AlertRulesClient) CreateOrUpdate(ctx context.Context, id AlertRuleId, input AlertRule) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c AlertRulesClient) preparerForCreateOrUpdate(ctx context.Context, id AlertRuleId, input AlertRule) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c AlertRulesClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalAlertRuleImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-11-01/alertrules/method_delete.go b/resource-manager/securityinsights/2022-11-01/alertrules/method_delete.go new file mode 100644 index 00000000000..aae7085c25e --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/alertrules/method_delete.go @@ -0,0 +1,47 @@ +package alertrules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c AlertRulesClient) Delete(ctx context.Context, id AlertRuleId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/alertrules/method_delete_autorest.go b/resource-manager/securityinsights/2022-11-01/alertrules/method_delete_autorest.go deleted file mode 100644 index 417e1a0017e..00000000000 --- a/resource-manager/securityinsights/2022-11-01/alertrules/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package alertrules - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c AlertRulesClient) Delete(ctx context.Context, id AlertRuleId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c AlertRulesClient) preparerForDelete(ctx context.Context, id AlertRuleId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c AlertRulesClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-11-01/alertrules/method_get.go b/resource-manager/securityinsights/2022-11-01/alertrules/method_get.go new file mode 100644 index 00000000000..945c07bfad1 --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/alertrules/method_get.go @@ -0,0 +1,58 @@ +package alertrules + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AlertRule +} + +// Get ... +func (c AlertRulesClient) Get(ctx context.Context, id AlertRuleId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalAlertRuleImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/alertrules/method_get_autorest.go b/resource-manager/securityinsights/2022-11-01/alertrules/method_get_autorest.go deleted file mode 100644 index ddd1836d4de..00000000000 --- a/resource-manager/securityinsights/2022-11-01/alertrules/method_get_autorest.go +++ /dev/null @@ -1,77 +0,0 @@ -package alertrules - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *AlertRule -} - -// Get ... -func (c AlertRulesClient) Get(ctx context.Context, id AlertRuleId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c AlertRulesClient) preparerForGet(ctx context.Context, id AlertRuleId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c AlertRulesClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalAlertRuleImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-11-01/alertrules/method_list.go b/resource-manager/securityinsights/2022-11-01/alertrules/method_list.go new file mode 100644 index 00000000000..5ac99496167 --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/alertrules/method_list.go @@ -0,0 +1,103 @@ +package alertrules + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AlertRule +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []AlertRule +} + +// List ... +func (c AlertRulesClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/alertRules", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]AlertRule, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalAlertRuleImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for AlertRule (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// ListComplete retrieves all the results into a single object +func (c AlertRulesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, AlertRuleOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AlertRulesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AlertRuleOperationPredicate) (result ListCompleteResult, err error) { + items := make([]AlertRule, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-11-01/alertrules/method_list_autorest.go b/resource-manager/securityinsights/2022-11-01/alertrules/method_list_autorest.go deleted file mode 100644 index f06cf0f6241..00000000000 --- a/resource-manager/securityinsights/2022-11-01/alertrules/method_list_autorest.go +++ /dev/null @@ -1,196 +0,0 @@ -package alertrules - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]AlertRule - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []AlertRule -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c AlertRulesClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c AlertRulesClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/alertRules", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c AlertRulesClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c AlertRulesClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]AlertRule, 0) - for i, v := range respObj.Values { - val, err := unmarshalAlertRuleImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for AlertRule (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c AlertRulesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, AlertRuleOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c AlertRulesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AlertRuleOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]AlertRule, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-11-01/alertruletemplates/client.go b/resource-manager/securityinsights/2022-11-01/alertruletemplates/client.go index c439e5a41c7..2932bf14a55 100644 --- a/resource-manager/securityinsights/2022-11-01/alertruletemplates/client.go +++ b/resource-manager/securityinsights/2022-11-01/alertruletemplates/client.go @@ -1,18 +1,26 @@ package alertruletemplates -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type AlertRuleTemplatesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewAlertRuleTemplatesClientWithBaseURI(endpoint string) AlertRuleTemplatesClient { - return AlertRuleTemplatesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewAlertRuleTemplatesClientWithBaseURI(sdkApi sdkEnv.Api) (*AlertRuleTemplatesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "alertruletemplates", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AlertRuleTemplatesClient: %+v", err) } + + return &AlertRuleTemplatesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-11-01/alertruletemplates/constants.go b/resource-manager/securityinsights/2022-11-01/alertruletemplates/constants.go index 6354a51236f..7ec9389513f 100644 --- a/resource-manager/securityinsights/2022-11-01/alertruletemplates/constants.go +++ b/resource-manager/securityinsights/2022-11-01/alertruletemplates/constants.go @@ -1,6 +1,10 @@ package alertruletemplates -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -21,6 +25,19 @@ func PossibleValuesForAlertRuleKind() []string { } } +func (s *AlertRuleKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertRuleKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertRuleKind(input string) (*AlertRuleKind, error) { vals := map[string]AlertRuleKind{ "fusion": AlertRuleKindFusion, @@ -54,6 +71,19 @@ func PossibleValuesForAlertSeverity() []string { } } +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertSeverity(input string) (*AlertSeverity, error) { vals := map[string]AlertSeverity{ "high": AlertSeverityHigh, @@ -114,6 +144,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -189,6 +232,19 @@ func PossibleValuesForEntityMappingType() []string { } } +func (s *EntityMappingType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityMappingType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityMappingType(input string) (*EntityMappingType, error) { vals := map[string]EntityMappingType{ "account": EntityMappingTypeAccount, @@ -233,6 +289,19 @@ func PossibleValuesForEventGroupingAggregationKind() []string { } } +func (s *EventGroupingAggregationKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEventGroupingAggregationKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEventGroupingAggregationKind(input string) (*EventGroupingAggregationKind, error) { vals := map[string]EventGroupingAggregationKind{ "alertperresult": EventGroupingAggregationKindAlertPerResult, @@ -267,6 +336,19 @@ func PossibleValuesForMicrosoftSecurityProductName() []string { } } +func (s *MicrosoftSecurityProductName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMicrosoftSecurityProductName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseMicrosoftSecurityProductName(input string) (*MicrosoftSecurityProductName, error) { vals := map[string]MicrosoftSecurityProductName{ "azure active directory identity protection": MicrosoftSecurityProductNameAzureActiveDirectoryIdentityProtection, @@ -300,6 +382,19 @@ func PossibleValuesForTemplateStatus() []string { } } +func (s *TemplateStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTemplateStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseTemplateStatus(input string) (*TemplateStatus, error) { vals := map[string]TemplateStatus{ "available": TemplateStatusAvailable, @@ -333,6 +428,19 @@ func PossibleValuesForTriggerOperator() []string { } } +func (s *TriggerOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTriggerOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseTriggerOperator(input string) (*TriggerOperator, error) { vals := map[string]TriggerOperator{ "equal": TriggerOperatorEqual, diff --git a/resource-manager/securityinsights/2022-11-01/alertruletemplates/method_get.go b/resource-manager/securityinsights/2022-11-01/alertruletemplates/method_get.go new file mode 100644 index 00000000000..861712be66a --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/alertruletemplates/method_get.go @@ -0,0 +1,58 @@ +package alertruletemplates + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AlertRuleTemplate +} + +// Get ... +func (c AlertRuleTemplatesClient) Get(ctx context.Context, id AlertRuleTemplateId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalAlertRuleTemplateImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/alertruletemplates/method_get_autorest.go b/resource-manager/securityinsights/2022-11-01/alertruletemplates/method_get_autorest.go deleted file mode 100644 index ad4e0487d83..00000000000 --- a/resource-manager/securityinsights/2022-11-01/alertruletemplates/method_get_autorest.go +++ /dev/null @@ -1,77 +0,0 @@ -package alertruletemplates - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *AlertRuleTemplate -} - -// Get ... -func (c AlertRuleTemplatesClient) Get(ctx context.Context, id AlertRuleTemplateId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c AlertRuleTemplatesClient) preparerForGet(ctx context.Context, id AlertRuleTemplateId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c AlertRuleTemplatesClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalAlertRuleTemplateImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-11-01/alertruletemplates/method_list.go b/resource-manager/securityinsights/2022-11-01/alertruletemplates/method_list.go new file mode 100644 index 00000000000..21f9ceec3de --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/alertruletemplates/method_list.go @@ -0,0 +1,103 @@ +package alertruletemplates + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AlertRuleTemplate +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []AlertRuleTemplate +} + +// List ... +func (c AlertRuleTemplatesClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/alertRuleTemplates", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]AlertRuleTemplate, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalAlertRuleTemplateImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for AlertRuleTemplate (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// ListComplete retrieves all the results into a single object +func (c AlertRuleTemplatesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, AlertRuleTemplateOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AlertRuleTemplatesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AlertRuleTemplateOperationPredicate) (result ListCompleteResult, err error) { + items := make([]AlertRuleTemplate, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-11-01/alertruletemplates/method_list_autorest.go b/resource-manager/securityinsights/2022-11-01/alertruletemplates/method_list_autorest.go deleted file mode 100644 index 56794382966..00000000000 --- a/resource-manager/securityinsights/2022-11-01/alertruletemplates/method_list_autorest.go +++ /dev/null @@ -1,196 +0,0 @@ -package alertruletemplates - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]AlertRuleTemplate - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []AlertRuleTemplate -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c AlertRuleTemplatesClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c AlertRuleTemplatesClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/alertRuleTemplates", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c AlertRuleTemplatesClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c AlertRuleTemplatesClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]AlertRuleTemplate, 0) - for i, v := range respObj.Values { - val, err := unmarshalAlertRuleTemplateImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for AlertRuleTemplate (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c AlertRuleTemplatesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, AlertRuleTemplateOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c AlertRuleTemplatesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AlertRuleTemplateOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]AlertRuleTemplate, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-11-01/automationrules/client.go b/resource-manager/securityinsights/2022-11-01/automationrules/client.go index 960f049c387..18fafea1496 100644 --- a/resource-manager/securityinsights/2022-11-01/automationrules/client.go +++ b/resource-manager/securityinsights/2022-11-01/automationrules/client.go @@ -1,18 +1,26 @@ package automationrules -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type AutomationRulesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewAutomationRulesClientWithBaseURI(endpoint string) AutomationRulesClient { - return AutomationRulesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewAutomationRulesClientWithBaseURI(sdkApi sdkEnv.Api) (*AutomationRulesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "automationrules", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AutomationRulesClient: %+v", err) } + + return &AutomationRulesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-11-01/automationrules/constants.go b/resource-manager/securityinsights/2022-11-01/automationrules/constants.go index 42f2fc009f2..71480e3d3d7 100644 --- a/resource-manager/securityinsights/2022-11-01/automationrules/constants.go +++ b/resource-manager/securityinsights/2022-11-01/automationrules/constants.go @@ -1,6 +1,10 @@ package automationrules -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -19,6 +23,19 @@ func PossibleValuesForActionType() []string { } } +func (s *ActionType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseActionType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseActionType(input string) (*ActionType, error) { vals := map[string]ActionType{ "modifyproperties": ActionTypeModifyProperties, @@ -51,6 +68,19 @@ func PossibleValuesForAutomationRulePropertyArrayChangedConditionSupportedArrayT } } +func (s *AutomationRulePropertyArrayChangedConditionSupportedArrayType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRulePropertyArrayChangedConditionSupportedArrayType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAutomationRulePropertyArrayChangedConditionSupportedArrayType(input string) (*AutomationRulePropertyArrayChangedConditionSupportedArrayType, error) { vals := map[string]AutomationRulePropertyArrayChangedConditionSupportedArrayType{ "alerts": AutomationRulePropertyArrayChangedConditionSupportedArrayTypeAlerts, @@ -79,6 +109,19 @@ func PossibleValuesForAutomationRulePropertyArrayChangedConditionSupportedChange } } +func (s *AutomationRulePropertyArrayChangedConditionSupportedChangeType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRulePropertyArrayChangedConditionSupportedChangeType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAutomationRulePropertyArrayChangedConditionSupportedChangeType(input string) (*AutomationRulePropertyArrayChangedConditionSupportedChangeType, error) { vals := map[string]AutomationRulePropertyArrayChangedConditionSupportedChangeType{ "added": AutomationRulePropertyArrayChangedConditionSupportedChangeTypeAdded, @@ -106,6 +149,19 @@ func PossibleValuesForAutomationRulePropertyChangedConditionSupportedChangedType } } +func (s *AutomationRulePropertyChangedConditionSupportedChangedType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRulePropertyChangedConditionSupportedChangedType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAutomationRulePropertyChangedConditionSupportedChangedType(input string) (*AutomationRulePropertyChangedConditionSupportedChangedType, error) { vals := map[string]AutomationRulePropertyChangedConditionSupportedChangedType{ "changedfrom": AutomationRulePropertyChangedConditionSupportedChangedTypeChangedFrom, @@ -136,6 +192,19 @@ func PossibleValuesForAutomationRulePropertyChangedConditionSupportedPropertyTyp } } +func (s *AutomationRulePropertyChangedConditionSupportedPropertyType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRulePropertyChangedConditionSupportedPropertyType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAutomationRulePropertyChangedConditionSupportedPropertyType(input string) (*AutomationRulePropertyChangedConditionSupportedPropertyType, error) { vals := map[string]AutomationRulePropertyChangedConditionSupportedPropertyType{ "incidentowner": AutomationRulePropertyChangedConditionSupportedPropertyTypeIncidentOwner, @@ -177,6 +246,19 @@ func PossibleValuesForAutomationRulePropertyConditionSupportedOperator() []strin } } +func (s *AutomationRulePropertyConditionSupportedOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRulePropertyConditionSupportedOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAutomationRulePropertyConditionSupportedOperator(input string) (*AutomationRulePropertyConditionSupportedOperator, error) { vals := map[string]AutomationRulePropertyConditionSupportedOperator{ "contains": AutomationRulePropertyConditionSupportedOperatorContains, @@ -319,6 +401,19 @@ func PossibleValuesForAutomationRulePropertyConditionSupportedProperty() []strin } } +func (s *AutomationRulePropertyConditionSupportedProperty) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRulePropertyConditionSupportedProperty(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAutomationRulePropertyConditionSupportedProperty(input string) (*AutomationRulePropertyConditionSupportedProperty, error) { vals := map[string]AutomationRulePropertyConditionSupportedProperty{ "accountaadtenantid": AutomationRulePropertyConditionSupportedPropertyAccountAadTenantId, @@ -403,6 +498,19 @@ func PossibleValuesForConditionType() []string { } } +func (s *ConditionType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConditionType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConditionType(input string) (*ConditionType, error) { vals := map[string]ConditionType{ "property": ConditionTypeProperty, @@ -436,6 +544,19 @@ func PossibleValuesForIncidentClassification() []string { } } +func (s *IncidentClassification) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentClassification(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentClassification(input string) (*IncidentClassification, error) { vals := map[string]IncidentClassification{ "benignpositive": IncidentClassificationBenignPositive, @@ -470,6 +591,19 @@ func PossibleValuesForIncidentClassificationReason() []string { } } +func (s *IncidentClassificationReason) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentClassificationReason(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentClassificationReason(input string) (*IncidentClassificationReason, error) { vals := map[string]IncidentClassificationReason{ "inaccuratedata": IncidentClassificationReasonInaccurateData, @@ -500,6 +634,19 @@ func PossibleValuesForIncidentLabelType() []string { } } +func (s *IncidentLabelType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentLabelType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentLabelType(input string) (*IncidentLabelType, error) { vals := map[string]IncidentLabelType{ "autoassigned": IncidentLabelTypeAutoAssigned, @@ -532,6 +679,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, @@ -564,6 +724,19 @@ func PossibleValuesForIncidentStatus() []string { } } +func (s *IncidentStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentStatus(input string) (*IncidentStatus, error) { vals := map[string]IncidentStatus{ "active": IncidentStatusActive, @@ -595,6 +768,19 @@ func PossibleValuesForOwnerType() []string { } } +func (s *OwnerType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOwnerType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseOwnerType(input string) (*OwnerType, error) { vals := map[string]OwnerType{ "group": OwnerTypeGroup, @@ -624,6 +810,19 @@ func PossibleValuesForTriggersOn() []string { } } +func (s *TriggersOn) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTriggersOn(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseTriggersOn(input string) (*TriggersOn, error) { vals := map[string]TriggersOn{ "alerts": TriggersOnAlerts, @@ -652,6 +851,19 @@ func PossibleValuesForTriggersWhen() []string { } } +func (s *TriggersWhen) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTriggersWhen(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseTriggersWhen(input string) (*TriggersWhen, error) { vals := map[string]TriggersWhen{ "created": TriggersWhenCreated, diff --git a/resource-manager/securityinsights/2022-11-01/automationrules/method_createorupdate.go b/resource-manager/securityinsights/2022-11-01/automationrules/method_createorupdate.go new file mode 100644 index 00000000000..c0b3c44f2da --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/automationrules/method_createorupdate.go @@ -0,0 +1,56 @@ +package automationrules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AutomationRule +} + +// CreateOrUpdate ... +func (c AutomationRulesClient) CreateOrUpdate(ctx context.Context, id AutomationRuleId, input AutomationRule) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/automationrules/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-11-01/automationrules/method_createorupdate_autorest.go deleted file mode 100644 index 790f2ff99f9..00000000000 --- a/resource-manager/securityinsights/2022-11-01/automationrules/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package automationrules - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *AutomationRule -} - -// CreateOrUpdate ... -func (c AutomationRulesClient) CreateOrUpdate(ctx context.Context, id AutomationRuleId, input AutomationRule) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c AutomationRulesClient) preparerForCreateOrUpdate(ctx context.Context, id AutomationRuleId, input AutomationRule) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c AutomationRulesClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-11-01/automationrules/method_delete.go b/resource-manager/securityinsights/2022-11-01/automationrules/method_delete.go new file mode 100644 index 00000000000..682e97ed619 --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/automationrules/method_delete.go @@ -0,0 +1,52 @@ +package automationrules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *interface{} +} + +// Delete ... +func (c AutomationRulesClient) Delete(ctx context.Context, id AutomationRuleId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/automationrules/method_delete_autorest.go b/resource-manager/securityinsights/2022-11-01/automationrules/method_delete_autorest.go deleted file mode 100644 index cd33f79070e..00000000000 --- a/resource-manager/securityinsights/2022-11-01/automationrules/method_delete_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package automationrules - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response - Model *interface{} -} - -// Delete ... -func (c AutomationRulesClient) Delete(ctx context.Context, id AutomationRuleId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c AutomationRulesClient) preparerForDelete(ctx context.Context, id AutomationRuleId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c AutomationRulesClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-11-01/automationrules/method_get.go b/resource-manager/securityinsights/2022-11-01/automationrules/method_get.go new file mode 100644 index 00000000000..0676dc80f40 --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/automationrules/method_get.go @@ -0,0 +1,51 @@ +package automationrules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AutomationRule +} + +// Get ... +func (c AutomationRulesClient) Get(ctx context.Context, id AutomationRuleId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/automationrules/method_get_autorest.go b/resource-manager/securityinsights/2022-11-01/automationrules/method_get_autorest.go deleted file mode 100644 index 20f385aa8d7..00000000000 --- a/resource-manager/securityinsights/2022-11-01/automationrules/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package automationrules - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *AutomationRule -} - -// Get ... -func (c AutomationRulesClient) Get(ctx context.Context, id AutomationRuleId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c AutomationRulesClient) preparerForGet(ctx context.Context, id AutomationRuleId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c AutomationRulesClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-11-01/automationrules/method_list.go b/resource-manager/securityinsights/2022-11-01/automationrules/method_list.go new file mode 100644 index 00000000000..a3c7db4995a --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/automationrules/method_list.go @@ -0,0 +1,91 @@ +package automationrules + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AutomationRule +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []AutomationRule +} + +// List ... +func (c AutomationRulesClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/automationRules", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]AutomationRule `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c AutomationRulesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, AutomationRuleOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AutomationRulesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AutomationRuleOperationPredicate) (result ListCompleteResult, err error) { + items := make([]AutomationRule, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-11-01/automationrules/method_list_autorest.go b/resource-manager/securityinsights/2022-11-01/automationrules/method_list_autorest.go deleted file mode 100644 index e2818088fcf..00000000000 --- a/resource-manager/securityinsights/2022-11-01/automationrules/method_list_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package automationrules - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]AutomationRule - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []AutomationRule -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c AutomationRulesClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c AutomationRulesClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/automationRules", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c AutomationRulesClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c AutomationRulesClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []AutomationRule `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c AutomationRulesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, AutomationRuleOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c AutomationRulesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AutomationRuleOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]AutomationRule, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-11-01/bookmarks/client.go b/resource-manager/securityinsights/2022-11-01/bookmarks/client.go index ee8ca229e2d..22469155649 100644 --- a/resource-manager/securityinsights/2022-11-01/bookmarks/client.go +++ b/resource-manager/securityinsights/2022-11-01/bookmarks/client.go @@ -1,18 +1,26 @@ package bookmarks -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type BookmarksClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewBookmarksClientWithBaseURI(endpoint string) BookmarksClient { - return BookmarksClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewBookmarksClientWithBaseURI(sdkApi sdkEnv.Api) (*BookmarksClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "bookmarks", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating BookmarksClient: %+v", err) } + + return &BookmarksClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-11-01/bookmarks/constants.go b/resource-manager/securityinsights/2022-11-01/bookmarks/constants.go index f3a9bf2482b..c057284aed1 100644 --- a/resource-manager/securityinsights/2022-11-01/bookmarks/constants.go +++ b/resource-manager/securityinsights/2022-11-01/bookmarks/constants.go @@ -1,6 +1,10 @@ package bookmarks -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -23,6 +27,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, diff --git a/resource-manager/securityinsights/2022-11-01/bookmarks/method_createorupdate.go b/resource-manager/securityinsights/2022-11-01/bookmarks/method_createorupdate.go new file mode 100644 index 00000000000..72b6987ce5b --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/bookmarks/method_createorupdate.go @@ -0,0 +1,56 @@ +package bookmarks + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Bookmark +} + +// CreateOrUpdate ... +func (c BookmarksClient) CreateOrUpdate(ctx context.Context, id BookmarkId, input Bookmark) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/bookmarks/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-11-01/bookmarks/method_createorupdate_autorest.go deleted file mode 100644 index 6bae46884df..00000000000 --- a/resource-manager/securityinsights/2022-11-01/bookmarks/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package bookmarks - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *Bookmark -} - -// CreateOrUpdate ... -func (c BookmarksClient) CreateOrUpdate(ctx context.Context, id BookmarkId, input Bookmark) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c BookmarksClient) preparerForCreateOrUpdate(ctx context.Context, id BookmarkId, input Bookmark) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c BookmarksClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-11-01/bookmarks/method_delete.go b/resource-manager/securityinsights/2022-11-01/bookmarks/method_delete.go new file mode 100644 index 00000000000..75eef715a7c --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/bookmarks/method_delete.go @@ -0,0 +1,47 @@ +package bookmarks + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c BookmarksClient) Delete(ctx context.Context, id BookmarkId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/bookmarks/method_delete_autorest.go b/resource-manager/securityinsights/2022-11-01/bookmarks/method_delete_autorest.go deleted file mode 100644 index aa1033f513c..00000000000 --- a/resource-manager/securityinsights/2022-11-01/bookmarks/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package bookmarks - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c BookmarksClient) Delete(ctx context.Context, id BookmarkId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c BookmarksClient) preparerForDelete(ctx context.Context, id BookmarkId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c BookmarksClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-11-01/bookmarks/method_get.go b/resource-manager/securityinsights/2022-11-01/bookmarks/method_get.go new file mode 100644 index 00000000000..b8db3d1b69f --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/bookmarks/method_get.go @@ -0,0 +1,51 @@ +package bookmarks + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Bookmark +} + +// Get ... +func (c BookmarksClient) Get(ctx context.Context, id BookmarkId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/bookmarks/method_get_autorest.go b/resource-manager/securityinsights/2022-11-01/bookmarks/method_get_autorest.go deleted file mode 100644 index c76a6c0c211..00000000000 --- a/resource-manager/securityinsights/2022-11-01/bookmarks/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package bookmarks - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *Bookmark -} - -// Get ... -func (c BookmarksClient) Get(ctx context.Context, id BookmarkId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c BookmarksClient) preparerForGet(ctx context.Context, id BookmarkId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c BookmarksClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-11-01/bookmarks/method_list.go b/resource-manager/securityinsights/2022-11-01/bookmarks/method_list.go new file mode 100644 index 00000000000..432b04c413a --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/bookmarks/method_list.go @@ -0,0 +1,91 @@ +package bookmarks + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Bookmark +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Bookmark +} + +// List ... +func (c BookmarksClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/bookmarks", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Bookmark `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c BookmarksClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, BookmarkOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c BookmarksClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate BookmarkOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Bookmark, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-11-01/bookmarks/method_list_autorest.go b/resource-manager/securityinsights/2022-11-01/bookmarks/method_list_autorest.go deleted file mode 100644 index 7c4a69eacea..00000000000 --- a/resource-manager/securityinsights/2022-11-01/bookmarks/method_list_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package bookmarks - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]Bookmark - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []Bookmark -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c BookmarksClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c BookmarksClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/bookmarks", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c BookmarksClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c BookmarksClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []Bookmark `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c BookmarksClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, BookmarkOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c BookmarksClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate BookmarkOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]Bookmark, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-11-01/client.go b/resource-manager/securityinsights/2022-11-01/client.go index 55bc02a6e7c..3f51706d094 100644 --- a/resource-manager/securityinsights/2022-11-01/client.go +++ b/resource-manager/securityinsights/2022-11-01/client.go @@ -4,7 +4,8 @@ package v2022_11_01 // Licensed under the MIT License. See NOTICE.txt in the project root for license information. import ( - "github.com/Azure/go-autorest/autorest" + "fmt" + "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-11-01/actions" "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-11-01/alertrules" "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-11-01/alertruletemplates" @@ -23,6 +24,8 @@ import ( "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-11-01/threatintelligence" "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-11-01/watchlistitems" "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-11-01/watchlists" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" ) type Client struct { @@ -46,80 +49,133 @@ type Client struct { Watchlists *watchlists.WatchlistsClient } -func NewClientWithBaseURI(endpoint string, configureAuthFunc func(c *autorest.Client)) Client { - - actionsClient := actions.NewActionsClientWithBaseURI(endpoint) - configureAuthFunc(&actionsClient.Client) - - alertRuleTemplatesClient := alertruletemplates.NewAlertRuleTemplatesClientWithBaseURI(endpoint) - configureAuthFunc(&alertRuleTemplatesClient.Client) +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + actionsClient, err := actions.NewActionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Actions client: %+v", err) + } + configureFunc(actionsClient.Client) - alertRulesClient := alertrules.NewAlertRulesClientWithBaseURI(endpoint) - configureAuthFunc(&alertRulesClient.Client) + alertRuleTemplatesClient, err := alertruletemplates.NewAlertRuleTemplatesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AlertRuleTemplates client: %+v", err) + } + configureFunc(alertRuleTemplatesClient.Client) - automationRulesClient := automationrules.NewAutomationRulesClientWithBaseURI(endpoint) - configureAuthFunc(&automationRulesClient.Client) + alertRulesClient, err := alertrules.NewAlertRulesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AlertRules client: %+v", err) + } + configureFunc(alertRulesClient.Client) - bookmarksClient := bookmarks.NewBookmarksClientWithBaseURI(endpoint) - configureAuthFunc(&bookmarksClient.Client) + automationRulesClient, err := automationrules.NewAutomationRulesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AutomationRules client: %+v", err) + } + configureFunc(automationRulesClient.Client) - dataConnectorsClient := dataconnectors.NewDataConnectorsClientWithBaseURI(endpoint) - configureAuthFunc(&dataConnectorsClient.Client) + bookmarksClient, err := bookmarks.NewBookmarksClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Bookmarks client: %+v", err) + } + configureFunc(bookmarksClient.Client) - entityTypesClient := entitytypes.NewEntityTypesClientWithBaseURI(endpoint) - configureAuthFunc(&entityTypesClient.Client) + dataConnectorsClient, err := dataconnectors.NewDataConnectorsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DataConnectors client: %+v", err) + } + configureFunc(dataConnectorsClient.Client) - incidentAlertsClient := incidentalerts.NewIncidentAlertsClientWithBaseURI(endpoint) - configureAuthFunc(&incidentAlertsClient.Client) + entityTypesClient, err := entitytypes.NewEntityTypesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building EntityTypes client: %+v", err) + } + configureFunc(entityTypesClient.Client) - incidentBookmarksClient := incidentbookmarks.NewIncidentBookmarksClientWithBaseURI(endpoint) - configureAuthFunc(&incidentBookmarksClient.Client) + incidentAlertsClient, err := incidentalerts.NewIncidentAlertsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IncidentAlerts client: %+v", err) + } + configureFunc(incidentAlertsClient.Client) - incidentCommentsClient := incidentcomments.NewIncidentCommentsClientWithBaseURI(endpoint) - configureAuthFunc(&incidentCommentsClient.Client) + incidentBookmarksClient, err := incidentbookmarks.NewIncidentBookmarksClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IncidentBookmarks client: %+v", err) + } + configureFunc(incidentBookmarksClient.Client) - incidentEntitiesClient := incidententities.NewIncidentEntitiesClientWithBaseURI(endpoint) - configureAuthFunc(&incidentEntitiesClient.Client) + incidentCommentsClient, err := incidentcomments.NewIncidentCommentsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IncidentComments client: %+v", err) + } + configureFunc(incidentCommentsClient.Client) - incidentRelationsClient := incidentrelations.NewIncidentRelationsClientWithBaseURI(endpoint) - configureAuthFunc(&incidentRelationsClient.Client) + incidentEntitiesClient, err := incidententities.NewIncidentEntitiesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IncidentEntities client: %+v", err) + } + configureFunc(incidentEntitiesClient.Client) - incidentsClient := incidents.NewIncidentsClientWithBaseURI(endpoint) - configureAuthFunc(&incidentsClient.Client) + incidentRelationsClient, err := incidentrelations.NewIncidentRelationsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IncidentRelations client: %+v", err) + } + configureFunc(incidentRelationsClient.Client) - securityMLAnalyticsSettingsClient := securitymlanalyticssettings.NewSecurityMLAnalyticsSettingsClientWithBaseURI(endpoint) - configureAuthFunc(&securityMLAnalyticsSettingsClient.Client) + incidentsClient, err := incidents.NewIncidentsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Incidents client: %+v", err) + } + configureFunc(incidentsClient.Client) - sentinelOnboardingStatesClient := sentinelonboardingstates.NewSentinelOnboardingStatesClientWithBaseURI(endpoint) - configureAuthFunc(&sentinelOnboardingStatesClient.Client) + securityMLAnalyticsSettingsClient, err := securitymlanalyticssettings.NewSecurityMLAnalyticsSettingsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SecurityMLAnalyticsSettings client: %+v", err) + } + configureFunc(securityMLAnalyticsSettingsClient.Client) - threatIntelligenceClient := threatintelligence.NewThreatIntelligenceClientWithBaseURI(endpoint) - configureAuthFunc(&threatIntelligenceClient.Client) + sentinelOnboardingStatesClient, err := sentinelonboardingstates.NewSentinelOnboardingStatesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SentinelOnboardingStates client: %+v", err) + } + configureFunc(sentinelOnboardingStatesClient.Client) - watchlistItemsClient := watchlistitems.NewWatchlistItemsClientWithBaseURI(endpoint) - configureAuthFunc(&watchlistItemsClient.Client) + threatIntelligenceClient, err := threatintelligence.NewThreatIntelligenceClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ThreatIntelligence client: %+v", err) + } + configureFunc(threatIntelligenceClient.Client) - watchlistsClient := watchlists.NewWatchlistsClientWithBaseURI(endpoint) - configureAuthFunc(&watchlistsClient.Client) + watchlistItemsClient, err := watchlistitems.NewWatchlistItemsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building WatchlistItems client: %+v", err) + } + configureFunc(watchlistItemsClient.Client) - return Client{ - Actions: &actionsClient, - AlertRuleTemplates: &alertRuleTemplatesClient, - AlertRules: &alertRulesClient, - AutomationRules: &automationRulesClient, - Bookmarks: &bookmarksClient, - DataConnectors: &dataConnectorsClient, - EntityTypes: &entityTypesClient, - IncidentAlerts: &incidentAlertsClient, - IncidentBookmarks: &incidentBookmarksClient, - IncidentComments: &incidentCommentsClient, - IncidentEntities: &incidentEntitiesClient, - IncidentRelations: &incidentRelationsClient, - Incidents: &incidentsClient, - SecurityMLAnalyticsSettings: &securityMLAnalyticsSettingsClient, - SentinelOnboardingStates: &sentinelOnboardingStatesClient, - ThreatIntelligence: &threatIntelligenceClient, - WatchlistItems: &watchlistItemsClient, - Watchlists: &watchlistsClient, + watchlistsClient, err := watchlists.NewWatchlistsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Watchlists client: %+v", err) } + configureFunc(watchlistsClient.Client) + + return &Client{ + Actions: actionsClient, + AlertRuleTemplates: alertRuleTemplatesClient, + AlertRules: alertRulesClient, + AutomationRules: automationRulesClient, + Bookmarks: bookmarksClient, + DataConnectors: dataConnectorsClient, + EntityTypes: entityTypesClient, + IncidentAlerts: incidentAlertsClient, + IncidentBookmarks: incidentBookmarksClient, + IncidentComments: incidentCommentsClient, + IncidentEntities: incidentEntitiesClient, + IncidentRelations: incidentRelationsClient, + Incidents: incidentsClient, + SecurityMLAnalyticsSettings: securityMLAnalyticsSettingsClient, + SentinelOnboardingStates: sentinelOnboardingStatesClient, + ThreatIntelligence: threatIntelligenceClient, + WatchlistItems: watchlistItemsClient, + Watchlists: watchlistsClient, + }, nil } diff --git a/resource-manager/securityinsights/2022-11-01/dataconnectors/client.go b/resource-manager/securityinsights/2022-11-01/dataconnectors/client.go index cf334b72568..8ed0120c79a 100644 --- a/resource-manager/securityinsights/2022-11-01/dataconnectors/client.go +++ b/resource-manager/securityinsights/2022-11-01/dataconnectors/client.go @@ -1,18 +1,26 @@ package dataconnectors -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type DataConnectorsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewDataConnectorsClientWithBaseURI(endpoint string) DataConnectorsClient { - return DataConnectorsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewDataConnectorsClientWithBaseURI(sdkApi sdkEnv.Api) (*DataConnectorsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "dataconnectors", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DataConnectorsClient: %+v", err) } + + return &DataConnectorsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-11-01/dataconnectors/constants.go b/resource-manager/securityinsights/2022-11-01/dataconnectors/constants.go index db98dc83577..3fb78689b33 100644 --- a/resource-manager/securityinsights/2022-11-01/dataconnectors/constants.go +++ b/resource-manager/securityinsights/2022-11-01/dataconnectors/constants.go @@ -1,6 +1,10 @@ package dataconnectors -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -31,6 +35,19 @@ func PossibleValuesForDataConnectorKind() []string { } } +func (s *DataConnectorKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataConnectorKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDataConnectorKind(input string) (*DataConnectorKind, error) { vals := map[string]DataConnectorKind{ "amazonwebservicescloudtrail": DataConnectorKindAmazonWebServicesCloudTrail, @@ -65,6 +82,19 @@ func PossibleValuesForDataTypeState() []string { } } +func (s *DataTypeState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataTypeState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDataTypeState(input string) (*DataTypeState, error) { vals := map[string]DataTypeState{ "disabled": DataTypeStateDisabled, diff --git a/resource-manager/securityinsights/2022-11-01/dataconnectors/method_createorupdate.go b/resource-manager/securityinsights/2022-11-01/dataconnectors/method_createorupdate.go new file mode 100644 index 00000000000..c5f6e5d1503 --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/dataconnectors/method_createorupdate.go @@ -0,0 +1,63 @@ +package dataconnectors + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DataConnector +} + +// CreateOrUpdate ... +func (c DataConnectorsClient) CreateOrUpdate(ctx context.Context, id DataConnectorId, input DataConnector) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalDataConnectorImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/dataconnectors/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-11-01/dataconnectors/method_createorupdate_autorest.go deleted file mode 100644 index 1f259eca36c..00000000000 --- a/resource-manager/securityinsights/2022-11-01/dataconnectors/method_createorupdate_autorest.go +++ /dev/null @@ -1,78 +0,0 @@ -package dataconnectors - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *DataConnector -} - -// CreateOrUpdate ... -func (c DataConnectorsClient) CreateOrUpdate(ctx context.Context, id DataConnectorId, input DataConnector) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c DataConnectorsClient) preparerForCreateOrUpdate(ctx context.Context, id DataConnectorId, input DataConnector) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c DataConnectorsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalDataConnectorImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-11-01/dataconnectors/method_delete.go b/resource-manager/securityinsights/2022-11-01/dataconnectors/method_delete.go new file mode 100644 index 00000000000..8461ec6d8a1 --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/dataconnectors/method_delete.go @@ -0,0 +1,47 @@ +package dataconnectors + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c DataConnectorsClient) Delete(ctx context.Context, id DataConnectorId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/dataconnectors/method_delete_autorest.go b/resource-manager/securityinsights/2022-11-01/dataconnectors/method_delete_autorest.go deleted file mode 100644 index ac4ddf57441..00000000000 --- a/resource-manager/securityinsights/2022-11-01/dataconnectors/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package dataconnectors - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c DataConnectorsClient) Delete(ctx context.Context, id DataConnectorId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c DataConnectorsClient) preparerForDelete(ctx context.Context, id DataConnectorId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c DataConnectorsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-11-01/dataconnectors/method_get.go b/resource-manager/securityinsights/2022-11-01/dataconnectors/method_get.go new file mode 100644 index 00000000000..3511ba85477 --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/dataconnectors/method_get.go @@ -0,0 +1,58 @@ +package dataconnectors + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DataConnector +} + +// Get ... +func (c DataConnectorsClient) Get(ctx context.Context, id DataConnectorId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalDataConnectorImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/dataconnectors/method_get_autorest.go b/resource-manager/securityinsights/2022-11-01/dataconnectors/method_get_autorest.go deleted file mode 100644 index af56be19c9c..00000000000 --- a/resource-manager/securityinsights/2022-11-01/dataconnectors/method_get_autorest.go +++ /dev/null @@ -1,77 +0,0 @@ -package dataconnectors - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *DataConnector -} - -// Get ... -func (c DataConnectorsClient) Get(ctx context.Context, id DataConnectorId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c DataConnectorsClient) preparerForGet(ctx context.Context, id DataConnectorId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c DataConnectorsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalDataConnectorImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-11-01/dataconnectors/method_list.go b/resource-manager/securityinsights/2022-11-01/dataconnectors/method_list.go new file mode 100644 index 00000000000..6975384fdee --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/dataconnectors/method_list.go @@ -0,0 +1,103 @@ +package dataconnectors + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DataConnector +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []DataConnector +} + +// List ... +func (c DataConnectorsClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/dataConnectors", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]DataConnector, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalDataConnectorImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for DataConnector (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// ListComplete retrieves all the results into a single object +func (c DataConnectorsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, DataConnectorOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DataConnectorsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate DataConnectorOperationPredicate) (result ListCompleteResult, err error) { + items := make([]DataConnector, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-11-01/dataconnectors/method_list_autorest.go b/resource-manager/securityinsights/2022-11-01/dataconnectors/method_list_autorest.go deleted file mode 100644 index e08d153a6eb..00000000000 --- a/resource-manager/securityinsights/2022-11-01/dataconnectors/method_list_autorest.go +++ /dev/null @@ -1,196 +0,0 @@ -package dataconnectors - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]DataConnector - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []DataConnector -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c DataConnectorsClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c DataConnectorsClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/dataConnectors", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c DataConnectorsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c DataConnectorsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]DataConnector, 0) - for i, v := range respObj.Values { - val, err := unmarshalDataConnectorImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for DataConnector (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c DataConnectorsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, DataConnectorOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c DataConnectorsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate DataConnectorOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]DataConnector, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-11-01/entitytypes/client.go b/resource-manager/securityinsights/2022-11-01/entitytypes/client.go index 60583ea834f..bcdd09e4029 100644 --- a/resource-manager/securityinsights/2022-11-01/entitytypes/client.go +++ b/resource-manager/securityinsights/2022-11-01/entitytypes/client.go @@ -1,18 +1,26 @@ package entitytypes -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type EntityTypesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewEntityTypesClientWithBaseURI(endpoint string) EntityTypesClient { - return EntityTypesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewEntityTypesClientWithBaseURI(sdkApi sdkEnv.Api) (*EntityTypesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "entitytypes", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating EntityTypesClient: %+v", err) } + + return &EntityTypesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-11-01/entitytypes/constants.go b/resource-manager/securityinsights/2022-11-01/entitytypes/constants.go index fbe60ce0f02..2f194a6f29d 100644 --- a/resource-manager/securityinsights/2022-11-01/entitytypes/constants.go +++ b/resource-manager/securityinsights/2022-11-01/entitytypes/constants.go @@ -1,6 +1,10 @@ package entitytypes -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -23,6 +27,19 @@ func PossibleValuesForAlertSeverity() []string { } } +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertSeverity(input string) (*AlertSeverity, error) { vals := map[string]AlertSeverity{ "high": AlertSeverityHigh, @@ -59,6 +76,19 @@ func PossibleValuesForAlertStatus() []string { } } +func (s *AlertStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertStatus(input string) (*AlertStatus, error) { vals := map[string]AlertStatus{ "dismissed": AlertStatusDismissed, @@ -94,6 +124,19 @@ func PossibleValuesForAntispamMailDirection() []string { } } +func (s *AntispamMailDirection) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAntispamMailDirection(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAntispamMailDirection(input string) (*AntispamMailDirection, error) { vals := map[string]AntispamMailDirection{ "inbound": AntispamMailDirectionInbound, @@ -154,6 +197,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -199,6 +255,19 @@ func PossibleValuesForConfidenceLevel() []string { } } +func (s *ConfidenceLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceLevel(input string) (*ConfidenceLevel, error) { vals := map[string]ConfidenceLevel{ "high": ConfidenceLevelHigh, @@ -232,6 +301,19 @@ func PossibleValuesForConfidenceScoreStatus() []string { } } +func (s *ConfidenceScoreStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceScoreStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceScoreStatus(input string) (*ConfidenceScoreStatus, error) { vals := map[string]ConfidenceScoreStatus{ "final": ConfidenceScoreStatusFinal, @@ -266,6 +348,19 @@ func PossibleValuesForCreatedByType() []string { } } +func (s *CreatedByType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCreatedByType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseCreatedByType(input string) (*CreatedByType, error) { vals := map[string]CreatedByType{ "application": CreatedByTypeApplication, @@ -302,6 +397,19 @@ func PossibleValuesForDeliveryAction() []string { } } +func (s *DeliveryAction) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeliveryAction(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDeliveryAction(input string) (*DeliveryAction, error) { vals := map[string]DeliveryAction{ "blocked": DeliveryActionBlocked, @@ -347,6 +455,19 @@ func PossibleValuesForDeliveryLocation() []string { } } +func (s *DeliveryLocation) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeliveryLocation(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDeliveryLocation(input string) (*DeliveryLocation, error) { vals := map[string]DeliveryLocation{ "deletedfolder": DeliveryLocationDeletedFolder, @@ -384,6 +505,19 @@ func PossibleValuesForElevationToken() []string { } } +func (s *ElevationToken) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseElevationToken(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseElevationToken(input string) (*ElevationToken, error) { vals := map[string]ElevationToken{ "default": ElevationTokenDefault, @@ -451,6 +585,19 @@ func PossibleValuesForEntityKindEnum() []string { } } +func (s *EntityKindEnum) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityKindEnum(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityKindEnum(input string) (*EntityKindEnum, error) { vals := map[string]EntityKindEnum{ "account": EntityKindEnumAccount, @@ -504,6 +651,19 @@ func PossibleValuesForFileHashAlgorithm() []string { } } +func (s *FileHashAlgorithm) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseFileHashAlgorithm(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseFileHashAlgorithm(input string) (*FileHashAlgorithm, error) { vals := map[string]FileHashAlgorithm{ "md5": FileHashAlgorithmMDFive, @@ -539,6 +699,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, @@ -593,6 +766,19 @@ func PossibleValuesForKillChainIntent() []string { } } +func (s *KillChainIntent) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKillChainIntent(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseKillChainIntent(input string) (*KillChainIntent, error) { vals := map[string]KillChainIntent{ "collection": KillChainIntentCollection, @@ -639,6 +825,19 @@ func PossibleValuesForOSFamily() []string { } } +func (s *OSFamily) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOSFamily(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseOSFamily(input string) (*OSFamily, error) { vals := map[string]OSFamily{ "android": OSFamilyAndroid, @@ -686,6 +885,19 @@ func PossibleValuesForRegistryHive() []string { } } +func (s *RegistryHive) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRegistryHive(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseRegistryHive(input string) (*RegistryHive, error) { vals := map[string]RegistryHive{ "hkey_a": RegistryHiveHKEYA, @@ -734,6 +946,19 @@ func PossibleValuesForRegistryValueKind() []string { } } +func (s *RegistryValueKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRegistryValueKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseRegistryValueKind(input string) (*RegistryValueKind, error) { vals := map[string]RegistryValueKind{ "binary": RegistryValueKindBinary, diff --git a/resource-manager/securityinsights/2022-11-01/incidentalerts/client.go b/resource-manager/securityinsights/2022-11-01/incidentalerts/client.go index ae19637d473..53dc2b4cd4e 100644 --- a/resource-manager/securityinsights/2022-11-01/incidentalerts/client.go +++ b/resource-manager/securityinsights/2022-11-01/incidentalerts/client.go @@ -1,18 +1,26 @@ package incidentalerts -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type IncidentAlertsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewIncidentAlertsClientWithBaseURI(endpoint string) IncidentAlertsClient { - return IncidentAlertsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewIncidentAlertsClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentAlertsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidentalerts", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentAlertsClient: %+v", err) } + + return &IncidentAlertsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-11-01/incidentalerts/constants.go b/resource-manager/securityinsights/2022-11-01/incidentalerts/constants.go index 8f605bb09d5..3673d5b1163 100644 --- a/resource-manager/securityinsights/2022-11-01/incidentalerts/constants.go +++ b/resource-manager/securityinsights/2022-11-01/incidentalerts/constants.go @@ -1,6 +1,10 @@ package incidentalerts -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -23,6 +27,19 @@ func PossibleValuesForAlertSeverity() []string { } } +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertSeverity(input string) (*AlertSeverity, error) { vals := map[string]AlertSeverity{ "high": AlertSeverityHigh, @@ -59,6 +76,19 @@ func PossibleValuesForAlertStatus() []string { } } +func (s *AlertStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertStatus(input string) (*AlertStatus, error) { vals := map[string]AlertStatus{ "dismissed": AlertStatusDismissed, @@ -120,6 +150,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -165,6 +208,19 @@ func PossibleValuesForConfidenceLevel() []string { } } +func (s *ConfidenceLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceLevel(input string) (*ConfidenceLevel, error) { vals := map[string]ConfidenceLevel{ "high": ConfidenceLevelHigh, @@ -198,6 +254,19 @@ func PossibleValuesForConfidenceScoreStatus() []string { } } +func (s *ConfidenceScoreStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceScoreStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceScoreStatus(input string) (*ConfidenceScoreStatus, error) { vals := map[string]ConfidenceScoreStatus{ "final": ConfidenceScoreStatusFinal, @@ -266,6 +335,19 @@ func PossibleValuesForEntityKindEnum() []string { } } +func (s *EntityKindEnum) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityKindEnum(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityKindEnum(input string) (*EntityKindEnum, error) { vals := map[string]EntityKindEnum{ "account": EntityKindEnumAccount, @@ -317,6 +399,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, @@ -371,6 +466,19 @@ func PossibleValuesForKillChainIntent() []string { } } +func (s *KillChainIntent) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKillChainIntent(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseKillChainIntent(input string) (*KillChainIntent, error) { vals := map[string]KillChainIntent{ "collection": KillChainIntentCollection, diff --git a/resource-manager/securityinsights/2022-11-01/incidentalerts/method_incidentslistalerts.go b/resource-manager/securityinsights/2022-11-01/incidentalerts/method_incidentslistalerts.go new file mode 100644 index 00000000000..fe83693eae2 --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/incidentalerts/method_incidentslistalerts.go @@ -0,0 +1,52 @@ +package incidentalerts + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentsListAlertsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IncidentAlertList +} + +// IncidentsListAlerts ... +func (c IncidentAlertsClient) IncidentsListAlerts(ctx context.Context, id IncidentId) (result IncidentsListAlertsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/alerts", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/incidentalerts/method_incidentslistalerts_autorest.go b/resource-manager/securityinsights/2022-11-01/incidentalerts/method_incidentslistalerts_autorest.go deleted file mode 100644 index de6c08e09a2..00000000000 --- a/resource-manager/securityinsights/2022-11-01/incidentalerts/method_incidentslistalerts_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package incidentalerts - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IncidentsListAlertsOperationResponse struct { - HttpResponse *http.Response - Model *IncidentAlertList -} - -// IncidentsListAlerts ... -func (c IncidentAlertsClient) IncidentsListAlerts(ctx context.Context, id IncidentId) (result IncidentsListAlertsOperationResponse, err error) { - req, err := c.preparerForIncidentsListAlerts(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentalerts.IncidentAlertsClient", "IncidentsListAlerts", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentalerts.IncidentAlertsClient", "IncidentsListAlerts", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIncidentsListAlerts(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentalerts.IncidentAlertsClient", "IncidentsListAlerts", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIncidentsListAlerts prepares the IncidentsListAlerts request. -func (c IncidentAlertsClient) preparerForIncidentsListAlerts(ctx context.Context, id IncidentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/alerts", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIncidentsListAlerts handles the response to the IncidentsListAlerts request. The method always -// closes the http.Response Body. -func (c IncidentAlertsClient) responderForIncidentsListAlerts(resp *http.Response) (result IncidentsListAlertsOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-11-01/incidentbookmarks/client.go b/resource-manager/securityinsights/2022-11-01/incidentbookmarks/client.go index e2fcca6728b..e6a60ede52d 100644 --- a/resource-manager/securityinsights/2022-11-01/incidentbookmarks/client.go +++ b/resource-manager/securityinsights/2022-11-01/incidentbookmarks/client.go @@ -1,18 +1,26 @@ package incidentbookmarks -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type IncidentBookmarksClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewIncidentBookmarksClientWithBaseURI(endpoint string) IncidentBookmarksClient { - return IncidentBookmarksClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewIncidentBookmarksClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentBookmarksClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidentbookmarks", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentBookmarksClient: %+v", err) } + + return &IncidentBookmarksClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-11-01/incidentbookmarks/constants.go b/resource-manager/securityinsights/2022-11-01/incidentbookmarks/constants.go index 7080e0657bc..27f31cfcc5e 100644 --- a/resource-manager/securityinsights/2022-11-01/incidentbookmarks/constants.go +++ b/resource-manager/securityinsights/2022-11-01/incidentbookmarks/constants.go @@ -1,6 +1,10 @@ package incidentbookmarks -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -23,6 +27,19 @@ func PossibleValuesForAlertSeverity() []string { } } +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertSeverity(input string) (*AlertSeverity, error) { vals := map[string]AlertSeverity{ "high": AlertSeverityHigh, @@ -59,6 +76,19 @@ func PossibleValuesForAlertStatus() []string { } } +func (s *AlertStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertStatus(input string) (*AlertStatus, error) { vals := map[string]AlertStatus{ "dismissed": AlertStatusDismissed, @@ -120,6 +150,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -165,6 +208,19 @@ func PossibleValuesForConfidenceLevel() []string { } } +func (s *ConfidenceLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceLevel(input string) (*ConfidenceLevel, error) { vals := map[string]ConfidenceLevel{ "high": ConfidenceLevelHigh, @@ -198,6 +254,19 @@ func PossibleValuesForConfidenceScoreStatus() []string { } } +func (s *ConfidenceScoreStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceScoreStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceScoreStatus(input string) (*ConfidenceScoreStatus, error) { vals := map[string]ConfidenceScoreStatus{ "final": ConfidenceScoreStatusFinal, @@ -266,6 +335,19 @@ func PossibleValuesForEntityKindEnum() []string { } } +func (s *EntityKindEnum) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityKindEnum(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityKindEnum(input string) (*EntityKindEnum, error) { vals := map[string]EntityKindEnum{ "account": EntityKindEnumAccount, @@ -317,6 +399,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, @@ -371,6 +466,19 @@ func PossibleValuesForKillChainIntent() []string { } } +func (s *KillChainIntent) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKillChainIntent(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseKillChainIntent(input string) (*KillChainIntent, error) { vals := map[string]KillChainIntent{ "collection": KillChainIntentCollection, diff --git a/resource-manager/securityinsights/2022-11-01/incidentbookmarks/method_incidentslistbookmarks.go b/resource-manager/securityinsights/2022-11-01/incidentbookmarks/method_incidentslistbookmarks.go new file mode 100644 index 00000000000..3ac7b9e8b2e --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/incidentbookmarks/method_incidentslistbookmarks.go @@ -0,0 +1,52 @@ +package incidentbookmarks + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentsListBookmarksOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IncidentBookmarkList +} + +// IncidentsListBookmarks ... +func (c IncidentBookmarksClient) IncidentsListBookmarks(ctx context.Context, id IncidentId) (result IncidentsListBookmarksOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/bookmarks", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/incidentbookmarks/method_incidentslistbookmarks_autorest.go b/resource-manager/securityinsights/2022-11-01/incidentbookmarks/method_incidentslistbookmarks_autorest.go deleted file mode 100644 index a5c3a89a09c..00000000000 --- a/resource-manager/securityinsights/2022-11-01/incidentbookmarks/method_incidentslistbookmarks_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package incidentbookmarks - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IncidentsListBookmarksOperationResponse struct { - HttpResponse *http.Response - Model *IncidentBookmarkList -} - -// IncidentsListBookmarks ... -func (c IncidentBookmarksClient) IncidentsListBookmarks(ctx context.Context, id IncidentId) (result IncidentsListBookmarksOperationResponse, err error) { - req, err := c.preparerForIncidentsListBookmarks(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentbookmarks.IncidentBookmarksClient", "IncidentsListBookmarks", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentbookmarks.IncidentBookmarksClient", "IncidentsListBookmarks", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIncidentsListBookmarks(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentbookmarks.IncidentBookmarksClient", "IncidentsListBookmarks", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIncidentsListBookmarks prepares the IncidentsListBookmarks request. -func (c IncidentBookmarksClient) preparerForIncidentsListBookmarks(ctx context.Context, id IncidentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/bookmarks", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIncidentsListBookmarks handles the response to the IncidentsListBookmarks request. The method always -// closes the http.Response Body. -func (c IncidentBookmarksClient) responderForIncidentsListBookmarks(resp *http.Response) (result IncidentsListBookmarksOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-11-01/incidentcomments/client.go b/resource-manager/securityinsights/2022-11-01/incidentcomments/client.go index 4006779247d..981e6f75216 100644 --- a/resource-manager/securityinsights/2022-11-01/incidentcomments/client.go +++ b/resource-manager/securityinsights/2022-11-01/incidentcomments/client.go @@ -1,18 +1,26 @@ package incidentcomments -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type IncidentCommentsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewIncidentCommentsClientWithBaseURI(endpoint string) IncidentCommentsClient { - return IncidentCommentsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewIncidentCommentsClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentCommentsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidentcomments", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentCommentsClient: %+v", err) } + + return &IncidentCommentsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-11-01/incidentcomments/method_createorupdate.go b/resource-manager/securityinsights/2022-11-01/incidentcomments/method_createorupdate.go new file mode 100644 index 00000000000..5c59b2be8d3 --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/incidentcomments/method_createorupdate.go @@ -0,0 +1,56 @@ +package incidentcomments + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IncidentComment +} + +// CreateOrUpdate ... +func (c IncidentCommentsClient) CreateOrUpdate(ctx context.Context, id CommentId, input IncidentComment) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/incidentcomments/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-11-01/incidentcomments/method_createorupdate_autorest.go deleted file mode 100644 index b27777aad2c..00000000000 --- a/resource-manager/securityinsights/2022-11-01/incidentcomments/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package incidentcomments - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *IncidentComment -} - -// CreateOrUpdate ... -func (c IncidentCommentsClient) CreateOrUpdate(ctx context.Context, id CommentId, input IncidentComment) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c IncidentCommentsClient) preparerForCreateOrUpdate(ctx context.Context, id CommentId, input IncidentComment) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c IncidentCommentsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-11-01/incidentcomments/method_delete.go b/resource-manager/securityinsights/2022-11-01/incidentcomments/method_delete.go new file mode 100644 index 00000000000..78412a13e76 --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/incidentcomments/method_delete.go @@ -0,0 +1,47 @@ +package incidentcomments + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c IncidentCommentsClient) Delete(ctx context.Context, id CommentId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/incidentcomments/method_delete_autorest.go b/resource-manager/securityinsights/2022-11-01/incidentcomments/method_delete_autorest.go deleted file mode 100644 index 6bbb4c92cbf..00000000000 --- a/resource-manager/securityinsights/2022-11-01/incidentcomments/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package incidentcomments - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c IncidentCommentsClient) Delete(ctx context.Context, id CommentId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c IncidentCommentsClient) preparerForDelete(ctx context.Context, id CommentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c IncidentCommentsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-11-01/incidentcomments/method_get.go b/resource-manager/securityinsights/2022-11-01/incidentcomments/method_get.go new file mode 100644 index 00000000000..e8d11306ddb --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/incidentcomments/method_get.go @@ -0,0 +1,51 @@ +package incidentcomments + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IncidentComment +} + +// Get ... +func (c IncidentCommentsClient) Get(ctx context.Context, id CommentId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/incidentcomments/method_get_autorest.go b/resource-manager/securityinsights/2022-11-01/incidentcomments/method_get_autorest.go deleted file mode 100644 index 8402ed77e94..00000000000 --- a/resource-manager/securityinsights/2022-11-01/incidentcomments/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package incidentcomments - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *IncidentComment -} - -// Get ... -func (c IncidentCommentsClient) Get(ctx context.Context, id CommentId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c IncidentCommentsClient) preparerForGet(ctx context.Context, id CommentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c IncidentCommentsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-11-01/incidentcomments/method_list.go b/resource-manager/securityinsights/2022-11-01/incidentcomments/method_list.go new file mode 100644 index 00000000000..b4c16058b38 --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/incidentcomments/method_list.go @@ -0,0 +1,127 @@ +package incidentcomments + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]IncidentComment +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []IncidentComment +} + +type ListOperationOptions struct { + Filter *string + Orderby *string + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c IncidentCommentsClient) List(ctx context.Context, id IncidentId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/comments", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]IncidentComment `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c IncidentCommentsClient) ListComplete(ctx context.Context, id IncidentId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, IncidentCommentOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c IncidentCommentsClient) ListCompleteMatchingPredicate(ctx context.Context, id IncidentId, options ListOperationOptions, predicate IncidentCommentOperationPredicate) (result ListCompleteResult, err error) { + items := make([]IncidentComment, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-11-01/incidentcomments/method_list_autorest.go b/resource-manager/securityinsights/2022-11-01/incidentcomments/method_list_autorest.go deleted file mode 100644 index 24fb8d1d7e7..00000000000 --- a/resource-manager/securityinsights/2022-11-01/incidentcomments/method_list_autorest.go +++ /dev/null @@ -1,225 +0,0 @@ -package incidentcomments - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]IncidentComment - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []IncidentComment -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ListOperationOptions struct { - Filter *string - Orderby *string - Top *int64 -} - -func DefaultListOperationOptions() ListOperationOptions { - return ListOperationOptions{} -} - -func (o ListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Filter != nil { - out["$filter"] = *o.Filter - } - - if o.Orderby != nil { - out["$orderby"] = *o.Orderby - } - - if o.Top != nil { - out["$top"] = *o.Top - } - - return out -} - -// List ... -func (c IncidentCommentsClient) List(ctx context.Context, id IncidentId, options ListOperationOptions) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c IncidentCommentsClient) preparerForList(ctx context.Context, id IncidentId, options ListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/comments", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c IncidentCommentsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c IncidentCommentsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []IncidentComment `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c IncidentCommentsClient) ListComplete(ctx context.Context, id IncidentId, options ListOperationOptions) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, options, IncidentCommentOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c IncidentCommentsClient) ListCompleteMatchingPredicate(ctx context.Context, id IncidentId, options ListOperationOptions, predicate IncidentCommentOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]IncidentComment, 0) - - page, err := c.List(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-11-01/incidententities/client.go b/resource-manager/securityinsights/2022-11-01/incidententities/client.go index 5f0eaf07782..740e7b81755 100644 --- a/resource-manager/securityinsights/2022-11-01/incidententities/client.go +++ b/resource-manager/securityinsights/2022-11-01/incidententities/client.go @@ -1,18 +1,26 @@ package incidententities -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type IncidentEntitiesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewIncidentEntitiesClientWithBaseURI(endpoint string) IncidentEntitiesClient { - return IncidentEntitiesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewIncidentEntitiesClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentEntitiesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidententities", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentEntitiesClient: %+v", err) } + + return &IncidentEntitiesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-11-01/incidententities/constants.go b/resource-manager/securityinsights/2022-11-01/incidententities/constants.go index cb1b487a229..a1d54eb28d0 100644 --- a/resource-manager/securityinsights/2022-11-01/incidententities/constants.go +++ b/resource-manager/securityinsights/2022-11-01/incidententities/constants.go @@ -1,6 +1,10 @@ package incidententities -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -23,6 +27,19 @@ func PossibleValuesForAlertSeverity() []string { } } +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertSeverity(input string) (*AlertSeverity, error) { vals := map[string]AlertSeverity{ "high": AlertSeverityHigh, @@ -59,6 +76,19 @@ func PossibleValuesForAlertStatus() []string { } } +func (s *AlertStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertStatus(input string) (*AlertStatus, error) { vals := map[string]AlertStatus{ "dismissed": AlertStatusDismissed, @@ -120,6 +150,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -165,6 +208,19 @@ func PossibleValuesForConfidenceLevel() []string { } } +func (s *ConfidenceLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceLevel(input string) (*ConfidenceLevel, error) { vals := map[string]ConfidenceLevel{ "high": ConfidenceLevelHigh, @@ -198,6 +254,19 @@ func PossibleValuesForConfidenceScoreStatus() []string { } } +func (s *ConfidenceScoreStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceScoreStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceScoreStatus(input string) (*ConfidenceScoreStatus, error) { vals := map[string]ConfidenceScoreStatus{ "final": ConfidenceScoreStatusFinal, @@ -266,6 +335,19 @@ func PossibleValuesForEntityKindEnum() []string { } } +func (s *EntityKindEnum) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityKindEnum(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityKindEnum(input string) (*EntityKindEnum, error) { vals := map[string]EntityKindEnum{ "account": EntityKindEnumAccount, @@ -317,6 +399,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, @@ -371,6 +466,19 @@ func PossibleValuesForKillChainIntent() []string { } } +func (s *KillChainIntent) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKillChainIntent(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseKillChainIntent(input string) (*KillChainIntent, error) { vals := map[string]KillChainIntent{ "collection": KillChainIntentCollection, diff --git a/resource-manager/securityinsights/2022-11-01/incidententities/method_incidentslistentities.go b/resource-manager/securityinsights/2022-11-01/incidententities/method_incidentslistentities.go new file mode 100644 index 00000000000..36ec8f0c75b --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/incidententities/method_incidentslistentities.go @@ -0,0 +1,52 @@ +package incidententities + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentsListEntitiesOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IncidentEntitiesResponse +} + +// IncidentsListEntities ... +func (c IncidentEntitiesClient) IncidentsListEntities(ctx context.Context, id IncidentId) (result IncidentsListEntitiesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/entities", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/incidententities/method_incidentslistentities_autorest.go b/resource-manager/securityinsights/2022-11-01/incidententities/method_incidentslistentities_autorest.go deleted file mode 100644 index 9d796d431cb..00000000000 --- a/resource-manager/securityinsights/2022-11-01/incidententities/method_incidentslistentities_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package incidententities - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IncidentsListEntitiesOperationResponse struct { - HttpResponse *http.Response - Model *IncidentEntitiesResponse -} - -// IncidentsListEntities ... -func (c IncidentEntitiesClient) IncidentsListEntities(ctx context.Context, id IncidentId) (result IncidentsListEntitiesOperationResponse, err error) { - req, err := c.preparerForIncidentsListEntities(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidententities.IncidentEntitiesClient", "IncidentsListEntities", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidententities.IncidentEntitiesClient", "IncidentsListEntities", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIncidentsListEntities(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidententities.IncidentEntitiesClient", "IncidentsListEntities", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIncidentsListEntities prepares the IncidentsListEntities request. -func (c IncidentEntitiesClient) preparerForIncidentsListEntities(ctx context.Context, id IncidentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/entities", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIncidentsListEntities handles the response to the IncidentsListEntities request. The method always -// closes the http.Response Body. -func (c IncidentEntitiesClient) responderForIncidentsListEntities(resp *http.Response) (result IncidentsListEntitiesOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-11-01/incidentrelations/client.go b/resource-manager/securityinsights/2022-11-01/incidentrelations/client.go index 58aa27c43e8..4e8fbfeb71d 100644 --- a/resource-manager/securityinsights/2022-11-01/incidentrelations/client.go +++ b/resource-manager/securityinsights/2022-11-01/incidentrelations/client.go @@ -1,18 +1,26 @@ package incidentrelations -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type IncidentRelationsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewIncidentRelationsClientWithBaseURI(endpoint string) IncidentRelationsClient { - return IncidentRelationsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewIncidentRelationsClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentRelationsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidentrelations", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentRelationsClient: %+v", err) } + + return &IncidentRelationsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-11-01/incidentrelations/method_createorupdate.go b/resource-manager/securityinsights/2022-11-01/incidentrelations/method_createorupdate.go new file mode 100644 index 00000000000..4b4ff3d56f8 --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/incidentrelations/method_createorupdate.go @@ -0,0 +1,56 @@ +package incidentrelations + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Relation +} + +// CreateOrUpdate ... +func (c IncidentRelationsClient) CreateOrUpdate(ctx context.Context, id RelationId, input Relation) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/incidentrelations/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-11-01/incidentrelations/method_createorupdate_autorest.go deleted file mode 100644 index 79cf52b5347..00000000000 --- a/resource-manager/securityinsights/2022-11-01/incidentrelations/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package incidentrelations - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *Relation -} - -// CreateOrUpdate ... -func (c IncidentRelationsClient) CreateOrUpdate(ctx context.Context, id RelationId, input Relation) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c IncidentRelationsClient) preparerForCreateOrUpdate(ctx context.Context, id RelationId, input Relation) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c IncidentRelationsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-11-01/incidentrelations/method_delete.go b/resource-manager/securityinsights/2022-11-01/incidentrelations/method_delete.go new file mode 100644 index 00000000000..de3afbf47c9 --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/incidentrelations/method_delete.go @@ -0,0 +1,47 @@ +package incidentrelations + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c IncidentRelationsClient) Delete(ctx context.Context, id RelationId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/incidentrelations/method_delete_autorest.go b/resource-manager/securityinsights/2022-11-01/incidentrelations/method_delete_autorest.go deleted file mode 100644 index 9003689e999..00000000000 --- a/resource-manager/securityinsights/2022-11-01/incidentrelations/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package incidentrelations - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c IncidentRelationsClient) Delete(ctx context.Context, id RelationId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c IncidentRelationsClient) preparerForDelete(ctx context.Context, id RelationId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c IncidentRelationsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-11-01/incidentrelations/method_get.go b/resource-manager/securityinsights/2022-11-01/incidentrelations/method_get.go new file mode 100644 index 00000000000..7cc37b68825 --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/incidentrelations/method_get.go @@ -0,0 +1,51 @@ +package incidentrelations + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Relation +} + +// Get ... +func (c IncidentRelationsClient) Get(ctx context.Context, id RelationId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/incidentrelations/method_get_autorest.go b/resource-manager/securityinsights/2022-11-01/incidentrelations/method_get_autorest.go deleted file mode 100644 index a8b88ddecb4..00000000000 --- a/resource-manager/securityinsights/2022-11-01/incidentrelations/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package incidentrelations - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *Relation -} - -// Get ... -func (c IncidentRelationsClient) Get(ctx context.Context, id RelationId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c IncidentRelationsClient) preparerForGet(ctx context.Context, id RelationId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c IncidentRelationsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-11-01/incidentrelations/method_list.go b/resource-manager/securityinsights/2022-11-01/incidentrelations/method_list.go new file mode 100644 index 00000000000..80873d441b4 --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/incidentrelations/method_list.go @@ -0,0 +1,127 @@ +package incidentrelations + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Relation +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Relation +} + +type ListOperationOptions struct { + Filter *string + Orderby *string + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c IncidentRelationsClient) List(ctx context.Context, id IncidentId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/relations", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Relation `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c IncidentRelationsClient) ListComplete(ctx context.Context, id IncidentId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, RelationOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c IncidentRelationsClient) ListCompleteMatchingPredicate(ctx context.Context, id IncidentId, options ListOperationOptions, predicate RelationOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Relation, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-11-01/incidentrelations/method_list_autorest.go b/resource-manager/securityinsights/2022-11-01/incidentrelations/method_list_autorest.go deleted file mode 100644 index a270a442886..00000000000 --- a/resource-manager/securityinsights/2022-11-01/incidentrelations/method_list_autorest.go +++ /dev/null @@ -1,225 +0,0 @@ -package incidentrelations - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]Relation - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []Relation -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ListOperationOptions struct { - Filter *string - Orderby *string - Top *int64 -} - -func DefaultListOperationOptions() ListOperationOptions { - return ListOperationOptions{} -} - -func (o ListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Filter != nil { - out["$filter"] = *o.Filter - } - - if o.Orderby != nil { - out["$orderby"] = *o.Orderby - } - - if o.Top != nil { - out["$top"] = *o.Top - } - - return out -} - -// List ... -func (c IncidentRelationsClient) List(ctx context.Context, id IncidentId, options ListOperationOptions) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c IncidentRelationsClient) preparerForList(ctx context.Context, id IncidentId, options ListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/relations", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c IncidentRelationsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c IncidentRelationsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []Relation `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c IncidentRelationsClient) ListComplete(ctx context.Context, id IncidentId, options ListOperationOptions) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, options, RelationOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c IncidentRelationsClient) ListCompleteMatchingPredicate(ctx context.Context, id IncidentId, options ListOperationOptions, predicate RelationOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]Relation, 0) - - page, err := c.List(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-11-01/incidents/client.go b/resource-manager/securityinsights/2022-11-01/incidents/client.go index 659897d18d7..aaf38071c39 100644 --- a/resource-manager/securityinsights/2022-11-01/incidents/client.go +++ b/resource-manager/securityinsights/2022-11-01/incidents/client.go @@ -1,18 +1,26 @@ package incidents -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type IncidentsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewIncidentsClientWithBaseURI(endpoint string) IncidentsClient { - return IncidentsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewIncidentsClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidents", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentsClient: %+v", err) } + + return &IncidentsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-11-01/incidents/constants.go b/resource-manager/securityinsights/2022-11-01/incidents/constants.go index 82782d4107f..ce046b9edba 100644 --- a/resource-manager/securityinsights/2022-11-01/incidents/constants.go +++ b/resource-manager/securityinsights/2022-11-01/incidents/constants.go @@ -1,6 +1,10 @@ package incidents -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -49,6 +53,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -96,6 +113,19 @@ func PossibleValuesForIncidentClassification() []string { } } +func (s *IncidentClassification) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentClassification(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentClassification(input string) (*IncidentClassification, error) { vals := map[string]IncidentClassification{ "benignpositive": IncidentClassificationBenignPositive, @@ -130,6 +160,19 @@ func PossibleValuesForIncidentClassificationReason() []string { } } +func (s *IncidentClassificationReason) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentClassificationReason(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentClassificationReason(input string) (*IncidentClassificationReason, error) { vals := map[string]IncidentClassificationReason{ "inaccuratedata": IncidentClassificationReasonInaccurateData, @@ -160,6 +203,19 @@ func PossibleValuesForIncidentLabelType() []string { } } +func (s *IncidentLabelType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentLabelType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentLabelType(input string) (*IncidentLabelType, error) { vals := map[string]IncidentLabelType{ "autoassigned": IncidentLabelTypeAutoAssigned, @@ -192,6 +248,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, @@ -224,6 +293,19 @@ func PossibleValuesForIncidentStatus() []string { } } +func (s *IncidentStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentStatus(input string) (*IncidentStatus, error) { vals := map[string]IncidentStatus{ "active": IncidentStatusActive, @@ -255,6 +337,19 @@ func PossibleValuesForOwnerType() []string { } } +func (s *OwnerType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOwnerType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseOwnerType(input string) (*OwnerType, error) { vals := map[string]OwnerType{ "group": OwnerTypeGroup, diff --git a/resource-manager/securityinsights/2022-11-01/incidents/method_createorupdate.go b/resource-manager/securityinsights/2022-11-01/incidents/method_createorupdate.go new file mode 100644 index 00000000000..3fcc110ed02 --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/incidents/method_createorupdate.go @@ -0,0 +1,56 @@ +package incidents + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Incident +} + +// CreateOrUpdate ... +func (c IncidentsClient) CreateOrUpdate(ctx context.Context, id IncidentId, input Incident) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/incidents/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-11-01/incidents/method_createorupdate_autorest.go deleted file mode 100644 index 837aa7c92a0..00000000000 --- a/resource-manager/securityinsights/2022-11-01/incidents/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package incidents - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *Incident -} - -// CreateOrUpdate ... -func (c IncidentsClient) CreateOrUpdate(ctx context.Context, id IncidentId, input Incident) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c IncidentsClient) preparerForCreateOrUpdate(ctx context.Context, id IncidentId, input Incident) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c IncidentsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-11-01/incidents/method_delete.go b/resource-manager/securityinsights/2022-11-01/incidents/method_delete.go new file mode 100644 index 00000000000..9b3205af5fc --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/incidents/method_delete.go @@ -0,0 +1,47 @@ +package incidents + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c IncidentsClient) Delete(ctx context.Context, id IncidentId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/incidents/method_delete_autorest.go b/resource-manager/securityinsights/2022-11-01/incidents/method_delete_autorest.go deleted file mode 100644 index 280832422f8..00000000000 --- a/resource-manager/securityinsights/2022-11-01/incidents/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package incidents - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c IncidentsClient) Delete(ctx context.Context, id IncidentId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c IncidentsClient) preparerForDelete(ctx context.Context, id IncidentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c IncidentsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-11-01/incidents/method_get.go b/resource-manager/securityinsights/2022-11-01/incidents/method_get.go new file mode 100644 index 00000000000..e6d4e9e933b --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/incidents/method_get.go @@ -0,0 +1,51 @@ +package incidents + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Incident +} + +// Get ... +func (c IncidentsClient) Get(ctx context.Context, id IncidentId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/incidents/method_get_autorest.go b/resource-manager/securityinsights/2022-11-01/incidents/method_get_autorest.go deleted file mode 100644 index d8d2b7debeb..00000000000 --- a/resource-manager/securityinsights/2022-11-01/incidents/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package incidents - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *Incident -} - -// Get ... -func (c IncidentsClient) Get(ctx context.Context, id IncidentId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c IncidentsClient) preparerForGet(ctx context.Context, id IncidentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c IncidentsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-11-01/incidents/method_list.go b/resource-manager/securityinsights/2022-11-01/incidents/method_list.go new file mode 100644 index 00000000000..fe19cd4d9ff --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/incidents/method_list.go @@ -0,0 +1,127 @@ +package incidents + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Incident +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Incident +} + +type ListOperationOptions struct { + Filter *string + Orderby *string + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c IncidentsClient) List(ctx context.Context, id WorkspaceId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/incidents", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Incident `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c IncidentsClient) ListComplete(ctx context.Context, id WorkspaceId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, IncidentOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c IncidentsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ListOperationOptions, predicate IncidentOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Incident, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-11-01/incidents/method_list_autorest.go b/resource-manager/securityinsights/2022-11-01/incidents/method_list_autorest.go deleted file mode 100644 index 8d2f5acc547..00000000000 --- a/resource-manager/securityinsights/2022-11-01/incidents/method_list_autorest.go +++ /dev/null @@ -1,225 +0,0 @@ -package incidents - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]Incident - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []Incident -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ListOperationOptions struct { - Filter *string - Orderby *string - Top *int64 -} - -func DefaultListOperationOptions() ListOperationOptions { - return ListOperationOptions{} -} - -func (o ListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Filter != nil { - out["$filter"] = *o.Filter - } - - if o.Orderby != nil { - out["$orderby"] = *o.Orderby - } - - if o.Top != nil { - out["$top"] = *o.Top - } - - return out -} - -// List ... -func (c IncidentsClient) List(ctx context.Context, id WorkspaceId, options ListOperationOptions) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c IncidentsClient) preparerForList(ctx context.Context, id WorkspaceId, options ListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/incidents", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c IncidentsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c IncidentsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []Incident `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c IncidentsClient) ListComplete(ctx context.Context, id WorkspaceId, options ListOperationOptions) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, options, IncidentOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c IncidentsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ListOperationOptions, predicate IncidentOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]Incident, 0) - - page, err := c.List(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-11-01/securitymlanalyticssettings/client.go b/resource-manager/securityinsights/2022-11-01/securitymlanalyticssettings/client.go index 50d64fb429c..65b248a41f5 100644 --- a/resource-manager/securityinsights/2022-11-01/securitymlanalyticssettings/client.go +++ b/resource-manager/securityinsights/2022-11-01/securitymlanalyticssettings/client.go @@ -1,18 +1,26 @@ package securitymlanalyticssettings -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type SecurityMLAnalyticsSettingsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewSecurityMLAnalyticsSettingsClientWithBaseURI(endpoint string) SecurityMLAnalyticsSettingsClient { - return SecurityMLAnalyticsSettingsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewSecurityMLAnalyticsSettingsClientWithBaseURI(sdkApi sdkEnv.Api) (*SecurityMLAnalyticsSettingsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "securitymlanalyticssettings", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SecurityMLAnalyticsSettingsClient: %+v", err) } + + return &SecurityMLAnalyticsSettingsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-11-01/securitymlanalyticssettings/constants.go b/resource-manager/securityinsights/2022-11-01/securitymlanalyticssettings/constants.go index 47b13b875e2..e32d4d9875f 100644 --- a/resource-manager/securityinsights/2022-11-01/securitymlanalyticssettings/constants.go +++ b/resource-manager/securityinsights/2022-11-01/securitymlanalyticssettings/constants.go @@ -1,6 +1,10 @@ package securitymlanalyticssettings -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -49,6 +53,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -90,6 +107,19 @@ func PossibleValuesForSecurityMLAnalyticsSettingsKind() []string { } } +func (s *SecurityMLAnalyticsSettingsKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSecurityMLAnalyticsSettingsKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSecurityMLAnalyticsSettingsKind(input string) (*SecurityMLAnalyticsSettingsKind, error) { vals := map[string]SecurityMLAnalyticsSettingsKind{ "anomaly": SecurityMLAnalyticsSettingsKindAnomaly, @@ -117,6 +147,19 @@ func PossibleValuesForSettingsStatus() []string { } } +func (s *SettingsStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSettingsStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSettingsStatus(input string) (*SettingsStatus, error) { vals := map[string]SettingsStatus{ "flighting": SettingsStatusFlighting, diff --git a/resource-manager/securityinsights/2022-11-01/securitymlanalyticssettings/method_createorupdate.go b/resource-manager/securityinsights/2022-11-01/securitymlanalyticssettings/method_createorupdate.go new file mode 100644 index 00000000000..f08267b7fac --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/securitymlanalyticssettings/method_createorupdate.go @@ -0,0 +1,63 @@ +package securitymlanalyticssettings + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SecurityMLAnalyticsSetting +} + +// CreateOrUpdate ... +func (c SecurityMLAnalyticsSettingsClient) CreateOrUpdate(ctx context.Context, id SecurityMLAnalyticsSettingId, input SecurityMLAnalyticsSetting) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalSecurityMLAnalyticsSettingImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/securitymlanalyticssettings/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-11-01/securitymlanalyticssettings/method_createorupdate_autorest.go deleted file mode 100644 index e72d9bcb79b..00000000000 --- a/resource-manager/securityinsights/2022-11-01/securitymlanalyticssettings/method_createorupdate_autorest.go +++ /dev/null @@ -1,78 +0,0 @@ -package securitymlanalyticssettings - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *SecurityMLAnalyticsSetting -} - -// CreateOrUpdate ... -func (c SecurityMLAnalyticsSettingsClient) CreateOrUpdate(ctx context.Context, id SecurityMLAnalyticsSettingId, input SecurityMLAnalyticsSetting) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c SecurityMLAnalyticsSettingsClient) preparerForCreateOrUpdate(ctx context.Context, id SecurityMLAnalyticsSettingId, input SecurityMLAnalyticsSetting) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c SecurityMLAnalyticsSettingsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalSecurityMLAnalyticsSettingImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-11-01/securitymlanalyticssettings/method_delete.go b/resource-manager/securityinsights/2022-11-01/securitymlanalyticssettings/method_delete.go new file mode 100644 index 00000000000..36309ecb138 --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/securitymlanalyticssettings/method_delete.go @@ -0,0 +1,47 @@ +package securitymlanalyticssettings + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c SecurityMLAnalyticsSettingsClient) Delete(ctx context.Context, id SecurityMLAnalyticsSettingId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/securitymlanalyticssettings/method_delete_autorest.go b/resource-manager/securityinsights/2022-11-01/securitymlanalyticssettings/method_delete_autorest.go deleted file mode 100644 index a2b0d18f72f..00000000000 --- a/resource-manager/securityinsights/2022-11-01/securitymlanalyticssettings/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package securitymlanalyticssettings - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c SecurityMLAnalyticsSettingsClient) Delete(ctx context.Context, id SecurityMLAnalyticsSettingId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c SecurityMLAnalyticsSettingsClient) preparerForDelete(ctx context.Context, id SecurityMLAnalyticsSettingId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c SecurityMLAnalyticsSettingsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-11-01/securitymlanalyticssettings/method_get.go b/resource-manager/securityinsights/2022-11-01/securitymlanalyticssettings/method_get.go new file mode 100644 index 00000000000..9be89fdf974 --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/securitymlanalyticssettings/method_get.go @@ -0,0 +1,58 @@ +package securitymlanalyticssettings + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SecurityMLAnalyticsSetting +} + +// Get ... +func (c SecurityMLAnalyticsSettingsClient) Get(ctx context.Context, id SecurityMLAnalyticsSettingId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalSecurityMLAnalyticsSettingImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/securitymlanalyticssettings/method_get_autorest.go b/resource-manager/securityinsights/2022-11-01/securitymlanalyticssettings/method_get_autorest.go deleted file mode 100644 index 0157220a0eb..00000000000 --- a/resource-manager/securityinsights/2022-11-01/securitymlanalyticssettings/method_get_autorest.go +++ /dev/null @@ -1,77 +0,0 @@ -package securitymlanalyticssettings - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *SecurityMLAnalyticsSetting -} - -// Get ... -func (c SecurityMLAnalyticsSettingsClient) Get(ctx context.Context, id SecurityMLAnalyticsSettingId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c SecurityMLAnalyticsSettingsClient) preparerForGet(ctx context.Context, id SecurityMLAnalyticsSettingId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c SecurityMLAnalyticsSettingsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalSecurityMLAnalyticsSettingImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-11-01/securitymlanalyticssettings/method_list.go b/resource-manager/securityinsights/2022-11-01/securitymlanalyticssettings/method_list.go new file mode 100644 index 00000000000..49878345af3 --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/securitymlanalyticssettings/method_list.go @@ -0,0 +1,103 @@ +package securitymlanalyticssettings + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SecurityMLAnalyticsSetting +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []SecurityMLAnalyticsSetting +} + +// List ... +func (c SecurityMLAnalyticsSettingsClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/securityMLAnalyticsSettings", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]SecurityMLAnalyticsSetting, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalSecurityMLAnalyticsSettingImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for SecurityMLAnalyticsSetting (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// ListComplete retrieves all the results into a single object +func (c SecurityMLAnalyticsSettingsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, SecurityMLAnalyticsSettingOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SecurityMLAnalyticsSettingsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate SecurityMLAnalyticsSettingOperationPredicate) (result ListCompleteResult, err error) { + items := make([]SecurityMLAnalyticsSetting, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-11-01/securitymlanalyticssettings/method_list_autorest.go b/resource-manager/securityinsights/2022-11-01/securitymlanalyticssettings/method_list_autorest.go deleted file mode 100644 index 127297aa869..00000000000 --- a/resource-manager/securityinsights/2022-11-01/securitymlanalyticssettings/method_list_autorest.go +++ /dev/null @@ -1,196 +0,0 @@ -package securitymlanalyticssettings - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]SecurityMLAnalyticsSetting - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []SecurityMLAnalyticsSetting -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c SecurityMLAnalyticsSettingsClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c SecurityMLAnalyticsSettingsClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/securityMLAnalyticsSettings", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c SecurityMLAnalyticsSettingsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c SecurityMLAnalyticsSettingsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]SecurityMLAnalyticsSetting, 0) - for i, v := range respObj.Values { - val, err := unmarshalSecurityMLAnalyticsSettingImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for SecurityMLAnalyticsSetting (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c SecurityMLAnalyticsSettingsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, SecurityMLAnalyticsSettingOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c SecurityMLAnalyticsSettingsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate SecurityMLAnalyticsSettingOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]SecurityMLAnalyticsSetting, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-11-01/sentinelonboardingstates/client.go b/resource-manager/securityinsights/2022-11-01/sentinelonboardingstates/client.go index 0ae442ba3fa..94701ed853a 100644 --- a/resource-manager/securityinsights/2022-11-01/sentinelonboardingstates/client.go +++ b/resource-manager/securityinsights/2022-11-01/sentinelonboardingstates/client.go @@ -1,18 +1,26 @@ package sentinelonboardingstates -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type SentinelOnboardingStatesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewSentinelOnboardingStatesClientWithBaseURI(endpoint string) SentinelOnboardingStatesClient { - return SentinelOnboardingStatesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewSentinelOnboardingStatesClientWithBaseURI(sdkApi sdkEnv.Api) (*SentinelOnboardingStatesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sentinelonboardingstates", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SentinelOnboardingStatesClient: %+v", err) } + + return &SentinelOnboardingStatesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-11-01/sentinelonboardingstates/method_create.go b/resource-manager/securityinsights/2022-11-01/sentinelonboardingstates/method_create.go new file mode 100644 index 00000000000..af163a9d66b --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/sentinelonboardingstates/method_create.go @@ -0,0 +1,56 @@ +package sentinelonboardingstates + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SentinelOnboardingState +} + +// Create ... +func (c SentinelOnboardingStatesClient) Create(ctx context.Context, id OnboardingStateId, input SentinelOnboardingState) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/sentinelonboardingstates/method_create_autorest.go b/resource-manager/securityinsights/2022-11-01/sentinelonboardingstates/method_create_autorest.go deleted file mode 100644 index 9ad88e95157..00000000000 --- a/resource-manager/securityinsights/2022-11-01/sentinelonboardingstates/method_create_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package sentinelonboardingstates - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOperationResponse struct { - HttpResponse *http.Response - Model *SentinelOnboardingState -} - -// Create ... -func (c SentinelOnboardingStatesClient) Create(ctx context.Context, id OnboardingStateId, input SentinelOnboardingState) (result CreateOperationResponse, err error) { - req, err := c.preparerForCreate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Create", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Create", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Create", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreate prepares the Create request. -func (c SentinelOnboardingStatesClient) preparerForCreate(ctx context.Context, id OnboardingStateId, input SentinelOnboardingState) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreate handles the response to the Create request. The method always -// closes the http.Response Body. -func (c SentinelOnboardingStatesClient) responderForCreate(resp *http.Response) (result CreateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-11-01/sentinelonboardingstates/method_delete.go b/resource-manager/securityinsights/2022-11-01/sentinelonboardingstates/method_delete.go new file mode 100644 index 00000000000..1c6c5e372d7 --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/sentinelonboardingstates/method_delete.go @@ -0,0 +1,47 @@ +package sentinelonboardingstates + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c SentinelOnboardingStatesClient) Delete(ctx context.Context, id OnboardingStateId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/sentinelonboardingstates/method_delete_autorest.go b/resource-manager/securityinsights/2022-11-01/sentinelonboardingstates/method_delete_autorest.go deleted file mode 100644 index 65fa74282f7..00000000000 --- a/resource-manager/securityinsights/2022-11-01/sentinelonboardingstates/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package sentinelonboardingstates - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c SentinelOnboardingStatesClient) Delete(ctx context.Context, id OnboardingStateId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c SentinelOnboardingStatesClient) preparerForDelete(ctx context.Context, id OnboardingStateId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c SentinelOnboardingStatesClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-11-01/sentinelonboardingstates/method_get.go b/resource-manager/securityinsights/2022-11-01/sentinelonboardingstates/method_get.go new file mode 100644 index 00000000000..82165662910 --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/sentinelonboardingstates/method_get.go @@ -0,0 +1,51 @@ +package sentinelonboardingstates + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SentinelOnboardingState +} + +// Get ... +func (c SentinelOnboardingStatesClient) Get(ctx context.Context, id OnboardingStateId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/sentinelonboardingstates/method_get_autorest.go b/resource-manager/securityinsights/2022-11-01/sentinelonboardingstates/method_get_autorest.go deleted file mode 100644 index d6174a7522a..00000000000 --- a/resource-manager/securityinsights/2022-11-01/sentinelonboardingstates/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package sentinelonboardingstates - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *SentinelOnboardingState -} - -// Get ... -func (c SentinelOnboardingStatesClient) Get(ctx context.Context, id OnboardingStateId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c SentinelOnboardingStatesClient) preparerForGet(ctx context.Context, id OnboardingStateId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c SentinelOnboardingStatesClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-11-01/sentinelonboardingstates/method_list.go b/resource-manager/securityinsights/2022-11-01/sentinelonboardingstates/method_list.go new file mode 100644 index 00000000000..2efd1d41230 --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/sentinelonboardingstates/method_list.go @@ -0,0 +1,52 @@ +package sentinelonboardingstates + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SentinelOnboardingStatesList +} + +// List ... +func (c SentinelOnboardingStatesClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/onboardingStates", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/sentinelonboardingstates/method_list_autorest.go b/resource-manager/securityinsights/2022-11-01/sentinelonboardingstates/method_list_autorest.go deleted file mode 100644 index 6a00bb3d3fd..00000000000 --- a/resource-manager/securityinsights/2022-11-01/sentinelonboardingstates/method_list_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package sentinelonboardingstates - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *SentinelOnboardingStatesList -} - -// List ... -func (c SentinelOnboardingStatesClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForList prepares the List request. -func (c SentinelOnboardingStatesClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/onboardingStates", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c SentinelOnboardingStatesClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-11-01/threatintelligence/client.go b/resource-manager/securityinsights/2022-11-01/threatintelligence/client.go index 35caff31357..edf96c3143f 100644 --- a/resource-manager/securityinsights/2022-11-01/threatintelligence/client.go +++ b/resource-manager/securityinsights/2022-11-01/threatintelligence/client.go @@ -1,18 +1,26 @@ package threatintelligence -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type ThreatIntelligenceClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewThreatIntelligenceClientWithBaseURI(endpoint string) ThreatIntelligenceClient { - return ThreatIntelligenceClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewThreatIntelligenceClientWithBaseURI(sdkApi sdkEnv.Api) (*ThreatIntelligenceClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "threatintelligence", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ThreatIntelligenceClient: %+v", err) } + + return &ThreatIntelligenceClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-11-01/threatintelligence/constants.go b/resource-manager/securityinsights/2022-11-01/threatintelligence/constants.go index 76610b31101..8cef3ba3f75 100644 --- a/resource-manager/securityinsights/2022-11-01/threatintelligence/constants.go +++ b/resource-manager/securityinsights/2022-11-01/threatintelligence/constants.go @@ -1,6 +1,10 @@ package threatintelligence -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -17,6 +21,19 @@ func PossibleValuesForThreatIntelligenceResourceInnerKind() []string { } } +func (s *ThreatIntelligenceResourceInnerKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseThreatIntelligenceResourceInnerKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseThreatIntelligenceResourceInnerKind(input string) (*ThreatIntelligenceResourceInnerKind, error) { vals := map[string]ThreatIntelligenceResourceInnerKind{ "indicator": ThreatIntelligenceResourceInnerKindIndicator, @@ -46,6 +63,19 @@ func PossibleValuesForThreatIntelligenceSortingOrder() []string { } } +func (s *ThreatIntelligenceSortingOrder) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseThreatIntelligenceSortingOrder(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseThreatIntelligenceSortingOrder(input string) (*ThreatIntelligenceSortingOrder, error) { vals := map[string]ThreatIntelligenceSortingOrder{ "ascending": ThreatIntelligenceSortingOrderAscending, diff --git a/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatorappendtags.go b/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatorappendtags.go new file mode 100644 index 00000000000..4384327485d --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatorappendtags.go @@ -0,0 +1,51 @@ +package threatintelligence + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorAppendTagsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// IndicatorAppendTags ... +func (c ThreatIntelligenceClient) IndicatorAppendTags(ctx context.Context, id IndicatorId, input ThreatIntelligenceAppendTags) (result IndicatorAppendTagsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/appendTags", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatorappendtags_autorest.go b/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatorappendtags_autorest.go deleted file mode 100644 index 18b86a166fe..00000000000 --- a/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatorappendtags_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package threatintelligence - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorAppendTagsOperationResponse struct { - HttpResponse *http.Response -} - -// IndicatorAppendTags ... -func (c ThreatIntelligenceClient) IndicatorAppendTags(ctx context.Context, id IndicatorId, input ThreatIntelligenceAppendTags) (result IndicatorAppendTagsOperationResponse, err error) { - req, err := c.preparerForIndicatorAppendTags(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorAppendTags", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorAppendTags", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorAppendTags(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorAppendTags", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorAppendTags prepares the IndicatorAppendTags request. -func (c ThreatIntelligenceClient) preparerForIndicatorAppendTags(ctx context.Context, id IndicatorId, input ThreatIntelligenceAppendTags) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/appendTags", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorAppendTags handles the response to the IndicatorAppendTags request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorAppendTags(resp *http.Response) (result IndicatorAppendTagsOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatorcreate.go b/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatorcreate.go new file mode 100644 index 00000000000..3cee598931c --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatorcreate.go @@ -0,0 +1,63 @@ +package threatintelligence + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorCreateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ThreatIntelligenceInformation +} + +// IndicatorCreate ... +func (c ThreatIntelligenceClient) IndicatorCreate(ctx context.Context, id IndicatorId, input ThreatIntelligenceIndicatorModel) (result IndicatorCreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatorcreate_autorest.go b/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatorcreate_autorest.go deleted file mode 100644 index 98609062b7f..00000000000 --- a/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatorcreate_autorest.go +++ /dev/null @@ -1,78 +0,0 @@ -package threatintelligence - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorCreateOperationResponse struct { - HttpResponse *http.Response - Model *ThreatIntelligenceInformation -} - -// IndicatorCreate ... -func (c ThreatIntelligenceClient) IndicatorCreate(ctx context.Context, id IndicatorId, input ThreatIntelligenceIndicatorModel) (result IndicatorCreateOperationResponse, err error) { - req, err := c.preparerForIndicatorCreate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorCreate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorCreate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorCreate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorCreate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorCreate prepares the IndicatorCreate request. -func (c ThreatIntelligenceClient) preparerForIndicatorCreate(ctx context.Context, id IndicatorId, input ThreatIntelligenceIndicatorModel) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorCreate handles the response to the IndicatorCreate request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorCreate(resp *http.Response) (result IndicatorCreateOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatorcreateindicator.go b/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatorcreateindicator.go new file mode 100644 index 00000000000..0f3ab94c4f5 --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatorcreateindicator.go @@ -0,0 +1,63 @@ +package threatintelligence + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorCreateIndicatorOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ThreatIntelligenceInformation +} + +// IndicatorCreateIndicator ... +func (c ThreatIntelligenceClient) IndicatorCreateIndicator(ctx context.Context, id WorkspaceId, input ThreatIntelligenceIndicatorModel) (result IndicatorCreateIndicatorOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/createIndicator", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatorcreateindicator_autorest.go b/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatorcreateindicator_autorest.go deleted file mode 100644 index ecc76b88f5c..00000000000 --- a/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatorcreateindicator_autorest.go +++ /dev/null @@ -1,79 +0,0 @@ -package threatintelligence - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorCreateIndicatorOperationResponse struct { - HttpResponse *http.Response - Model *ThreatIntelligenceInformation -} - -// IndicatorCreateIndicator ... -func (c ThreatIntelligenceClient) IndicatorCreateIndicator(ctx context.Context, id WorkspaceId, input ThreatIntelligenceIndicatorModel) (result IndicatorCreateIndicatorOperationResponse, err error) { - req, err := c.preparerForIndicatorCreateIndicator(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorCreateIndicator", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorCreateIndicator", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorCreateIndicator(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorCreateIndicator", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorCreateIndicator prepares the IndicatorCreateIndicator request. -func (c ThreatIntelligenceClient) preparerForIndicatorCreateIndicator(ctx context.Context, id WorkspaceId, input ThreatIntelligenceIndicatorModel) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/createIndicator", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorCreateIndicator handles the response to the IndicatorCreateIndicator request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorCreateIndicator(resp *http.Response) (result IndicatorCreateIndicatorOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatordelete.go b/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatordelete.go new file mode 100644 index 00000000000..4de264524d5 --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatordelete.go @@ -0,0 +1,47 @@ +package threatintelligence + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// IndicatorDelete ... +func (c ThreatIntelligenceClient) IndicatorDelete(ctx context.Context, id IndicatorId) (result IndicatorDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatordelete_autorest.go b/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatordelete_autorest.go deleted file mode 100644 index 825d3b911ce..00000000000 --- a/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatordelete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package threatintelligence - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorDeleteOperationResponse struct { - HttpResponse *http.Response -} - -// IndicatorDelete ... -func (c ThreatIntelligenceClient) IndicatorDelete(ctx context.Context, id IndicatorId) (result IndicatorDeleteOperationResponse, err error) { - req, err := c.preparerForIndicatorDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorDelete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorDelete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorDelete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorDelete prepares the IndicatorDelete request. -func (c ThreatIntelligenceClient) preparerForIndicatorDelete(ctx context.Context, id IndicatorId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorDelete handles the response to the IndicatorDelete request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorDelete(resp *http.Response) (result IndicatorDeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatorget.go b/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatorget.go new file mode 100644 index 00000000000..3358363f139 --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatorget.go @@ -0,0 +1,58 @@ +package threatintelligence + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ThreatIntelligenceInformation +} + +// IndicatorGet ... +func (c ThreatIntelligenceClient) IndicatorGet(ctx context.Context, id IndicatorId) (result IndicatorGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatorget_autorest.go b/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatorget_autorest.go deleted file mode 100644 index ac1187fb285..00000000000 --- a/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatorget_autorest.go +++ /dev/null @@ -1,77 +0,0 @@ -package threatintelligence - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorGetOperationResponse struct { - HttpResponse *http.Response - Model *ThreatIntelligenceInformation -} - -// IndicatorGet ... -func (c ThreatIntelligenceClient) IndicatorGet(ctx context.Context, id IndicatorId) (result IndicatorGetOperationResponse, err error) { - req, err := c.preparerForIndicatorGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorGet", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorGet", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorGet", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorGet prepares the IndicatorGet request. -func (c ThreatIntelligenceClient) preparerForIndicatorGet(ctx context.Context, id IndicatorId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorGet handles the response to the IndicatorGet request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorGet(resp *http.Response) (result IndicatorGetOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatormetricslist.go b/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatormetricslist.go new file mode 100644 index 00000000000..688ff3c16d1 --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatormetricslist.go @@ -0,0 +1,52 @@ +package threatintelligence + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorMetricsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ThreatIntelligenceMetricsList +} + +// IndicatorMetricsList ... +func (c ThreatIntelligenceClient) IndicatorMetricsList(ctx context.Context, id WorkspaceId) (result IndicatorMetricsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/metrics", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatormetricslist_autorest.go b/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatormetricslist_autorest.go deleted file mode 100644 index 1835c26ed96..00000000000 --- a/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatormetricslist_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package threatintelligence - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorMetricsListOperationResponse struct { - HttpResponse *http.Response - Model *ThreatIntelligenceMetricsList -} - -// IndicatorMetricsList ... -func (c ThreatIntelligenceClient) IndicatorMetricsList(ctx context.Context, id WorkspaceId) (result IndicatorMetricsListOperationResponse, err error) { - req, err := c.preparerForIndicatorMetricsList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorMetricsList", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorMetricsList", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorMetricsList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorMetricsList", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorMetricsList prepares the IndicatorMetricsList request. -func (c ThreatIntelligenceClient) preparerForIndicatorMetricsList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/metrics", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorMetricsList handles the response to the IndicatorMetricsList request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorMetricsList(resp *http.Response) (result IndicatorMetricsListOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatorqueryindicators.go b/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatorqueryindicators.go new file mode 100644 index 00000000000..8ce639f2623 --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatorqueryindicators.go @@ -0,0 +1,103 @@ +package threatintelligence + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorQueryIndicatorsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ThreatIntelligenceInformation +} + +type IndicatorQueryIndicatorsCompleteResult struct { + LatestHttpResponse *http.Response + Items []ThreatIntelligenceInformation +} + +// IndicatorQueryIndicators ... +func (c ThreatIntelligenceClient) IndicatorQueryIndicators(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria) (result IndicatorQueryIndicatorsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/queryIndicators", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]ThreatIntelligenceInformation, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalThreatIntelligenceInformationImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for ThreatIntelligenceInformation (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// IndicatorQueryIndicatorsComplete retrieves all the results into a single object +func (c ThreatIntelligenceClient) IndicatorQueryIndicatorsComplete(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria) (IndicatorQueryIndicatorsCompleteResult, error) { + return c.IndicatorQueryIndicatorsCompleteMatchingPredicate(ctx, id, input, ThreatIntelligenceInformationOperationPredicate{}) +} + +// IndicatorQueryIndicatorsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ThreatIntelligenceClient) IndicatorQueryIndicatorsCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria, predicate ThreatIntelligenceInformationOperationPredicate) (result IndicatorQueryIndicatorsCompleteResult, err error) { + items := make([]ThreatIntelligenceInformation, 0) + + resp, err := c.IndicatorQueryIndicators(ctx, id, input) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = IndicatorQueryIndicatorsCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatorqueryindicators_autorest.go b/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatorqueryindicators_autorest.go deleted file mode 100644 index fcbe7c74758..00000000000 --- a/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatorqueryindicators_autorest.go +++ /dev/null @@ -1,197 +0,0 @@ -package threatintelligence - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorQueryIndicatorsOperationResponse struct { - HttpResponse *http.Response - Model *[]ThreatIntelligenceInformation - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (IndicatorQueryIndicatorsOperationResponse, error) -} - -type IndicatorQueryIndicatorsCompleteResult struct { - Items []ThreatIntelligenceInformation -} - -func (r IndicatorQueryIndicatorsOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r IndicatorQueryIndicatorsOperationResponse) LoadMore(ctx context.Context) (resp IndicatorQueryIndicatorsOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// IndicatorQueryIndicators ... -func (c ThreatIntelligenceClient) IndicatorQueryIndicators(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria) (resp IndicatorQueryIndicatorsOperationResponse, err error) { - req, err := c.preparerForIndicatorQueryIndicators(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorQueryIndicators", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorQueryIndicators", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForIndicatorQueryIndicators(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorQueryIndicators", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForIndicatorQueryIndicators prepares the IndicatorQueryIndicators request. -func (c ThreatIntelligenceClient) preparerForIndicatorQueryIndicators(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/queryIndicators", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForIndicatorQueryIndicatorsWithNextLink prepares the IndicatorQueryIndicators request with the given nextLink token. -func (c ThreatIntelligenceClient) preparerForIndicatorQueryIndicatorsWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorQueryIndicators handles the response to the IndicatorQueryIndicators request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorQueryIndicators(resp *http.Response) (result IndicatorQueryIndicatorsOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]ThreatIntelligenceInformation, 0) - for i, v := range respObj.Values { - val, err := unmarshalThreatIntelligenceInformationImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for ThreatIntelligenceInformation (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result IndicatorQueryIndicatorsOperationResponse, err error) { - req, err := c.preparerForIndicatorQueryIndicatorsWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorQueryIndicators", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorQueryIndicators", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorQueryIndicators(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorQueryIndicators", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// IndicatorQueryIndicatorsComplete retrieves all of the results into a single object -func (c ThreatIntelligenceClient) IndicatorQueryIndicatorsComplete(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria) (IndicatorQueryIndicatorsCompleteResult, error) { - return c.IndicatorQueryIndicatorsCompleteMatchingPredicate(ctx, id, input, ThreatIntelligenceInformationOperationPredicate{}) -} - -// IndicatorQueryIndicatorsCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c ThreatIntelligenceClient) IndicatorQueryIndicatorsCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria, predicate ThreatIntelligenceInformationOperationPredicate) (resp IndicatorQueryIndicatorsCompleteResult, err error) { - items := make([]ThreatIntelligenceInformation, 0) - - page, err := c.IndicatorQueryIndicators(ctx, id, input) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := IndicatorQueryIndicatorsCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatorreplacetags.go b/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatorreplacetags.go new file mode 100644 index 00000000000..052bbe7b66a --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatorreplacetags.go @@ -0,0 +1,63 @@ +package threatintelligence + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorReplaceTagsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ThreatIntelligenceInformation +} + +// IndicatorReplaceTags ... +func (c ThreatIntelligenceClient) IndicatorReplaceTags(ctx context.Context, id IndicatorId, input ThreatIntelligenceIndicatorModel) (result IndicatorReplaceTagsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/replaceTags", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatorreplacetags_autorest.go b/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatorreplacetags_autorest.go deleted file mode 100644 index 01efbe5b778..00000000000 --- a/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatorreplacetags_autorest.go +++ /dev/null @@ -1,79 +0,0 @@ -package threatintelligence - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorReplaceTagsOperationResponse struct { - HttpResponse *http.Response - Model *ThreatIntelligenceInformation -} - -// IndicatorReplaceTags ... -func (c ThreatIntelligenceClient) IndicatorReplaceTags(ctx context.Context, id IndicatorId, input ThreatIntelligenceIndicatorModel) (result IndicatorReplaceTagsOperationResponse, err error) { - req, err := c.preparerForIndicatorReplaceTags(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorReplaceTags", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorReplaceTags", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorReplaceTags(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorReplaceTags", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorReplaceTags prepares the IndicatorReplaceTags request. -func (c ThreatIntelligenceClient) preparerForIndicatorReplaceTags(ctx context.Context, id IndicatorId, input ThreatIntelligenceIndicatorModel) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/replaceTags", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorReplaceTags handles the response to the IndicatorReplaceTags request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorReplaceTags(resp *http.Response) (result IndicatorReplaceTagsOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatorslist.go b/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatorslist.go new file mode 100644 index 00000000000..860ecd26255 --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatorslist.go @@ -0,0 +1,139 @@ +package threatintelligence + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ThreatIntelligenceInformation +} + +type IndicatorsListCompleteResult struct { + LatestHttpResponse *http.Response + Items []ThreatIntelligenceInformation +} + +type IndicatorsListOperationOptions struct { + Filter *string + Orderby *string + Top *int64 +} + +func DefaultIndicatorsListOperationOptions() IndicatorsListOperationOptions { + return IndicatorsListOperationOptions{} +} + +func (o IndicatorsListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o IndicatorsListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o IndicatorsListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// IndicatorsList ... +func (c ThreatIntelligenceClient) IndicatorsList(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions) (result IndicatorsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/indicators", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]ThreatIntelligenceInformation, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalThreatIntelligenceInformationImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for ThreatIntelligenceInformation (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// IndicatorsListComplete retrieves all the results into a single object +func (c ThreatIntelligenceClient) IndicatorsListComplete(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions) (IndicatorsListCompleteResult, error) { + return c.IndicatorsListCompleteMatchingPredicate(ctx, id, options, ThreatIntelligenceInformationOperationPredicate{}) +} + +// IndicatorsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ThreatIntelligenceClient) IndicatorsListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions, predicate ThreatIntelligenceInformationOperationPredicate) (result IndicatorsListCompleteResult, err error) { + items := make([]ThreatIntelligenceInformation, 0) + + resp, err := c.IndicatorsList(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = IndicatorsListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatorslist_autorest.go b/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatorslist_autorest.go deleted file mode 100644 index 22ef9d7b193..00000000000 --- a/resource-manager/securityinsights/2022-11-01/threatintelligence/method_indicatorslist_autorest.go +++ /dev/null @@ -1,235 +0,0 @@ -package threatintelligence - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorsListOperationResponse struct { - HttpResponse *http.Response - Model *[]ThreatIntelligenceInformation - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (IndicatorsListOperationResponse, error) -} - -type IndicatorsListCompleteResult struct { - Items []ThreatIntelligenceInformation -} - -func (r IndicatorsListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r IndicatorsListOperationResponse) LoadMore(ctx context.Context) (resp IndicatorsListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type IndicatorsListOperationOptions struct { - Filter *string - Orderby *string - Top *int64 -} - -func DefaultIndicatorsListOperationOptions() IndicatorsListOperationOptions { - return IndicatorsListOperationOptions{} -} - -func (o IndicatorsListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o IndicatorsListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Filter != nil { - out["$filter"] = *o.Filter - } - - if o.Orderby != nil { - out["$orderby"] = *o.Orderby - } - - if o.Top != nil { - out["$top"] = *o.Top - } - - return out -} - -// IndicatorsList ... -func (c ThreatIntelligenceClient) IndicatorsList(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions) (resp IndicatorsListOperationResponse, err error) { - req, err := c.preparerForIndicatorsList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForIndicatorsList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForIndicatorsList prepares the IndicatorsList request. -func (c ThreatIntelligenceClient) preparerForIndicatorsList(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/indicators", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForIndicatorsListWithNextLink prepares the IndicatorsList request with the given nextLink token. -func (c ThreatIntelligenceClient) preparerForIndicatorsListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorsList handles the response to the IndicatorsList request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorsList(resp *http.Response) (result IndicatorsListOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]ThreatIntelligenceInformation, 0) - for i, v := range respObj.Values { - val, err := unmarshalThreatIntelligenceInformationImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for ThreatIntelligenceInformation (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result IndicatorsListOperationResponse, err error) { - req, err := c.preparerForIndicatorsListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorsList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// IndicatorsListComplete retrieves all of the results into a single object -func (c ThreatIntelligenceClient) IndicatorsListComplete(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions) (IndicatorsListCompleteResult, error) { - return c.IndicatorsListCompleteMatchingPredicate(ctx, id, options, ThreatIntelligenceInformationOperationPredicate{}) -} - -// IndicatorsListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c ThreatIntelligenceClient) IndicatorsListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions, predicate ThreatIntelligenceInformationOperationPredicate) (resp IndicatorsListCompleteResult, err error) { - items := make([]ThreatIntelligenceInformation, 0) - - page, err := c.IndicatorsList(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := IndicatorsListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-11-01/watchlistitems/client.go b/resource-manager/securityinsights/2022-11-01/watchlistitems/client.go index 9403755456e..d3193694a48 100644 --- a/resource-manager/securityinsights/2022-11-01/watchlistitems/client.go +++ b/resource-manager/securityinsights/2022-11-01/watchlistitems/client.go @@ -1,18 +1,26 @@ package watchlistitems -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type WatchlistItemsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewWatchlistItemsClientWithBaseURI(endpoint string) WatchlistItemsClient { - return WatchlistItemsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewWatchlistItemsClientWithBaseURI(sdkApi sdkEnv.Api) (*WatchlistItemsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "watchlistitems", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating WatchlistItemsClient: %+v", err) } + + return &WatchlistItemsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-11-01/watchlistitems/method_createorupdate.go b/resource-manager/securityinsights/2022-11-01/watchlistitems/method_createorupdate.go new file mode 100644 index 00000000000..d02782f71bc --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/watchlistitems/method_createorupdate.go @@ -0,0 +1,56 @@ +package watchlistitems + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *WatchlistItem +} + +// CreateOrUpdate ... +func (c WatchlistItemsClient) CreateOrUpdate(ctx context.Context, id WatchlistItemId, input WatchlistItem) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/watchlistitems/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-11-01/watchlistitems/method_createorupdate_autorest.go deleted file mode 100644 index 15d8fdcc2be..00000000000 --- a/resource-manager/securityinsights/2022-11-01/watchlistitems/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package watchlistitems - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *WatchlistItem -} - -// CreateOrUpdate ... -func (c WatchlistItemsClient) CreateOrUpdate(ctx context.Context, id WatchlistItemId, input WatchlistItem) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c WatchlistItemsClient) preparerForCreateOrUpdate(ctx context.Context, id WatchlistItemId, input WatchlistItem) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c WatchlistItemsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-11-01/watchlistitems/method_delete.go b/resource-manager/securityinsights/2022-11-01/watchlistitems/method_delete.go new file mode 100644 index 00000000000..5565b767fa5 --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/watchlistitems/method_delete.go @@ -0,0 +1,47 @@ +package watchlistitems + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c WatchlistItemsClient) Delete(ctx context.Context, id WatchlistItemId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/watchlistitems/method_delete_autorest.go b/resource-manager/securityinsights/2022-11-01/watchlistitems/method_delete_autorest.go deleted file mode 100644 index c9b8c46f9e5..00000000000 --- a/resource-manager/securityinsights/2022-11-01/watchlistitems/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package watchlistitems - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c WatchlistItemsClient) Delete(ctx context.Context, id WatchlistItemId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c WatchlistItemsClient) preparerForDelete(ctx context.Context, id WatchlistItemId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c WatchlistItemsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-11-01/watchlistitems/method_get.go b/resource-manager/securityinsights/2022-11-01/watchlistitems/method_get.go new file mode 100644 index 00000000000..ff9a8e143fa --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/watchlistitems/method_get.go @@ -0,0 +1,51 @@ +package watchlistitems + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *WatchlistItem +} + +// Get ... +func (c WatchlistItemsClient) Get(ctx context.Context, id WatchlistItemId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/watchlistitems/method_get_autorest.go b/resource-manager/securityinsights/2022-11-01/watchlistitems/method_get_autorest.go deleted file mode 100644 index b294f999f64..00000000000 --- a/resource-manager/securityinsights/2022-11-01/watchlistitems/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package watchlistitems - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *WatchlistItem -} - -// Get ... -func (c WatchlistItemsClient) Get(ctx context.Context, id WatchlistItemId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c WatchlistItemsClient) preparerForGet(ctx context.Context, id WatchlistItemId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c WatchlistItemsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-11-01/watchlistitems/method_list.go b/resource-manager/securityinsights/2022-11-01/watchlistitems/method_list.go new file mode 100644 index 00000000000..8a4d418ea0b --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/watchlistitems/method_list.go @@ -0,0 +1,91 @@ +package watchlistitems + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]WatchlistItem +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []WatchlistItem +} + +// List ... +func (c WatchlistItemsClient) List(ctx context.Context, id WatchlistId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/watchlistItems", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]WatchlistItem `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c WatchlistItemsClient) ListComplete(ctx context.Context, id WatchlistId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, WatchlistItemOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c WatchlistItemsClient) ListCompleteMatchingPredicate(ctx context.Context, id WatchlistId, predicate WatchlistItemOperationPredicate) (result ListCompleteResult, err error) { + items := make([]WatchlistItem, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-11-01/watchlistitems/method_list_autorest.go b/resource-manager/securityinsights/2022-11-01/watchlistitems/method_list_autorest.go deleted file mode 100644 index d8e4bf85bf1..00000000000 --- a/resource-manager/securityinsights/2022-11-01/watchlistitems/method_list_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package watchlistitems - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]WatchlistItem - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []WatchlistItem -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c WatchlistItemsClient) List(ctx context.Context, id WatchlistId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c WatchlistItemsClient) preparerForList(ctx context.Context, id WatchlistId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/watchlistItems", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c WatchlistItemsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c WatchlistItemsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []WatchlistItem `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c WatchlistItemsClient) ListComplete(ctx context.Context, id WatchlistId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, WatchlistItemOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c WatchlistItemsClient) ListCompleteMatchingPredicate(ctx context.Context, id WatchlistId, predicate WatchlistItemOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]WatchlistItem, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2022-11-01/watchlists/client.go b/resource-manager/securityinsights/2022-11-01/watchlists/client.go index 61cfa3d0ac3..45211175054 100644 --- a/resource-manager/securityinsights/2022-11-01/watchlists/client.go +++ b/resource-manager/securityinsights/2022-11-01/watchlists/client.go @@ -1,18 +1,26 @@ package watchlists -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type WatchlistsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewWatchlistsClientWithBaseURI(endpoint string) WatchlistsClient { - return WatchlistsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewWatchlistsClientWithBaseURI(sdkApi sdkEnv.Api) (*WatchlistsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "watchlists", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating WatchlistsClient: %+v", err) } + + return &WatchlistsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2022-11-01/watchlists/constants.go b/resource-manager/securityinsights/2022-11-01/watchlists/constants.go index 504c5ecef48..2ec351b8408 100644 --- a/resource-manager/securityinsights/2022-11-01/watchlists/constants.go +++ b/resource-manager/securityinsights/2022-11-01/watchlists/constants.go @@ -1,6 +1,10 @@ package watchlists -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -19,6 +23,19 @@ func PossibleValuesForSource() []string { } } +func (s *Source) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSource(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSource(input string) (*Source, error) { vals := map[string]Source{ "local file": SourceLocalFile, diff --git a/resource-manager/securityinsights/2022-11-01/watchlists/method_createorupdate.go b/resource-manager/securityinsights/2022-11-01/watchlists/method_createorupdate.go new file mode 100644 index 00000000000..cf0dc47e9d7 --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/watchlists/method_createorupdate.go @@ -0,0 +1,56 @@ +package watchlists + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Watchlist +} + +// CreateOrUpdate ... +func (c WatchlistsClient) CreateOrUpdate(ctx context.Context, id WatchlistId, input Watchlist) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/watchlists/method_createorupdate_autorest.go b/resource-manager/securityinsights/2022-11-01/watchlists/method_createorupdate_autorest.go deleted file mode 100644 index e6d8a5976b8..00000000000 --- a/resource-manager/securityinsights/2022-11-01/watchlists/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package watchlists - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *Watchlist -} - -// CreateOrUpdate ... -func (c WatchlistsClient) CreateOrUpdate(ctx context.Context, id WatchlistId, input Watchlist) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c WatchlistsClient) preparerForCreateOrUpdate(ctx context.Context, id WatchlistId, input Watchlist) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c WatchlistsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-11-01/watchlists/method_delete.go b/resource-manager/securityinsights/2022-11-01/watchlists/method_delete.go new file mode 100644 index 00000000000..9d495f99c57 --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/watchlists/method_delete.go @@ -0,0 +1,47 @@ +package watchlists + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c WatchlistsClient) Delete(ctx context.Context, id WatchlistId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/watchlists/method_delete_autorest.go b/resource-manager/securityinsights/2022-11-01/watchlists/method_delete_autorest.go deleted file mode 100644 index 56234124b82..00000000000 --- a/resource-manager/securityinsights/2022-11-01/watchlists/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package watchlists - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c WatchlistsClient) Delete(ctx context.Context, id WatchlistId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c WatchlistsClient) preparerForDelete(ctx context.Context, id WatchlistId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c WatchlistsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-11-01/watchlists/method_get.go b/resource-manager/securityinsights/2022-11-01/watchlists/method_get.go new file mode 100644 index 00000000000..39ec92feaeb --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/watchlists/method_get.go @@ -0,0 +1,51 @@ +package watchlists + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Watchlist +} + +// Get ... +func (c WatchlistsClient) Get(ctx context.Context, id WatchlistId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2022-11-01/watchlists/method_get_autorest.go b/resource-manager/securityinsights/2022-11-01/watchlists/method_get_autorest.go deleted file mode 100644 index d7253f62215..00000000000 --- a/resource-manager/securityinsights/2022-11-01/watchlists/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package watchlists - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *Watchlist -} - -// Get ... -func (c WatchlistsClient) Get(ctx context.Context, id WatchlistId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c WatchlistsClient) preparerForGet(ctx context.Context, id WatchlistId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c WatchlistsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2022-11-01/watchlists/method_list.go b/resource-manager/securityinsights/2022-11-01/watchlists/method_list.go new file mode 100644 index 00000000000..9122b014815 --- /dev/null +++ b/resource-manager/securityinsights/2022-11-01/watchlists/method_list.go @@ -0,0 +1,91 @@ +package watchlists + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Watchlist +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Watchlist +} + +// List ... +func (c WatchlistsClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/watchlists", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Watchlist `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c WatchlistsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, WatchlistOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c WatchlistsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate WatchlistOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Watchlist, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2022-11-01/watchlists/method_list_autorest.go b/resource-manager/securityinsights/2022-11-01/watchlists/method_list_autorest.go deleted file mode 100644 index a3a2c27c15e..00000000000 --- a/resource-manager/securityinsights/2022-11-01/watchlists/method_list_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package watchlists - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]Watchlist - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []Watchlist -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c WatchlistsClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c WatchlistsClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/watchlists", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c WatchlistsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c WatchlistsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []Watchlist `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c WatchlistsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, WatchlistOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c WatchlistsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate WatchlistOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]Watchlist, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2023-02-01/actions/client.go b/resource-manager/securityinsights/2023-02-01/actions/client.go index 9a66b55eb82..a2b7d01bfe1 100644 --- a/resource-manager/securityinsights/2023-02-01/actions/client.go +++ b/resource-manager/securityinsights/2023-02-01/actions/client.go @@ -1,18 +1,26 @@ package actions -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type ActionsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewActionsClientWithBaseURI(endpoint string) ActionsClient { - return ActionsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewActionsClientWithBaseURI(sdkApi sdkEnv.Api) (*ActionsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "actions", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ActionsClient: %+v", err) } + + return &ActionsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2023-02-01/actions/method_createorupdate.go b/resource-manager/securityinsights/2023-02-01/actions/method_createorupdate.go new file mode 100644 index 00000000000..1672bf99a0f --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/actions/method_createorupdate.go @@ -0,0 +1,56 @@ +package actions + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ActionResponse +} + +// CreateOrUpdate ... +func (c ActionsClient) CreateOrUpdate(ctx context.Context, id ActionId, input ActionRequest) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/actions/method_createorupdate_autorest.go b/resource-manager/securityinsights/2023-02-01/actions/method_createorupdate_autorest.go deleted file mode 100644 index f5145e1a555..00000000000 --- a/resource-manager/securityinsights/2023-02-01/actions/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package actions - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *ActionResponse -} - -// CreateOrUpdate ... -func (c ActionsClient) CreateOrUpdate(ctx context.Context, id ActionId, input ActionRequest) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c ActionsClient) preparerForCreateOrUpdate(ctx context.Context, id ActionId, input ActionRequest) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c ActionsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-02-01/actions/method_delete.go b/resource-manager/securityinsights/2023-02-01/actions/method_delete.go new file mode 100644 index 00000000000..0f8a28307c2 --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/actions/method_delete.go @@ -0,0 +1,47 @@ +package actions + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c ActionsClient) Delete(ctx context.Context, id ActionId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/actions/method_delete_autorest.go b/resource-manager/securityinsights/2023-02-01/actions/method_delete_autorest.go deleted file mode 100644 index d142f9f3054..00000000000 --- a/resource-manager/securityinsights/2023-02-01/actions/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package actions - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c ActionsClient) Delete(ctx context.Context, id ActionId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c ActionsClient) preparerForDelete(ctx context.Context, id ActionId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c ActionsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-02-01/actions/method_get.go b/resource-manager/securityinsights/2023-02-01/actions/method_get.go new file mode 100644 index 00000000000..76d3593e1f1 --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/actions/method_get.go @@ -0,0 +1,51 @@ +package actions + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ActionResponse +} + +// Get ... +func (c ActionsClient) Get(ctx context.Context, id ActionId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/actions/method_get_autorest.go b/resource-manager/securityinsights/2023-02-01/actions/method_get_autorest.go deleted file mode 100644 index aa1388a0c31..00000000000 --- a/resource-manager/securityinsights/2023-02-01/actions/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package actions - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *ActionResponse -} - -// Get ... -func (c ActionsClient) Get(ctx context.Context, id ActionId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c ActionsClient) preparerForGet(ctx context.Context, id ActionId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c ActionsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-02-01/actions/method_listbyalertrule.go b/resource-manager/securityinsights/2023-02-01/actions/method_listbyalertrule.go new file mode 100644 index 00000000000..09d32b9d82d --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/actions/method_listbyalertrule.go @@ -0,0 +1,91 @@ +package actions + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByAlertRuleOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ActionResponse +} + +type ListByAlertRuleCompleteResult struct { + LatestHttpResponse *http.Response + Items []ActionResponse +} + +// ListByAlertRule ... +func (c ActionsClient) ListByAlertRule(ctx context.Context, id AlertRuleId) (result ListByAlertRuleOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/actions", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ActionResponse `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByAlertRuleComplete retrieves all the results into a single object +func (c ActionsClient) ListByAlertRuleComplete(ctx context.Context, id AlertRuleId) (ListByAlertRuleCompleteResult, error) { + return c.ListByAlertRuleCompleteMatchingPredicate(ctx, id, ActionResponseOperationPredicate{}) +} + +// ListByAlertRuleCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ActionsClient) ListByAlertRuleCompleteMatchingPredicate(ctx context.Context, id AlertRuleId, predicate ActionResponseOperationPredicate) (result ListByAlertRuleCompleteResult, err error) { + items := make([]ActionResponse, 0) + + resp, err := c.ListByAlertRule(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByAlertRuleCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2023-02-01/actions/method_listbyalertrule_autorest.go b/resource-manager/securityinsights/2023-02-01/actions/method_listbyalertrule_autorest.go deleted file mode 100644 index a58a9738f1f..00000000000 --- a/resource-manager/securityinsights/2023-02-01/actions/method_listbyalertrule_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package actions - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListByAlertRuleOperationResponse struct { - HttpResponse *http.Response - Model *[]ActionResponse - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListByAlertRuleOperationResponse, error) -} - -type ListByAlertRuleCompleteResult struct { - Items []ActionResponse -} - -func (r ListByAlertRuleOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListByAlertRuleOperationResponse) LoadMore(ctx context.Context) (resp ListByAlertRuleOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// ListByAlertRule ... -func (c ActionsClient) ListByAlertRule(ctx context.Context, id AlertRuleId) (resp ListByAlertRuleOperationResponse, err error) { - req, err := c.preparerForListByAlertRule(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "ListByAlertRule", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "ListByAlertRule", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForListByAlertRule(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "ListByAlertRule", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForListByAlertRule prepares the ListByAlertRule request. -func (c ActionsClient) preparerForListByAlertRule(ctx context.Context, id AlertRuleId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/actions", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListByAlertRuleWithNextLink prepares the ListByAlertRule request with the given nextLink token. -func (c ActionsClient) preparerForListByAlertRuleWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForListByAlertRule handles the response to the ListByAlertRule request. The method always -// closes the http.Response Body. -func (c ActionsClient) responderForListByAlertRule(resp *http.Response) (result ListByAlertRuleOperationResponse, err error) { - type page struct { - Values []ActionResponse `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByAlertRuleOperationResponse, err error) { - req, err := c.preparerForListByAlertRuleWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "ListByAlertRule", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "ListByAlertRule", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForListByAlertRule(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "ListByAlertRule", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListByAlertRuleComplete retrieves all of the results into a single object -func (c ActionsClient) ListByAlertRuleComplete(ctx context.Context, id AlertRuleId) (ListByAlertRuleCompleteResult, error) { - return c.ListByAlertRuleCompleteMatchingPredicate(ctx, id, ActionResponseOperationPredicate{}) -} - -// ListByAlertRuleCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c ActionsClient) ListByAlertRuleCompleteMatchingPredicate(ctx context.Context, id AlertRuleId, predicate ActionResponseOperationPredicate) (resp ListByAlertRuleCompleteResult, err error) { - items := make([]ActionResponse, 0) - - page, err := c.ListByAlertRule(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListByAlertRuleCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2023-02-01/alertrules/client.go b/resource-manager/securityinsights/2023-02-01/alertrules/client.go index 6e34bca2ce3..e6ca04af9da 100644 --- a/resource-manager/securityinsights/2023-02-01/alertrules/client.go +++ b/resource-manager/securityinsights/2023-02-01/alertrules/client.go @@ -1,18 +1,26 @@ package alertrules -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type AlertRulesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewAlertRulesClientWithBaseURI(endpoint string) AlertRulesClient { - return AlertRulesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewAlertRulesClientWithBaseURI(sdkApi sdkEnv.Api) (*AlertRulesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "alertrules", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AlertRulesClient: %+v", err) } + + return &AlertRulesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2023-02-01/alertrules/constants.go b/resource-manager/securityinsights/2023-02-01/alertrules/constants.go index 5d1bc78496f..fb693333ff0 100644 --- a/resource-manager/securityinsights/2023-02-01/alertrules/constants.go +++ b/resource-manager/securityinsights/2023-02-01/alertrules/constants.go @@ -1,6 +1,10 @@ package alertrules -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -19,6 +23,19 @@ func PossibleValuesForAlertDetail() []string { } } +func (s *AlertDetail) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertDetail(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertDetail(input string) (*AlertDetail, error) { vals := map[string]AlertDetail{ "displayname": AlertDetailDisplayName, @@ -61,6 +78,19 @@ func PossibleValuesForAlertProperty() []string { } } +func (s *AlertProperty) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertProperty(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertProperty(input string) (*AlertProperty, error) { vals := map[string]AlertProperty{ "alertlink": AlertPropertyAlertLink, @@ -98,6 +128,19 @@ func PossibleValuesForAlertRuleKind() []string { } } +func (s *AlertRuleKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertRuleKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertRuleKind(input string) (*AlertRuleKind, error) { vals := map[string]AlertRuleKind{ "fusion": AlertRuleKindFusion, @@ -131,6 +174,19 @@ func PossibleValuesForAlertSeverity() []string { } } +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertSeverity(input string) (*AlertSeverity, error) { vals := map[string]AlertSeverity{ "high": AlertSeverityHigh, @@ -191,6 +247,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -266,6 +335,19 @@ func PossibleValuesForEntityMappingType() []string { } } +func (s *EntityMappingType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityMappingType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityMappingType(input string) (*EntityMappingType, error) { vals := map[string]EntityMappingType{ "account": EntityMappingTypeAccount, @@ -310,6 +392,19 @@ func PossibleValuesForEventGroupingAggregationKind() []string { } } +func (s *EventGroupingAggregationKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEventGroupingAggregationKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEventGroupingAggregationKind(input string) (*EventGroupingAggregationKind, error) { vals := map[string]EventGroupingAggregationKind{ "alertperresult": EventGroupingAggregationKindAlertPerResult, @@ -340,6 +435,19 @@ func PossibleValuesForMatchingMethod() []string { } } +func (s *MatchingMethod) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMatchingMethod(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseMatchingMethod(input string) (*MatchingMethod, error) { vals := map[string]MatchingMethod{ "allentities": MatchingMethodAllEntities, @@ -375,6 +483,19 @@ func PossibleValuesForMicrosoftSecurityProductName() []string { } } +func (s *MicrosoftSecurityProductName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMicrosoftSecurityProductName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseMicrosoftSecurityProductName(input string) (*MicrosoftSecurityProductName, error) { vals := map[string]MicrosoftSecurityProductName{ "azure active directory identity protection": MicrosoftSecurityProductNameAzureActiveDirectoryIdentityProtection, @@ -410,6 +531,19 @@ func PossibleValuesForTriggerOperator() []string { } } +func (s *TriggerOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTriggerOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseTriggerOperator(input string) (*TriggerOperator, error) { vals := map[string]TriggerOperator{ "equal": TriggerOperatorEqual, diff --git a/resource-manager/securityinsights/2023-02-01/alertrules/method_createorupdate.go b/resource-manager/securityinsights/2023-02-01/alertrules/method_createorupdate.go new file mode 100644 index 00000000000..f77c7558d09 --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/alertrules/method_createorupdate.go @@ -0,0 +1,63 @@ +package alertrules + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AlertRule +} + +// CreateOrUpdate ... +func (c AlertRulesClient) CreateOrUpdate(ctx context.Context, id AlertRuleId, input AlertRule) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalAlertRuleImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/alertrules/method_createorupdate_autorest.go b/resource-manager/securityinsights/2023-02-01/alertrules/method_createorupdate_autorest.go deleted file mode 100644 index 548f6c4ef37..00000000000 --- a/resource-manager/securityinsights/2023-02-01/alertrules/method_createorupdate_autorest.go +++ /dev/null @@ -1,78 +0,0 @@ -package alertrules - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *AlertRule -} - -// CreateOrUpdate ... -func (c AlertRulesClient) CreateOrUpdate(ctx context.Context, id AlertRuleId, input AlertRule) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c AlertRulesClient) preparerForCreateOrUpdate(ctx context.Context, id AlertRuleId, input AlertRule) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c AlertRulesClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalAlertRuleImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2023-02-01/alertrules/method_delete.go b/resource-manager/securityinsights/2023-02-01/alertrules/method_delete.go new file mode 100644 index 00000000000..aae7085c25e --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/alertrules/method_delete.go @@ -0,0 +1,47 @@ +package alertrules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c AlertRulesClient) Delete(ctx context.Context, id AlertRuleId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/alertrules/method_delete_autorest.go b/resource-manager/securityinsights/2023-02-01/alertrules/method_delete_autorest.go deleted file mode 100644 index 417e1a0017e..00000000000 --- a/resource-manager/securityinsights/2023-02-01/alertrules/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package alertrules - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c AlertRulesClient) Delete(ctx context.Context, id AlertRuleId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c AlertRulesClient) preparerForDelete(ctx context.Context, id AlertRuleId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c AlertRulesClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-02-01/alertrules/method_get.go b/resource-manager/securityinsights/2023-02-01/alertrules/method_get.go new file mode 100644 index 00000000000..945c07bfad1 --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/alertrules/method_get.go @@ -0,0 +1,58 @@ +package alertrules + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AlertRule +} + +// Get ... +func (c AlertRulesClient) Get(ctx context.Context, id AlertRuleId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalAlertRuleImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/alertrules/method_get_autorest.go b/resource-manager/securityinsights/2023-02-01/alertrules/method_get_autorest.go deleted file mode 100644 index ddd1836d4de..00000000000 --- a/resource-manager/securityinsights/2023-02-01/alertrules/method_get_autorest.go +++ /dev/null @@ -1,77 +0,0 @@ -package alertrules - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *AlertRule -} - -// Get ... -func (c AlertRulesClient) Get(ctx context.Context, id AlertRuleId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c AlertRulesClient) preparerForGet(ctx context.Context, id AlertRuleId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c AlertRulesClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalAlertRuleImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2023-02-01/alertrules/method_list.go b/resource-manager/securityinsights/2023-02-01/alertrules/method_list.go new file mode 100644 index 00000000000..5ac99496167 --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/alertrules/method_list.go @@ -0,0 +1,103 @@ +package alertrules + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AlertRule +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []AlertRule +} + +// List ... +func (c AlertRulesClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/alertRules", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]AlertRule, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalAlertRuleImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for AlertRule (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// ListComplete retrieves all the results into a single object +func (c AlertRulesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, AlertRuleOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AlertRulesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AlertRuleOperationPredicate) (result ListCompleteResult, err error) { + items := make([]AlertRule, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2023-02-01/alertrules/method_list_autorest.go b/resource-manager/securityinsights/2023-02-01/alertrules/method_list_autorest.go deleted file mode 100644 index f06cf0f6241..00000000000 --- a/resource-manager/securityinsights/2023-02-01/alertrules/method_list_autorest.go +++ /dev/null @@ -1,196 +0,0 @@ -package alertrules - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]AlertRule - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []AlertRule -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c AlertRulesClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c AlertRulesClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/alertRules", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c AlertRulesClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c AlertRulesClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]AlertRule, 0) - for i, v := range respObj.Values { - val, err := unmarshalAlertRuleImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for AlertRule (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c AlertRulesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, AlertRuleOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c AlertRulesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AlertRuleOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]AlertRule, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2023-02-01/alertruletemplates/client.go b/resource-manager/securityinsights/2023-02-01/alertruletemplates/client.go index c439e5a41c7..2932bf14a55 100644 --- a/resource-manager/securityinsights/2023-02-01/alertruletemplates/client.go +++ b/resource-manager/securityinsights/2023-02-01/alertruletemplates/client.go @@ -1,18 +1,26 @@ package alertruletemplates -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type AlertRuleTemplatesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewAlertRuleTemplatesClientWithBaseURI(endpoint string) AlertRuleTemplatesClient { - return AlertRuleTemplatesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewAlertRuleTemplatesClientWithBaseURI(sdkApi sdkEnv.Api) (*AlertRuleTemplatesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "alertruletemplates", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AlertRuleTemplatesClient: %+v", err) } + + return &AlertRuleTemplatesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2023-02-01/alertruletemplates/constants.go b/resource-manager/securityinsights/2023-02-01/alertruletemplates/constants.go index c69aaf1ed65..0f9acf0ddf0 100644 --- a/resource-manager/securityinsights/2023-02-01/alertruletemplates/constants.go +++ b/resource-manager/securityinsights/2023-02-01/alertruletemplates/constants.go @@ -1,6 +1,10 @@ package alertruletemplates -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -33,6 +37,19 @@ func PossibleValuesForAlertProperty() []string { } } +func (s *AlertProperty) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertProperty(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertProperty(input string) (*AlertProperty, error) { vals := map[string]AlertProperty{ "alertlink": AlertPropertyAlertLink, @@ -70,6 +87,19 @@ func PossibleValuesForAlertRuleKind() []string { } } +func (s *AlertRuleKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertRuleKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertRuleKind(input string) (*AlertRuleKind, error) { vals := map[string]AlertRuleKind{ "fusion": AlertRuleKindFusion, @@ -103,6 +133,19 @@ func PossibleValuesForAlertSeverity() []string { } } +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertSeverity(input string) (*AlertSeverity, error) { vals := map[string]AlertSeverity{ "high": AlertSeverityHigh, @@ -163,6 +206,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -238,6 +294,19 @@ func PossibleValuesForEntityMappingType() []string { } } +func (s *EntityMappingType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityMappingType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityMappingType(input string) (*EntityMappingType, error) { vals := map[string]EntityMappingType{ "account": EntityMappingTypeAccount, @@ -282,6 +351,19 @@ func PossibleValuesForEventGroupingAggregationKind() []string { } } +func (s *EventGroupingAggregationKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEventGroupingAggregationKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEventGroupingAggregationKind(input string) (*EventGroupingAggregationKind, error) { vals := map[string]EventGroupingAggregationKind{ "alertperresult": EventGroupingAggregationKindAlertPerResult, @@ -316,6 +398,19 @@ func PossibleValuesForMicrosoftSecurityProductName() []string { } } +func (s *MicrosoftSecurityProductName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMicrosoftSecurityProductName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseMicrosoftSecurityProductName(input string) (*MicrosoftSecurityProductName, error) { vals := map[string]MicrosoftSecurityProductName{ "azure active directory identity protection": MicrosoftSecurityProductNameAzureActiveDirectoryIdentityProtection, @@ -349,6 +444,19 @@ func PossibleValuesForTemplateStatus() []string { } } +func (s *TemplateStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTemplateStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseTemplateStatus(input string) (*TemplateStatus, error) { vals := map[string]TemplateStatus{ "available": TemplateStatusAvailable, @@ -382,6 +490,19 @@ func PossibleValuesForTriggerOperator() []string { } } +func (s *TriggerOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTriggerOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseTriggerOperator(input string) (*TriggerOperator, error) { vals := map[string]TriggerOperator{ "equal": TriggerOperatorEqual, diff --git a/resource-manager/securityinsights/2023-02-01/alertruletemplates/method_get.go b/resource-manager/securityinsights/2023-02-01/alertruletemplates/method_get.go new file mode 100644 index 00000000000..861712be66a --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/alertruletemplates/method_get.go @@ -0,0 +1,58 @@ +package alertruletemplates + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AlertRuleTemplate +} + +// Get ... +func (c AlertRuleTemplatesClient) Get(ctx context.Context, id AlertRuleTemplateId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalAlertRuleTemplateImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/alertruletemplates/method_get_autorest.go b/resource-manager/securityinsights/2023-02-01/alertruletemplates/method_get_autorest.go deleted file mode 100644 index ad4e0487d83..00000000000 --- a/resource-manager/securityinsights/2023-02-01/alertruletemplates/method_get_autorest.go +++ /dev/null @@ -1,77 +0,0 @@ -package alertruletemplates - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *AlertRuleTemplate -} - -// Get ... -func (c AlertRuleTemplatesClient) Get(ctx context.Context, id AlertRuleTemplateId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c AlertRuleTemplatesClient) preparerForGet(ctx context.Context, id AlertRuleTemplateId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c AlertRuleTemplatesClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalAlertRuleTemplateImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2023-02-01/alertruletemplates/method_list.go b/resource-manager/securityinsights/2023-02-01/alertruletemplates/method_list.go new file mode 100644 index 00000000000..21f9ceec3de --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/alertruletemplates/method_list.go @@ -0,0 +1,103 @@ +package alertruletemplates + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AlertRuleTemplate +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []AlertRuleTemplate +} + +// List ... +func (c AlertRuleTemplatesClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/alertRuleTemplates", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]AlertRuleTemplate, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalAlertRuleTemplateImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for AlertRuleTemplate (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// ListComplete retrieves all the results into a single object +func (c AlertRuleTemplatesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, AlertRuleTemplateOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AlertRuleTemplatesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AlertRuleTemplateOperationPredicate) (result ListCompleteResult, err error) { + items := make([]AlertRuleTemplate, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2023-02-01/alertruletemplates/method_list_autorest.go b/resource-manager/securityinsights/2023-02-01/alertruletemplates/method_list_autorest.go deleted file mode 100644 index 56794382966..00000000000 --- a/resource-manager/securityinsights/2023-02-01/alertruletemplates/method_list_autorest.go +++ /dev/null @@ -1,196 +0,0 @@ -package alertruletemplates - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]AlertRuleTemplate - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []AlertRuleTemplate -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c AlertRuleTemplatesClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c AlertRuleTemplatesClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/alertRuleTemplates", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c AlertRuleTemplatesClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c AlertRuleTemplatesClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]AlertRuleTemplate, 0) - for i, v := range respObj.Values { - val, err := unmarshalAlertRuleTemplateImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for AlertRuleTemplate (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c AlertRuleTemplatesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, AlertRuleTemplateOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c AlertRuleTemplatesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AlertRuleTemplateOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]AlertRuleTemplate, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2023-02-01/automationrules/client.go b/resource-manager/securityinsights/2023-02-01/automationrules/client.go index 960f049c387..18fafea1496 100644 --- a/resource-manager/securityinsights/2023-02-01/automationrules/client.go +++ b/resource-manager/securityinsights/2023-02-01/automationrules/client.go @@ -1,18 +1,26 @@ package automationrules -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type AutomationRulesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewAutomationRulesClientWithBaseURI(endpoint string) AutomationRulesClient { - return AutomationRulesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewAutomationRulesClientWithBaseURI(sdkApi sdkEnv.Api) (*AutomationRulesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "automationrules", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AutomationRulesClient: %+v", err) } + + return &AutomationRulesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2023-02-01/automationrules/constants.go b/resource-manager/securityinsights/2023-02-01/automationrules/constants.go index 42f2fc009f2..71480e3d3d7 100644 --- a/resource-manager/securityinsights/2023-02-01/automationrules/constants.go +++ b/resource-manager/securityinsights/2023-02-01/automationrules/constants.go @@ -1,6 +1,10 @@ package automationrules -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -19,6 +23,19 @@ func PossibleValuesForActionType() []string { } } +func (s *ActionType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseActionType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseActionType(input string) (*ActionType, error) { vals := map[string]ActionType{ "modifyproperties": ActionTypeModifyProperties, @@ -51,6 +68,19 @@ func PossibleValuesForAutomationRulePropertyArrayChangedConditionSupportedArrayT } } +func (s *AutomationRulePropertyArrayChangedConditionSupportedArrayType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRulePropertyArrayChangedConditionSupportedArrayType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAutomationRulePropertyArrayChangedConditionSupportedArrayType(input string) (*AutomationRulePropertyArrayChangedConditionSupportedArrayType, error) { vals := map[string]AutomationRulePropertyArrayChangedConditionSupportedArrayType{ "alerts": AutomationRulePropertyArrayChangedConditionSupportedArrayTypeAlerts, @@ -79,6 +109,19 @@ func PossibleValuesForAutomationRulePropertyArrayChangedConditionSupportedChange } } +func (s *AutomationRulePropertyArrayChangedConditionSupportedChangeType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRulePropertyArrayChangedConditionSupportedChangeType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAutomationRulePropertyArrayChangedConditionSupportedChangeType(input string) (*AutomationRulePropertyArrayChangedConditionSupportedChangeType, error) { vals := map[string]AutomationRulePropertyArrayChangedConditionSupportedChangeType{ "added": AutomationRulePropertyArrayChangedConditionSupportedChangeTypeAdded, @@ -106,6 +149,19 @@ func PossibleValuesForAutomationRulePropertyChangedConditionSupportedChangedType } } +func (s *AutomationRulePropertyChangedConditionSupportedChangedType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRulePropertyChangedConditionSupportedChangedType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAutomationRulePropertyChangedConditionSupportedChangedType(input string) (*AutomationRulePropertyChangedConditionSupportedChangedType, error) { vals := map[string]AutomationRulePropertyChangedConditionSupportedChangedType{ "changedfrom": AutomationRulePropertyChangedConditionSupportedChangedTypeChangedFrom, @@ -136,6 +192,19 @@ func PossibleValuesForAutomationRulePropertyChangedConditionSupportedPropertyTyp } } +func (s *AutomationRulePropertyChangedConditionSupportedPropertyType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRulePropertyChangedConditionSupportedPropertyType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAutomationRulePropertyChangedConditionSupportedPropertyType(input string) (*AutomationRulePropertyChangedConditionSupportedPropertyType, error) { vals := map[string]AutomationRulePropertyChangedConditionSupportedPropertyType{ "incidentowner": AutomationRulePropertyChangedConditionSupportedPropertyTypeIncidentOwner, @@ -177,6 +246,19 @@ func PossibleValuesForAutomationRulePropertyConditionSupportedOperator() []strin } } +func (s *AutomationRulePropertyConditionSupportedOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRulePropertyConditionSupportedOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAutomationRulePropertyConditionSupportedOperator(input string) (*AutomationRulePropertyConditionSupportedOperator, error) { vals := map[string]AutomationRulePropertyConditionSupportedOperator{ "contains": AutomationRulePropertyConditionSupportedOperatorContains, @@ -319,6 +401,19 @@ func PossibleValuesForAutomationRulePropertyConditionSupportedProperty() []strin } } +func (s *AutomationRulePropertyConditionSupportedProperty) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRulePropertyConditionSupportedProperty(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAutomationRulePropertyConditionSupportedProperty(input string) (*AutomationRulePropertyConditionSupportedProperty, error) { vals := map[string]AutomationRulePropertyConditionSupportedProperty{ "accountaadtenantid": AutomationRulePropertyConditionSupportedPropertyAccountAadTenantId, @@ -403,6 +498,19 @@ func PossibleValuesForConditionType() []string { } } +func (s *ConditionType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConditionType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConditionType(input string) (*ConditionType, error) { vals := map[string]ConditionType{ "property": ConditionTypeProperty, @@ -436,6 +544,19 @@ func PossibleValuesForIncidentClassification() []string { } } +func (s *IncidentClassification) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentClassification(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentClassification(input string) (*IncidentClassification, error) { vals := map[string]IncidentClassification{ "benignpositive": IncidentClassificationBenignPositive, @@ -470,6 +591,19 @@ func PossibleValuesForIncidentClassificationReason() []string { } } +func (s *IncidentClassificationReason) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentClassificationReason(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentClassificationReason(input string) (*IncidentClassificationReason, error) { vals := map[string]IncidentClassificationReason{ "inaccuratedata": IncidentClassificationReasonInaccurateData, @@ -500,6 +634,19 @@ func PossibleValuesForIncidentLabelType() []string { } } +func (s *IncidentLabelType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentLabelType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentLabelType(input string) (*IncidentLabelType, error) { vals := map[string]IncidentLabelType{ "autoassigned": IncidentLabelTypeAutoAssigned, @@ -532,6 +679,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, @@ -564,6 +724,19 @@ func PossibleValuesForIncidentStatus() []string { } } +func (s *IncidentStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentStatus(input string) (*IncidentStatus, error) { vals := map[string]IncidentStatus{ "active": IncidentStatusActive, @@ -595,6 +768,19 @@ func PossibleValuesForOwnerType() []string { } } +func (s *OwnerType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOwnerType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseOwnerType(input string) (*OwnerType, error) { vals := map[string]OwnerType{ "group": OwnerTypeGroup, @@ -624,6 +810,19 @@ func PossibleValuesForTriggersOn() []string { } } +func (s *TriggersOn) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTriggersOn(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseTriggersOn(input string) (*TriggersOn, error) { vals := map[string]TriggersOn{ "alerts": TriggersOnAlerts, @@ -652,6 +851,19 @@ func PossibleValuesForTriggersWhen() []string { } } +func (s *TriggersWhen) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTriggersWhen(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseTriggersWhen(input string) (*TriggersWhen, error) { vals := map[string]TriggersWhen{ "created": TriggersWhenCreated, diff --git a/resource-manager/securityinsights/2023-02-01/automationrules/method_createorupdate.go b/resource-manager/securityinsights/2023-02-01/automationrules/method_createorupdate.go new file mode 100644 index 00000000000..c0b3c44f2da --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/automationrules/method_createorupdate.go @@ -0,0 +1,56 @@ +package automationrules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AutomationRule +} + +// CreateOrUpdate ... +func (c AutomationRulesClient) CreateOrUpdate(ctx context.Context, id AutomationRuleId, input AutomationRule) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/automationrules/method_createorupdate_autorest.go b/resource-manager/securityinsights/2023-02-01/automationrules/method_createorupdate_autorest.go deleted file mode 100644 index 790f2ff99f9..00000000000 --- a/resource-manager/securityinsights/2023-02-01/automationrules/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package automationrules - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *AutomationRule -} - -// CreateOrUpdate ... -func (c AutomationRulesClient) CreateOrUpdate(ctx context.Context, id AutomationRuleId, input AutomationRule) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c AutomationRulesClient) preparerForCreateOrUpdate(ctx context.Context, id AutomationRuleId, input AutomationRule) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c AutomationRulesClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-02-01/automationrules/method_delete.go b/resource-manager/securityinsights/2023-02-01/automationrules/method_delete.go new file mode 100644 index 00000000000..682e97ed619 --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/automationrules/method_delete.go @@ -0,0 +1,52 @@ +package automationrules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *interface{} +} + +// Delete ... +func (c AutomationRulesClient) Delete(ctx context.Context, id AutomationRuleId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/automationrules/method_delete_autorest.go b/resource-manager/securityinsights/2023-02-01/automationrules/method_delete_autorest.go deleted file mode 100644 index cd33f79070e..00000000000 --- a/resource-manager/securityinsights/2023-02-01/automationrules/method_delete_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package automationrules - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response - Model *interface{} -} - -// Delete ... -func (c AutomationRulesClient) Delete(ctx context.Context, id AutomationRuleId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c AutomationRulesClient) preparerForDelete(ctx context.Context, id AutomationRuleId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c AutomationRulesClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-02-01/automationrules/method_get.go b/resource-manager/securityinsights/2023-02-01/automationrules/method_get.go new file mode 100644 index 00000000000..0676dc80f40 --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/automationrules/method_get.go @@ -0,0 +1,51 @@ +package automationrules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AutomationRule +} + +// Get ... +func (c AutomationRulesClient) Get(ctx context.Context, id AutomationRuleId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/automationrules/method_get_autorest.go b/resource-manager/securityinsights/2023-02-01/automationrules/method_get_autorest.go deleted file mode 100644 index 20f385aa8d7..00000000000 --- a/resource-manager/securityinsights/2023-02-01/automationrules/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package automationrules - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *AutomationRule -} - -// Get ... -func (c AutomationRulesClient) Get(ctx context.Context, id AutomationRuleId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c AutomationRulesClient) preparerForGet(ctx context.Context, id AutomationRuleId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c AutomationRulesClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-02-01/automationrules/method_list.go b/resource-manager/securityinsights/2023-02-01/automationrules/method_list.go new file mode 100644 index 00000000000..a3c7db4995a --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/automationrules/method_list.go @@ -0,0 +1,91 @@ +package automationrules + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AutomationRule +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []AutomationRule +} + +// List ... +func (c AutomationRulesClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/automationRules", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]AutomationRule `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c AutomationRulesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, AutomationRuleOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AutomationRulesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AutomationRuleOperationPredicate) (result ListCompleteResult, err error) { + items := make([]AutomationRule, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2023-02-01/automationrules/method_list_autorest.go b/resource-manager/securityinsights/2023-02-01/automationrules/method_list_autorest.go deleted file mode 100644 index e2818088fcf..00000000000 --- a/resource-manager/securityinsights/2023-02-01/automationrules/method_list_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package automationrules - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]AutomationRule - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []AutomationRule -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c AutomationRulesClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c AutomationRulesClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/automationRules", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c AutomationRulesClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c AutomationRulesClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []AutomationRule `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c AutomationRulesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, AutomationRuleOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c AutomationRulesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AutomationRuleOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]AutomationRule, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2023-02-01/bookmarks/client.go b/resource-manager/securityinsights/2023-02-01/bookmarks/client.go index ee8ca229e2d..22469155649 100644 --- a/resource-manager/securityinsights/2023-02-01/bookmarks/client.go +++ b/resource-manager/securityinsights/2023-02-01/bookmarks/client.go @@ -1,18 +1,26 @@ package bookmarks -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type BookmarksClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewBookmarksClientWithBaseURI(endpoint string) BookmarksClient { - return BookmarksClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewBookmarksClientWithBaseURI(sdkApi sdkEnv.Api) (*BookmarksClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "bookmarks", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating BookmarksClient: %+v", err) } + + return &BookmarksClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2023-02-01/bookmarks/constants.go b/resource-manager/securityinsights/2023-02-01/bookmarks/constants.go index f3a9bf2482b..c057284aed1 100644 --- a/resource-manager/securityinsights/2023-02-01/bookmarks/constants.go +++ b/resource-manager/securityinsights/2023-02-01/bookmarks/constants.go @@ -1,6 +1,10 @@ package bookmarks -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -23,6 +27,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, diff --git a/resource-manager/securityinsights/2023-02-01/bookmarks/method_createorupdate.go b/resource-manager/securityinsights/2023-02-01/bookmarks/method_createorupdate.go new file mode 100644 index 00000000000..72b6987ce5b --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/bookmarks/method_createorupdate.go @@ -0,0 +1,56 @@ +package bookmarks + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Bookmark +} + +// CreateOrUpdate ... +func (c BookmarksClient) CreateOrUpdate(ctx context.Context, id BookmarkId, input Bookmark) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/bookmarks/method_createorupdate_autorest.go b/resource-manager/securityinsights/2023-02-01/bookmarks/method_createorupdate_autorest.go deleted file mode 100644 index 6bae46884df..00000000000 --- a/resource-manager/securityinsights/2023-02-01/bookmarks/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package bookmarks - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *Bookmark -} - -// CreateOrUpdate ... -func (c BookmarksClient) CreateOrUpdate(ctx context.Context, id BookmarkId, input Bookmark) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c BookmarksClient) preparerForCreateOrUpdate(ctx context.Context, id BookmarkId, input Bookmark) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c BookmarksClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-02-01/bookmarks/method_delete.go b/resource-manager/securityinsights/2023-02-01/bookmarks/method_delete.go new file mode 100644 index 00000000000..75eef715a7c --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/bookmarks/method_delete.go @@ -0,0 +1,47 @@ +package bookmarks + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c BookmarksClient) Delete(ctx context.Context, id BookmarkId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/bookmarks/method_delete_autorest.go b/resource-manager/securityinsights/2023-02-01/bookmarks/method_delete_autorest.go deleted file mode 100644 index aa1033f513c..00000000000 --- a/resource-manager/securityinsights/2023-02-01/bookmarks/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package bookmarks - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c BookmarksClient) Delete(ctx context.Context, id BookmarkId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c BookmarksClient) preparerForDelete(ctx context.Context, id BookmarkId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c BookmarksClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-02-01/bookmarks/method_get.go b/resource-manager/securityinsights/2023-02-01/bookmarks/method_get.go new file mode 100644 index 00000000000..b8db3d1b69f --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/bookmarks/method_get.go @@ -0,0 +1,51 @@ +package bookmarks + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Bookmark +} + +// Get ... +func (c BookmarksClient) Get(ctx context.Context, id BookmarkId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/bookmarks/method_get_autorest.go b/resource-manager/securityinsights/2023-02-01/bookmarks/method_get_autorest.go deleted file mode 100644 index c76a6c0c211..00000000000 --- a/resource-manager/securityinsights/2023-02-01/bookmarks/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package bookmarks - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *Bookmark -} - -// Get ... -func (c BookmarksClient) Get(ctx context.Context, id BookmarkId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c BookmarksClient) preparerForGet(ctx context.Context, id BookmarkId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c BookmarksClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-02-01/bookmarks/method_list.go b/resource-manager/securityinsights/2023-02-01/bookmarks/method_list.go new file mode 100644 index 00000000000..432b04c413a --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/bookmarks/method_list.go @@ -0,0 +1,91 @@ +package bookmarks + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Bookmark +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Bookmark +} + +// List ... +func (c BookmarksClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/bookmarks", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Bookmark `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c BookmarksClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, BookmarkOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c BookmarksClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate BookmarkOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Bookmark, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2023-02-01/bookmarks/method_list_autorest.go b/resource-manager/securityinsights/2023-02-01/bookmarks/method_list_autorest.go deleted file mode 100644 index 7c4a69eacea..00000000000 --- a/resource-manager/securityinsights/2023-02-01/bookmarks/method_list_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package bookmarks - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]Bookmark - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []Bookmark -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c BookmarksClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c BookmarksClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/bookmarks", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c BookmarksClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c BookmarksClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []Bookmark `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c BookmarksClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, BookmarkOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c BookmarksClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate BookmarkOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]Bookmark, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2023-02-01/client.go b/resource-manager/securityinsights/2023-02-01/client.go index c874eefd2a0..28bc3c65176 100644 --- a/resource-manager/securityinsights/2023-02-01/client.go +++ b/resource-manager/securityinsights/2023-02-01/client.go @@ -4,7 +4,8 @@ package v2023_02_01 // Licensed under the MIT License. See NOTICE.txt in the project root for license information. import ( - "github.com/Azure/go-autorest/autorest" + "fmt" + "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2023-02-01/actions" "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2023-02-01/alertrules" "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2023-02-01/alertruletemplates" @@ -24,6 +25,8 @@ import ( "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2023-02-01/threatintelligence" "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2023-02-01/watchlistitems" "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2023-02-01/watchlists" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" ) type Client struct { @@ -48,84 +51,140 @@ type Client struct { Watchlists *watchlists.WatchlistsClient } -func NewClientWithBaseURI(endpoint string, configureAuthFunc func(c *autorest.Client)) Client { - - actionsClient := actions.NewActionsClientWithBaseURI(endpoint) - configureAuthFunc(&actionsClient.Client) - - alertRuleTemplatesClient := alertruletemplates.NewAlertRuleTemplatesClientWithBaseURI(endpoint) - configureAuthFunc(&alertRuleTemplatesClient.Client) +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + actionsClient, err := actions.NewActionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Actions client: %+v", err) + } + configureFunc(actionsClient.Client) - alertRulesClient := alertrules.NewAlertRulesClientWithBaseURI(endpoint) - configureAuthFunc(&alertRulesClient.Client) + alertRuleTemplatesClient, err := alertruletemplates.NewAlertRuleTemplatesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AlertRuleTemplates client: %+v", err) + } + configureFunc(alertRuleTemplatesClient.Client) - automationRulesClient := automationrules.NewAutomationRulesClientWithBaseURI(endpoint) - configureAuthFunc(&automationRulesClient.Client) + alertRulesClient, err := alertrules.NewAlertRulesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AlertRules client: %+v", err) + } + configureFunc(alertRulesClient.Client) - bookmarksClient := bookmarks.NewBookmarksClientWithBaseURI(endpoint) - configureAuthFunc(&bookmarksClient.Client) + automationRulesClient, err := automationrules.NewAutomationRulesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AutomationRules client: %+v", err) + } + configureFunc(automationRulesClient.Client) - dataConnectorsClient := dataconnectors.NewDataConnectorsClientWithBaseURI(endpoint) - configureAuthFunc(&dataConnectorsClient.Client) + bookmarksClient, err := bookmarks.NewBookmarksClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Bookmarks client: %+v", err) + } + configureFunc(bookmarksClient.Client) - entityTypesClient := entitytypes.NewEntityTypesClientWithBaseURI(endpoint) - configureAuthFunc(&entityTypesClient.Client) + dataConnectorsClient, err := dataconnectors.NewDataConnectorsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DataConnectors client: %+v", err) + } + configureFunc(dataConnectorsClient.Client) - incidentAlertsClient := incidentalerts.NewIncidentAlertsClientWithBaseURI(endpoint) - configureAuthFunc(&incidentAlertsClient.Client) + entityTypesClient, err := entitytypes.NewEntityTypesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building EntityTypes client: %+v", err) + } + configureFunc(entityTypesClient.Client) - incidentBookmarksClient := incidentbookmarks.NewIncidentBookmarksClientWithBaseURI(endpoint) - configureAuthFunc(&incidentBookmarksClient.Client) + incidentAlertsClient, err := incidentalerts.NewIncidentAlertsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IncidentAlerts client: %+v", err) + } + configureFunc(incidentAlertsClient.Client) - incidentCommentsClient := incidentcomments.NewIncidentCommentsClientWithBaseURI(endpoint) - configureAuthFunc(&incidentCommentsClient.Client) + incidentBookmarksClient, err := incidentbookmarks.NewIncidentBookmarksClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IncidentBookmarks client: %+v", err) + } + configureFunc(incidentBookmarksClient.Client) - incidentEntitiesClient := incidententities.NewIncidentEntitiesClientWithBaseURI(endpoint) - configureAuthFunc(&incidentEntitiesClient.Client) + incidentCommentsClient, err := incidentcomments.NewIncidentCommentsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IncidentComments client: %+v", err) + } + configureFunc(incidentCommentsClient.Client) - incidentRelationsClient := incidentrelations.NewIncidentRelationsClientWithBaseURI(endpoint) - configureAuthFunc(&incidentRelationsClient.Client) + incidentEntitiesClient, err := incidententities.NewIncidentEntitiesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IncidentEntities client: %+v", err) + } + configureFunc(incidentEntitiesClient.Client) - incidentsClient := incidents.NewIncidentsClientWithBaseURI(endpoint) - configureAuthFunc(&incidentsClient.Client) + incidentRelationsClient, err := incidentrelations.NewIncidentRelationsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IncidentRelations client: %+v", err) + } + configureFunc(incidentRelationsClient.Client) - metadataClient := metadata.NewMetadataClientWithBaseURI(endpoint) - configureAuthFunc(&metadataClient.Client) + incidentsClient, err := incidents.NewIncidentsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Incidents client: %+v", err) + } + configureFunc(incidentsClient.Client) - securityMLAnalyticsSettingsClient := securitymlanalyticssettings.NewSecurityMLAnalyticsSettingsClientWithBaseURI(endpoint) - configureAuthFunc(&securityMLAnalyticsSettingsClient.Client) + metadataClient, err := metadata.NewMetadataClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Metadata client: %+v", err) + } + configureFunc(metadataClient.Client) - sentinelOnboardingStatesClient := sentinelonboardingstates.NewSentinelOnboardingStatesClientWithBaseURI(endpoint) - configureAuthFunc(&sentinelOnboardingStatesClient.Client) + securityMLAnalyticsSettingsClient, err := securitymlanalyticssettings.NewSecurityMLAnalyticsSettingsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SecurityMLAnalyticsSettings client: %+v", err) + } + configureFunc(securityMLAnalyticsSettingsClient.Client) - threatIntelligenceClient := threatintelligence.NewThreatIntelligenceClientWithBaseURI(endpoint) - configureAuthFunc(&threatIntelligenceClient.Client) + sentinelOnboardingStatesClient, err := sentinelonboardingstates.NewSentinelOnboardingStatesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SentinelOnboardingStates client: %+v", err) + } + configureFunc(sentinelOnboardingStatesClient.Client) - watchlistItemsClient := watchlistitems.NewWatchlistItemsClientWithBaseURI(endpoint) - configureAuthFunc(&watchlistItemsClient.Client) + threatIntelligenceClient, err := threatintelligence.NewThreatIntelligenceClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ThreatIntelligence client: %+v", err) + } + configureFunc(threatIntelligenceClient.Client) - watchlistsClient := watchlists.NewWatchlistsClientWithBaseURI(endpoint) - configureAuthFunc(&watchlistsClient.Client) + watchlistItemsClient, err := watchlistitems.NewWatchlistItemsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building WatchlistItems client: %+v", err) + } + configureFunc(watchlistItemsClient.Client) - return Client{ - Actions: &actionsClient, - AlertRuleTemplates: &alertRuleTemplatesClient, - AlertRules: &alertRulesClient, - AutomationRules: &automationRulesClient, - Bookmarks: &bookmarksClient, - DataConnectors: &dataConnectorsClient, - EntityTypes: &entityTypesClient, - IncidentAlerts: &incidentAlertsClient, - IncidentBookmarks: &incidentBookmarksClient, - IncidentComments: &incidentCommentsClient, - IncidentEntities: &incidentEntitiesClient, - IncidentRelations: &incidentRelationsClient, - Incidents: &incidentsClient, - Metadata: &metadataClient, - SecurityMLAnalyticsSettings: &securityMLAnalyticsSettingsClient, - SentinelOnboardingStates: &sentinelOnboardingStatesClient, - ThreatIntelligence: &threatIntelligenceClient, - WatchlistItems: &watchlistItemsClient, - Watchlists: &watchlistsClient, + watchlistsClient, err := watchlists.NewWatchlistsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Watchlists client: %+v", err) } + configureFunc(watchlistsClient.Client) + + return &Client{ + Actions: actionsClient, + AlertRuleTemplates: alertRuleTemplatesClient, + AlertRules: alertRulesClient, + AutomationRules: automationRulesClient, + Bookmarks: bookmarksClient, + DataConnectors: dataConnectorsClient, + EntityTypes: entityTypesClient, + IncidentAlerts: incidentAlertsClient, + IncidentBookmarks: incidentBookmarksClient, + IncidentComments: incidentCommentsClient, + IncidentEntities: incidentEntitiesClient, + IncidentRelations: incidentRelationsClient, + Incidents: incidentsClient, + Metadata: metadataClient, + SecurityMLAnalyticsSettings: securityMLAnalyticsSettingsClient, + SentinelOnboardingStates: sentinelOnboardingStatesClient, + ThreatIntelligence: threatIntelligenceClient, + WatchlistItems: watchlistItemsClient, + Watchlists: watchlistsClient, + }, nil } diff --git a/resource-manager/securityinsights/2023-02-01/dataconnectors/client.go b/resource-manager/securityinsights/2023-02-01/dataconnectors/client.go index cf334b72568..8ed0120c79a 100644 --- a/resource-manager/securityinsights/2023-02-01/dataconnectors/client.go +++ b/resource-manager/securityinsights/2023-02-01/dataconnectors/client.go @@ -1,18 +1,26 @@ package dataconnectors -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type DataConnectorsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewDataConnectorsClientWithBaseURI(endpoint string) DataConnectorsClient { - return DataConnectorsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewDataConnectorsClientWithBaseURI(sdkApi sdkEnv.Api) (*DataConnectorsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "dataconnectors", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DataConnectorsClient: %+v", err) } + + return &DataConnectorsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2023-02-01/dataconnectors/constants.go b/resource-manager/securityinsights/2023-02-01/dataconnectors/constants.go index db98dc83577..3fb78689b33 100644 --- a/resource-manager/securityinsights/2023-02-01/dataconnectors/constants.go +++ b/resource-manager/securityinsights/2023-02-01/dataconnectors/constants.go @@ -1,6 +1,10 @@ package dataconnectors -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -31,6 +35,19 @@ func PossibleValuesForDataConnectorKind() []string { } } +func (s *DataConnectorKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataConnectorKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDataConnectorKind(input string) (*DataConnectorKind, error) { vals := map[string]DataConnectorKind{ "amazonwebservicescloudtrail": DataConnectorKindAmazonWebServicesCloudTrail, @@ -65,6 +82,19 @@ func PossibleValuesForDataTypeState() []string { } } +func (s *DataTypeState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataTypeState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDataTypeState(input string) (*DataTypeState, error) { vals := map[string]DataTypeState{ "disabled": DataTypeStateDisabled, diff --git a/resource-manager/securityinsights/2023-02-01/dataconnectors/method_createorupdate.go b/resource-manager/securityinsights/2023-02-01/dataconnectors/method_createorupdate.go new file mode 100644 index 00000000000..c5f6e5d1503 --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/dataconnectors/method_createorupdate.go @@ -0,0 +1,63 @@ +package dataconnectors + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DataConnector +} + +// CreateOrUpdate ... +func (c DataConnectorsClient) CreateOrUpdate(ctx context.Context, id DataConnectorId, input DataConnector) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalDataConnectorImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/dataconnectors/method_createorupdate_autorest.go b/resource-manager/securityinsights/2023-02-01/dataconnectors/method_createorupdate_autorest.go deleted file mode 100644 index 1f259eca36c..00000000000 --- a/resource-manager/securityinsights/2023-02-01/dataconnectors/method_createorupdate_autorest.go +++ /dev/null @@ -1,78 +0,0 @@ -package dataconnectors - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *DataConnector -} - -// CreateOrUpdate ... -func (c DataConnectorsClient) CreateOrUpdate(ctx context.Context, id DataConnectorId, input DataConnector) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c DataConnectorsClient) preparerForCreateOrUpdate(ctx context.Context, id DataConnectorId, input DataConnector) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c DataConnectorsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalDataConnectorImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2023-02-01/dataconnectors/method_delete.go b/resource-manager/securityinsights/2023-02-01/dataconnectors/method_delete.go new file mode 100644 index 00000000000..8461ec6d8a1 --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/dataconnectors/method_delete.go @@ -0,0 +1,47 @@ +package dataconnectors + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c DataConnectorsClient) Delete(ctx context.Context, id DataConnectorId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/dataconnectors/method_delete_autorest.go b/resource-manager/securityinsights/2023-02-01/dataconnectors/method_delete_autorest.go deleted file mode 100644 index ac4ddf57441..00000000000 --- a/resource-manager/securityinsights/2023-02-01/dataconnectors/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package dataconnectors - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c DataConnectorsClient) Delete(ctx context.Context, id DataConnectorId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c DataConnectorsClient) preparerForDelete(ctx context.Context, id DataConnectorId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c DataConnectorsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-02-01/dataconnectors/method_get.go b/resource-manager/securityinsights/2023-02-01/dataconnectors/method_get.go new file mode 100644 index 00000000000..3511ba85477 --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/dataconnectors/method_get.go @@ -0,0 +1,58 @@ +package dataconnectors + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DataConnector +} + +// Get ... +func (c DataConnectorsClient) Get(ctx context.Context, id DataConnectorId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalDataConnectorImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/dataconnectors/method_get_autorest.go b/resource-manager/securityinsights/2023-02-01/dataconnectors/method_get_autorest.go deleted file mode 100644 index af56be19c9c..00000000000 --- a/resource-manager/securityinsights/2023-02-01/dataconnectors/method_get_autorest.go +++ /dev/null @@ -1,77 +0,0 @@ -package dataconnectors - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *DataConnector -} - -// Get ... -func (c DataConnectorsClient) Get(ctx context.Context, id DataConnectorId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c DataConnectorsClient) preparerForGet(ctx context.Context, id DataConnectorId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c DataConnectorsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalDataConnectorImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2023-02-01/dataconnectors/method_list.go b/resource-manager/securityinsights/2023-02-01/dataconnectors/method_list.go new file mode 100644 index 00000000000..6975384fdee --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/dataconnectors/method_list.go @@ -0,0 +1,103 @@ +package dataconnectors + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DataConnector +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []DataConnector +} + +// List ... +func (c DataConnectorsClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/dataConnectors", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]DataConnector, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalDataConnectorImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for DataConnector (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// ListComplete retrieves all the results into a single object +func (c DataConnectorsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, DataConnectorOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DataConnectorsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate DataConnectorOperationPredicate) (result ListCompleteResult, err error) { + items := make([]DataConnector, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2023-02-01/dataconnectors/method_list_autorest.go b/resource-manager/securityinsights/2023-02-01/dataconnectors/method_list_autorest.go deleted file mode 100644 index e08d153a6eb..00000000000 --- a/resource-manager/securityinsights/2023-02-01/dataconnectors/method_list_autorest.go +++ /dev/null @@ -1,196 +0,0 @@ -package dataconnectors - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]DataConnector - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []DataConnector -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c DataConnectorsClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c DataConnectorsClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/dataConnectors", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c DataConnectorsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c DataConnectorsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]DataConnector, 0) - for i, v := range respObj.Values { - val, err := unmarshalDataConnectorImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for DataConnector (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c DataConnectorsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, DataConnectorOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c DataConnectorsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate DataConnectorOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]DataConnector, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2023-02-01/entitytypes/client.go b/resource-manager/securityinsights/2023-02-01/entitytypes/client.go index 60583ea834f..bcdd09e4029 100644 --- a/resource-manager/securityinsights/2023-02-01/entitytypes/client.go +++ b/resource-manager/securityinsights/2023-02-01/entitytypes/client.go @@ -1,18 +1,26 @@ package entitytypes -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type EntityTypesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewEntityTypesClientWithBaseURI(endpoint string) EntityTypesClient { - return EntityTypesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewEntityTypesClientWithBaseURI(sdkApi sdkEnv.Api) (*EntityTypesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "entitytypes", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating EntityTypesClient: %+v", err) } + + return &EntityTypesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2023-02-01/entitytypes/constants.go b/resource-manager/securityinsights/2023-02-01/entitytypes/constants.go index fbe60ce0f02..2f194a6f29d 100644 --- a/resource-manager/securityinsights/2023-02-01/entitytypes/constants.go +++ b/resource-manager/securityinsights/2023-02-01/entitytypes/constants.go @@ -1,6 +1,10 @@ package entitytypes -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -23,6 +27,19 @@ func PossibleValuesForAlertSeverity() []string { } } +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertSeverity(input string) (*AlertSeverity, error) { vals := map[string]AlertSeverity{ "high": AlertSeverityHigh, @@ -59,6 +76,19 @@ func PossibleValuesForAlertStatus() []string { } } +func (s *AlertStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertStatus(input string) (*AlertStatus, error) { vals := map[string]AlertStatus{ "dismissed": AlertStatusDismissed, @@ -94,6 +124,19 @@ func PossibleValuesForAntispamMailDirection() []string { } } +func (s *AntispamMailDirection) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAntispamMailDirection(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAntispamMailDirection(input string) (*AntispamMailDirection, error) { vals := map[string]AntispamMailDirection{ "inbound": AntispamMailDirectionInbound, @@ -154,6 +197,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -199,6 +255,19 @@ func PossibleValuesForConfidenceLevel() []string { } } +func (s *ConfidenceLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceLevel(input string) (*ConfidenceLevel, error) { vals := map[string]ConfidenceLevel{ "high": ConfidenceLevelHigh, @@ -232,6 +301,19 @@ func PossibleValuesForConfidenceScoreStatus() []string { } } +func (s *ConfidenceScoreStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceScoreStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceScoreStatus(input string) (*ConfidenceScoreStatus, error) { vals := map[string]ConfidenceScoreStatus{ "final": ConfidenceScoreStatusFinal, @@ -266,6 +348,19 @@ func PossibleValuesForCreatedByType() []string { } } +func (s *CreatedByType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCreatedByType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseCreatedByType(input string) (*CreatedByType, error) { vals := map[string]CreatedByType{ "application": CreatedByTypeApplication, @@ -302,6 +397,19 @@ func PossibleValuesForDeliveryAction() []string { } } +func (s *DeliveryAction) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeliveryAction(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDeliveryAction(input string) (*DeliveryAction, error) { vals := map[string]DeliveryAction{ "blocked": DeliveryActionBlocked, @@ -347,6 +455,19 @@ func PossibleValuesForDeliveryLocation() []string { } } +func (s *DeliveryLocation) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeliveryLocation(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDeliveryLocation(input string) (*DeliveryLocation, error) { vals := map[string]DeliveryLocation{ "deletedfolder": DeliveryLocationDeletedFolder, @@ -384,6 +505,19 @@ func PossibleValuesForElevationToken() []string { } } +func (s *ElevationToken) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseElevationToken(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseElevationToken(input string) (*ElevationToken, error) { vals := map[string]ElevationToken{ "default": ElevationTokenDefault, @@ -451,6 +585,19 @@ func PossibleValuesForEntityKindEnum() []string { } } +func (s *EntityKindEnum) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityKindEnum(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityKindEnum(input string) (*EntityKindEnum, error) { vals := map[string]EntityKindEnum{ "account": EntityKindEnumAccount, @@ -504,6 +651,19 @@ func PossibleValuesForFileHashAlgorithm() []string { } } +func (s *FileHashAlgorithm) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseFileHashAlgorithm(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseFileHashAlgorithm(input string) (*FileHashAlgorithm, error) { vals := map[string]FileHashAlgorithm{ "md5": FileHashAlgorithmMDFive, @@ -539,6 +699,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, @@ -593,6 +766,19 @@ func PossibleValuesForKillChainIntent() []string { } } +func (s *KillChainIntent) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKillChainIntent(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseKillChainIntent(input string) (*KillChainIntent, error) { vals := map[string]KillChainIntent{ "collection": KillChainIntentCollection, @@ -639,6 +825,19 @@ func PossibleValuesForOSFamily() []string { } } +func (s *OSFamily) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOSFamily(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseOSFamily(input string) (*OSFamily, error) { vals := map[string]OSFamily{ "android": OSFamilyAndroid, @@ -686,6 +885,19 @@ func PossibleValuesForRegistryHive() []string { } } +func (s *RegistryHive) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRegistryHive(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseRegistryHive(input string) (*RegistryHive, error) { vals := map[string]RegistryHive{ "hkey_a": RegistryHiveHKEYA, @@ -734,6 +946,19 @@ func PossibleValuesForRegistryValueKind() []string { } } +func (s *RegistryValueKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRegistryValueKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseRegistryValueKind(input string) (*RegistryValueKind, error) { vals := map[string]RegistryValueKind{ "binary": RegistryValueKindBinary, diff --git a/resource-manager/securityinsights/2023-02-01/incidentalerts/client.go b/resource-manager/securityinsights/2023-02-01/incidentalerts/client.go index ae19637d473..53dc2b4cd4e 100644 --- a/resource-manager/securityinsights/2023-02-01/incidentalerts/client.go +++ b/resource-manager/securityinsights/2023-02-01/incidentalerts/client.go @@ -1,18 +1,26 @@ package incidentalerts -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type IncidentAlertsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewIncidentAlertsClientWithBaseURI(endpoint string) IncidentAlertsClient { - return IncidentAlertsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewIncidentAlertsClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentAlertsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidentalerts", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentAlertsClient: %+v", err) } + + return &IncidentAlertsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2023-02-01/incidentalerts/constants.go b/resource-manager/securityinsights/2023-02-01/incidentalerts/constants.go index 8f605bb09d5..3673d5b1163 100644 --- a/resource-manager/securityinsights/2023-02-01/incidentalerts/constants.go +++ b/resource-manager/securityinsights/2023-02-01/incidentalerts/constants.go @@ -1,6 +1,10 @@ package incidentalerts -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -23,6 +27,19 @@ func PossibleValuesForAlertSeverity() []string { } } +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertSeverity(input string) (*AlertSeverity, error) { vals := map[string]AlertSeverity{ "high": AlertSeverityHigh, @@ -59,6 +76,19 @@ func PossibleValuesForAlertStatus() []string { } } +func (s *AlertStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertStatus(input string) (*AlertStatus, error) { vals := map[string]AlertStatus{ "dismissed": AlertStatusDismissed, @@ -120,6 +150,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -165,6 +208,19 @@ func PossibleValuesForConfidenceLevel() []string { } } +func (s *ConfidenceLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceLevel(input string) (*ConfidenceLevel, error) { vals := map[string]ConfidenceLevel{ "high": ConfidenceLevelHigh, @@ -198,6 +254,19 @@ func PossibleValuesForConfidenceScoreStatus() []string { } } +func (s *ConfidenceScoreStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceScoreStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceScoreStatus(input string) (*ConfidenceScoreStatus, error) { vals := map[string]ConfidenceScoreStatus{ "final": ConfidenceScoreStatusFinal, @@ -266,6 +335,19 @@ func PossibleValuesForEntityKindEnum() []string { } } +func (s *EntityKindEnum) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityKindEnum(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityKindEnum(input string) (*EntityKindEnum, error) { vals := map[string]EntityKindEnum{ "account": EntityKindEnumAccount, @@ -317,6 +399,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, @@ -371,6 +466,19 @@ func PossibleValuesForKillChainIntent() []string { } } +func (s *KillChainIntent) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKillChainIntent(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseKillChainIntent(input string) (*KillChainIntent, error) { vals := map[string]KillChainIntent{ "collection": KillChainIntentCollection, diff --git a/resource-manager/securityinsights/2023-02-01/incidentalerts/method_incidentslistalerts.go b/resource-manager/securityinsights/2023-02-01/incidentalerts/method_incidentslistalerts.go new file mode 100644 index 00000000000..fe83693eae2 --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/incidentalerts/method_incidentslistalerts.go @@ -0,0 +1,52 @@ +package incidentalerts + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentsListAlertsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IncidentAlertList +} + +// IncidentsListAlerts ... +func (c IncidentAlertsClient) IncidentsListAlerts(ctx context.Context, id IncidentId) (result IncidentsListAlertsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/alerts", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/incidentalerts/method_incidentslistalerts_autorest.go b/resource-manager/securityinsights/2023-02-01/incidentalerts/method_incidentslistalerts_autorest.go deleted file mode 100644 index de6c08e09a2..00000000000 --- a/resource-manager/securityinsights/2023-02-01/incidentalerts/method_incidentslistalerts_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package incidentalerts - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IncidentsListAlertsOperationResponse struct { - HttpResponse *http.Response - Model *IncidentAlertList -} - -// IncidentsListAlerts ... -func (c IncidentAlertsClient) IncidentsListAlerts(ctx context.Context, id IncidentId) (result IncidentsListAlertsOperationResponse, err error) { - req, err := c.preparerForIncidentsListAlerts(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentalerts.IncidentAlertsClient", "IncidentsListAlerts", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentalerts.IncidentAlertsClient", "IncidentsListAlerts", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIncidentsListAlerts(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentalerts.IncidentAlertsClient", "IncidentsListAlerts", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIncidentsListAlerts prepares the IncidentsListAlerts request. -func (c IncidentAlertsClient) preparerForIncidentsListAlerts(ctx context.Context, id IncidentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/alerts", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIncidentsListAlerts handles the response to the IncidentsListAlerts request. The method always -// closes the http.Response Body. -func (c IncidentAlertsClient) responderForIncidentsListAlerts(resp *http.Response) (result IncidentsListAlertsOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-02-01/incidentbookmarks/client.go b/resource-manager/securityinsights/2023-02-01/incidentbookmarks/client.go index e2fcca6728b..e6a60ede52d 100644 --- a/resource-manager/securityinsights/2023-02-01/incidentbookmarks/client.go +++ b/resource-manager/securityinsights/2023-02-01/incidentbookmarks/client.go @@ -1,18 +1,26 @@ package incidentbookmarks -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type IncidentBookmarksClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewIncidentBookmarksClientWithBaseURI(endpoint string) IncidentBookmarksClient { - return IncidentBookmarksClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewIncidentBookmarksClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentBookmarksClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidentbookmarks", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentBookmarksClient: %+v", err) } + + return &IncidentBookmarksClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2023-02-01/incidentbookmarks/constants.go b/resource-manager/securityinsights/2023-02-01/incidentbookmarks/constants.go index 7080e0657bc..27f31cfcc5e 100644 --- a/resource-manager/securityinsights/2023-02-01/incidentbookmarks/constants.go +++ b/resource-manager/securityinsights/2023-02-01/incidentbookmarks/constants.go @@ -1,6 +1,10 @@ package incidentbookmarks -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -23,6 +27,19 @@ func PossibleValuesForAlertSeverity() []string { } } +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertSeverity(input string) (*AlertSeverity, error) { vals := map[string]AlertSeverity{ "high": AlertSeverityHigh, @@ -59,6 +76,19 @@ func PossibleValuesForAlertStatus() []string { } } +func (s *AlertStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertStatus(input string) (*AlertStatus, error) { vals := map[string]AlertStatus{ "dismissed": AlertStatusDismissed, @@ -120,6 +150,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -165,6 +208,19 @@ func PossibleValuesForConfidenceLevel() []string { } } +func (s *ConfidenceLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceLevel(input string) (*ConfidenceLevel, error) { vals := map[string]ConfidenceLevel{ "high": ConfidenceLevelHigh, @@ -198,6 +254,19 @@ func PossibleValuesForConfidenceScoreStatus() []string { } } +func (s *ConfidenceScoreStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceScoreStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceScoreStatus(input string) (*ConfidenceScoreStatus, error) { vals := map[string]ConfidenceScoreStatus{ "final": ConfidenceScoreStatusFinal, @@ -266,6 +335,19 @@ func PossibleValuesForEntityKindEnum() []string { } } +func (s *EntityKindEnum) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityKindEnum(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityKindEnum(input string) (*EntityKindEnum, error) { vals := map[string]EntityKindEnum{ "account": EntityKindEnumAccount, @@ -317,6 +399,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, @@ -371,6 +466,19 @@ func PossibleValuesForKillChainIntent() []string { } } +func (s *KillChainIntent) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKillChainIntent(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseKillChainIntent(input string) (*KillChainIntent, error) { vals := map[string]KillChainIntent{ "collection": KillChainIntentCollection, diff --git a/resource-manager/securityinsights/2023-02-01/incidentbookmarks/method_incidentslistbookmarks.go b/resource-manager/securityinsights/2023-02-01/incidentbookmarks/method_incidentslistbookmarks.go new file mode 100644 index 00000000000..3ac7b9e8b2e --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/incidentbookmarks/method_incidentslistbookmarks.go @@ -0,0 +1,52 @@ +package incidentbookmarks + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentsListBookmarksOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IncidentBookmarkList +} + +// IncidentsListBookmarks ... +func (c IncidentBookmarksClient) IncidentsListBookmarks(ctx context.Context, id IncidentId) (result IncidentsListBookmarksOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/bookmarks", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/incidentbookmarks/method_incidentslistbookmarks_autorest.go b/resource-manager/securityinsights/2023-02-01/incidentbookmarks/method_incidentslistbookmarks_autorest.go deleted file mode 100644 index a5c3a89a09c..00000000000 --- a/resource-manager/securityinsights/2023-02-01/incidentbookmarks/method_incidentslistbookmarks_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package incidentbookmarks - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IncidentsListBookmarksOperationResponse struct { - HttpResponse *http.Response - Model *IncidentBookmarkList -} - -// IncidentsListBookmarks ... -func (c IncidentBookmarksClient) IncidentsListBookmarks(ctx context.Context, id IncidentId) (result IncidentsListBookmarksOperationResponse, err error) { - req, err := c.preparerForIncidentsListBookmarks(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentbookmarks.IncidentBookmarksClient", "IncidentsListBookmarks", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentbookmarks.IncidentBookmarksClient", "IncidentsListBookmarks", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIncidentsListBookmarks(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentbookmarks.IncidentBookmarksClient", "IncidentsListBookmarks", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIncidentsListBookmarks prepares the IncidentsListBookmarks request. -func (c IncidentBookmarksClient) preparerForIncidentsListBookmarks(ctx context.Context, id IncidentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/bookmarks", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIncidentsListBookmarks handles the response to the IncidentsListBookmarks request. The method always -// closes the http.Response Body. -func (c IncidentBookmarksClient) responderForIncidentsListBookmarks(resp *http.Response) (result IncidentsListBookmarksOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-02-01/incidentcomments/client.go b/resource-manager/securityinsights/2023-02-01/incidentcomments/client.go index 4006779247d..981e6f75216 100644 --- a/resource-manager/securityinsights/2023-02-01/incidentcomments/client.go +++ b/resource-manager/securityinsights/2023-02-01/incidentcomments/client.go @@ -1,18 +1,26 @@ package incidentcomments -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type IncidentCommentsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewIncidentCommentsClientWithBaseURI(endpoint string) IncidentCommentsClient { - return IncidentCommentsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewIncidentCommentsClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentCommentsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidentcomments", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentCommentsClient: %+v", err) } + + return &IncidentCommentsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2023-02-01/incidentcomments/method_createorupdate.go b/resource-manager/securityinsights/2023-02-01/incidentcomments/method_createorupdate.go new file mode 100644 index 00000000000..5c59b2be8d3 --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/incidentcomments/method_createorupdate.go @@ -0,0 +1,56 @@ +package incidentcomments + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IncidentComment +} + +// CreateOrUpdate ... +func (c IncidentCommentsClient) CreateOrUpdate(ctx context.Context, id CommentId, input IncidentComment) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/incidentcomments/method_createorupdate_autorest.go b/resource-manager/securityinsights/2023-02-01/incidentcomments/method_createorupdate_autorest.go deleted file mode 100644 index b27777aad2c..00000000000 --- a/resource-manager/securityinsights/2023-02-01/incidentcomments/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package incidentcomments - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *IncidentComment -} - -// CreateOrUpdate ... -func (c IncidentCommentsClient) CreateOrUpdate(ctx context.Context, id CommentId, input IncidentComment) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c IncidentCommentsClient) preparerForCreateOrUpdate(ctx context.Context, id CommentId, input IncidentComment) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c IncidentCommentsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-02-01/incidentcomments/method_delete.go b/resource-manager/securityinsights/2023-02-01/incidentcomments/method_delete.go new file mode 100644 index 00000000000..78412a13e76 --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/incidentcomments/method_delete.go @@ -0,0 +1,47 @@ +package incidentcomments + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c IncidentCommentsClient) Delete(ctx context.Context, id CommentId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/incidentcomments/method_delete_autorest.go b/resource-manager/securityinsights/2023-02-01/incidentcomments/method_delete_autorest.go deleted file mode 100644 index 6bbb4c92cbf..00000000000 --- a/resource-manager/securityinsights/2023-02-01/incidentcomments/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package incidentcomments - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c IncidentCommentsClient) Delete(ctx context.Context, id CommentId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c IncidentCommentsClient) preparerForDelete(ctx context.Context, id CommentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c IncidentCommentsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-02-01/incidentcomments/method_get.go b/resource-manager/securityinsights/2023-02-01/incidentcomments/method_get.go new file mode 100644 index 00000000000..e8d11306ddb --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/incidentcomments/method_get.go @@ -0,0 +1,51 @@ +package incidentcomments + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IncidentComment +} + +// Get ... +func (c IncidentCommentsClient) Get(ctx context.Context, id CommentId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/incidentcomments/method_get_autorest.go b/resource-manager/securityinsights/2023-02-01/incidentcomments/method_get_autorest.go deleted file mode 100644 index 8402ed77e94..00000000000 --- a/resource-manager/securityinsights/2023-02-01/incidentcomments/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package incidentcomments - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *IncidentComment -} - -// Get ... -func (c IncidentCommentsClient) Get(ctx context.Context, id CommentId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c IncidentCommentsClient) preparerForGet(ctx context.Context, id CommentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c IncidentCommentsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-02-01/incidentcomments/method_list.go b/resource-manager/securityinsights/2023-02-01/incidentcomments/method_list.go new file mode 100644 index 00000000000..b4c16058b38 --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/incidentcomments/method_list.go @@ -0,0 +1,127 @@ +package incidentcomments + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]IncidentComment +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []IncidentComment +} + +type ListOperationOptions struct { + Filter *string + Orderby *string + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c IncidentCommentsClient) List(ctx context.Context, id IncidentId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/comments", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]IncidentComment `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c IncidentCommentsClient) ListComplete(ctx context.Context, id IncidentId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, IncidentCommentOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c IncidentCommentsClient) ListCompleteMatchingPredicate(ctx context.Context, id IncidentId, options ListOperationOptions, predicate IncidentCommentOperationPredicate) (result ListCompleteResult, err error) { + items := make([]IncidentComment, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2023-02-01/incidentcomments/method_list_autorest.go b/resource-manager/securityinsights/2023-02-01/incidentcomments/method_list_autorest.go deleted file mode 100644 index 24fb8d1d7e7..00000000000 --- a/resource-manager/securityinsights/2023-02-01/incidentcomments/method_list_autorest.go +++ /dev/null @@ -1,225 +0,0 @@ -package incidentcomments - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]IncidentComment - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []IncidentComment -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ListOperationOptions struct { - Filter *string - Orderby *string - Top *int64 -} - -func DefaultListOperationOptions() ListOperationOptions { - return ListOperationOptions{} -} - -func (o ListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Filter != nil { - out["$filter"] = *o.Filter - } - - if o.Orderby != nil { - out["$orderby"] = *o.Orderby - } - - if o.Top != nil { - out["$top"] = *o.Top - } - - return out -} - -// List ... -func (c IncidentCommentsClient) List(ctx context.Context, id IncidentId, options ListOperationOptions) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c IncidentCommentsClient) preparerForList(ctx context.Context, id IncidentId, options ListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/comments", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c IncidentCommentsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c IncidentCommentsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []IncidentComment `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c IncidentCommentsClient) ListComplete(ctx context.Context, id IncidentId, options ListOperationOptions) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, options, IncidentCommentOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c IncidentCommentsClient) ListCompleteMatchingPredicate(ctx context.Context, id IncidentId, options ListOperationOptions, predicate IncidentCommentOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]IncidentComment, 0) - - page, err := c.List(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2023-02-01/incidententities/client.go b/resource-manager/securityinsights/2023-02-01/incidententities/client.go index 5f0eaf07782..740e7b81755 100644 --- a/resource-manager/securityinsights/2023-02-01/incidententities/client.go +++ b/resource-manager/securityinsights/2023-02-01/incidententities/client.go @@ -1,18 +1,26 @@ package incidententities -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type IncidentEntitiesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewIncidentEntitiesClientWithBaseURI(endpoint string) IncidentEntitiesClient { - return IncidentEntitiesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewIncidentEntitiesClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentEntitiesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidententities", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentEntitiesClient: %+v", err) } + + return &IncidentEntitiesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2023-02-01/incidententities/constants.go b/resource-manager/securityinsights/2023-02-01/incidententities/constants.go index cb1b487a229..a1d54eb28d0 100644 --- a/resource-manager/securityinsights/2023-02-01/incidententities/constants.go +++ b/resource-manager/securityinsights/2023-02-01/incidententities/constants.go @@ -1,6 +1,10 @@ package incidententities -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -23,6 +27,19 @@ func PossibleValuesForAlertSeverity() []string { } } +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertSeverity(input string) (*AlertSeverity, error) { vals := map[string]AlertSeverity{ "high": AlertSeverityHigh, @@ -59,6 +76,19 @@ func PossibleValuesForAlertStatus() []string { } } +func (s *AlertStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertStatus(input string) (*AlertStatus, error) { vals := map[string]AlertStatus{ "dismissed": AlertStatusDismissed, @@ -120,6 +150,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -165,6 +208,19 @@ func PossibleValuesForConfidenceLevel() []string { } } +func (s *ConfidenceLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceLevel(input string) (*ConfidenceLevel, error) { vals := map[string]ConfidenceLevel{ "high": ConfidenceLevelHigh, @@ -198,6 +254,19 @@ func PossibleValuesForConfidenceScoreStatus() []string { } } +func (s *ConfidenceScoreStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceScoreStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceScoreStatus(input string) (*ConfidenceScoreStatus, error) { vals := map[string]ConfidenceScoreStatus{ "final": ConfidenceScoreStatusFinal, @@ -266,6 +335,19 @@ func PossibleValuesForEntityKindEnum() []string { } } +func (s *EntityKindEnum) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityKindEnum(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityKindEnum(input string) (*EntityKindEnum, error) { vals := map[string]EntityKindEnum{ "account": EntityKindEnumAccount, @@ -317,6 +399,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, @@ -371,6 +466,19 @@ func PossibleValuesForKillChainIntent() []string { } } +func (s *KillChainIntent) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKillChainIntent(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseKillChainIntent(input string) (*KillChainIntent, error) { vals := map[string]KillChainIntent{ "collection": KillChainIntentCollection, diff --git a/resource-manager/securityinsights/2023-02-01/incidententities/method_incidentslistentities.go b/resource-manager/securityinsights/2023-02-01/incidententities/method_incidentslistentities.go new file mode 100644 index 00000000000..36ec8f0c75b --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/incidententities/method_incidentslistentities.go @@ -0,0 +1,52 @@ +package incidententities + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentsListEntitiesOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IncidentEntitiesResponse +} + +// IncidentsListEntities ... +func (c IncidentEntitiesClient) IncidentsListEntities(ctx context.Context, id IncidentId) (result IncidentsListEntitiesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/entities", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/incidententities/method_incidentslistentities_autorest.go b/resource-manager/securityinsights/2023-02-01/incidententities/method_incidentslistentities_autorest.go deleted file mode 100644 index 9d796d431cb..00000000000 --- a/resource-manager/securityinsights/2023-02-01/incidententities/method_incidentslistentities_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package incidententities - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IncidentsListEntitiesOperationResponse struct { - HttpResponse *http.Response - Model *IncidentEntitiesResponse -} - -// IncidentsListEntities ... -func (c IncidentEntitiesClient) IncidentsListEntities(ctx context.Context, id IncidentId) (result IncidentsListEntitiesOperationResponse, err error) { - req, err := c.preparerForIncidentsListEntities(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidententities.IncidentEntitiesClient", "IncidentsListEntities", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidententities.IncidentEntitiesClient", "IncidentsListEntities", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIncidentsListEntities(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidententities.IncidentEntitiesClient", "IncidentsListEntities", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIncidentsListEntities prepares the IncidentsListEntities request. -func (c IncidentEntitiesClient) preparerForIncidentsListEntities(ctx context.Context, id IncidentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/entities", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIncidentsListEntities handles the response to the IncidentsListEntities request. The method always -// closes the http.Response Body. -func (c IncidentEntitiesClient) responderForIncidentsListEntities(resp *http.Response) (result IncidentsListEntitiesOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-02-01/incidentrelations/client.go b/resource-manager/securityinsights/2023-02-01/incidentrelations/client.go index 58aa27c43e8..4e8fbfeb71d 100644 --- a/resource-manager/securityinsights/2023-02-01/incidentrelations/client.go +++ b/resource-manager/securityinsights/2023-02-01/incidentrelations/client.go @@ -1,18 +1,26 @@ package incidentrelations -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type IncidentRelationsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewIncidentRelationsClientWithBaseURI(endpoint string) IncidentRelationsClient { - return IncidentRelationsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewIncidentRelationsClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentRelationsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidentrelations", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentRelationsClient: %+v", err) } + + return &IncidentRelationsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2023-02-01/incidentrelations/method_createorupdate.go b/resource-manager/securityinsights/2023-02-01/incidentrelations/method_createorupdate.go new file mode 100644 index 00000000000..4b4ff3d56f8 --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/incidentrelations/method_createorupdate.go @@ -0,0 +1,56 @@ +package incidentrelations + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Relation +} + +// CreateOrUpdate ... +func (c IncidentRelationsClient) CreateOrUpdate(ctx context.Context, id RelationId, input Relation) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/incidentrelations/method_createorupdate_autorest.go b/resource-manager/securityinsights/2023-02-01/incidentrelations/method_createorupdate_autorest.go deleted file mode 100644 index 79cf52b5347..00000000000 --- a/resource-manager/securityinsights/2023-02-01/incidentrelations/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package incidentrelations - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *Relation -} - -// CreateOrUpdate ... -func (c IncidentRelationsClient) CreateOrUpdate(ctx context.Context, id RelationId, input Relation) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c IncidentRelationsClient) preparerForCreateOrUpdate(ctx context.Context, id RelationId, input Relation) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c IncidentRelationsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-02-01/incidentrelations/method_delete.go b/resource-manager/securityinsights/2023-02-01/incidentrelations/method_delete.go new file mode 100644 index 00000000000..de3afbf47c9 --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/incidentrelations/method_delete.go @@ -0,0 +1,47 @@ +package incidentrelations + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c IncidentRelationsClient) Delete(ctx context.Context, id RelationId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/incidentrelations/method_delete_autorest.go b/resource-manager/securityinsights/2023-02-01/incidentrelations/method_delete_autorest.go deleted file mode 100644 index 9003689e999..00000000000 --- a/resource-manager/securityinsights/2023-02-01/incidentrelations/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package incidentrelations - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c IncidentRelationsClient) Delete(ctx context.Context, id RelationId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c IncidentRelationsClient) preparerForDelete(ctx context.Context, id RelationId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c IncidentRelationsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-02-01/incidentrelations/method_get.go b/resource-manager/securityinsights/2023-02-01/incidentrelations/method_get.go new file mode 100644 index 00000000000..7cc37b68825 --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/incidentrelations/method_get.go @@ -0,0 +1,51 @@ +package incidentrelations + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Relation +} + +// Get ... +func (c IncidentRelationsClient) Get(ctx context.Context, id RelationId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/incidentrelations/method_get_autorest.go b/resource-manager/securityinsights/2023-02-01/incidentrelations/method_get_autorest.go deleted file mode 100644 index a8b88ddecb4..00000000000 --- a/resource-manager/securityinsights/2023-02-01/incidentrelations/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package incidentrelations - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *Relation -} - -// Get ... -func (c IncidentRelationsClient) Get(ctx context.Context, id RelationId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c IncidentRelationsClient) preparerForGet(ctx context.Context, id RelationId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c IncidentRelationsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-02-01/incidentrelations/method_list.go b/resource-manager/securityinsights/2023-02-01/incidentrelations/method_list.go new file mode 100644 index 00000000000..80873d441b4 --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/incidentrelations/method_list.go @@ -0,0 +1,127 @@ +package incidentrelations + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Relation +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Relation +} + +type ListOperationOptions struct { + Filter *string + Orderby *string + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c IncidentRelationsClient) List(ctx context.Context, id IncidentId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/relations", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Relation `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c IncidentRelationsClient) ListComplete(ctx context.Context, id IncidentId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, RelationOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c IncidentRelationsClient) ListCompleteMatchingPredicate(ctx context.Context, id IncidentId, options ListOperationOptions, predicate RelationOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Relation, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2023-02-01/incidentrelations/method_list_autorest.go b/resource-manager/securityinsights/2023-02-01/incidentrelations/method_list_autorest.go deleted file mode 100644 index a270a442886..00000000000 --- a/resource-manager/securityinsights/2023-02-01/incidentrelations/method_list_autorest.go +++ /dev/null @@ -1,225 +0,0 @@ -package incidentrelations - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]Relation - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []Relation -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ListOperationOptions struct { - Filter *string - Orderby *string - Top *int64 -} - -func DefaultListOperationOptions() ListOperationOptions { - return ListOperationOptions{} -} - -func (o ListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Filter != nil { - out["$filter"] = *o.Filter - } - - if o.Orderby != nil { - out["$orderby"] = *o.Orderby - } - - if o.Top != nil { - out["$top"] = *o.Top - } - - return out -} - -// List ... -func (c IncidentRelationsClient) List(ctx context.Context, id IncidentId, options ListOperationOptions) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c IncidentRelationsClient) preparerForList(ctx context.Context, id IncidentId, options ListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/relations", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c IncidentRelationsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c IncidentRelationsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []Relation `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c IncidentRelationsClient) ListComplete(ctx context.Context, id IncidentId, options ListOperationOptions) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, options, RelationOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c IncidentRelationsClient) ListCompleteMatchingPredicate(ctx context.Context, id IncidentId, options ListOperationOptions, predicate RelationOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]Relation, 0) - - page, err := c.List(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2023-02-01/incidents/client.go b/resource-manager/securityinsights/2023-02-01/incidents/client.go index 659897d18d7..aaf38071c39 100644 --- a/resource-manager/securityinsights/2023-02-01/incidents/client.go +++ b/resource-manager/securityinsights/2023-02-01/incidents/client.go @@ -1,18 +1,26 @@ package incidents -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type IncidentsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewIncidentsClientWithBaseURI(endpoint string) IncidentsClient { - return IncidentsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewIncidentsClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidents", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentsClient: %+v", err) } + + return &IncidentsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2023-02-01/incidents/constants.go b/resource-manager/securityinsights/2023-02-01/incidents/constants.go index 82782d4107f..ce046b9edba 100644 --- a/resource-manager/securityinsights/2023-02-01/incidents/constants.go +++ b/resource-manager/securityinsights/2023-02-01/incidents/constants.go @@ -1,6 +1,10 @@ package incidents -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -49,6 +53,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -96,6 +113,19 @@ func PossibleValuesForIncidentClassification() []string { } } +func (s *IncidentClassification) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentClassification(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentClassification(input string) (*IncidentClassification, error) { vals := map[string]IncidentClassification{ "benignpositive": IncidentClassificationBenignPositive, @@ -130,6 +160,19 @@ func PossibleValuesForIncidentClassificationReason() []string { } } +func (s *IncidentClassificationReason) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentClassificationReason(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentClassificationReason(input string) (*IncidentClassificationReason, error) { vals := map[string]IncidentClassificationReason{ "inaccuratedata": IncidentClassificationReasonInaccurateData, @@ -160,6 +203,19 @@ func PossibleValuesForIncidentLabelType() []string { } } +func (s *IncidentLabelType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentLabelType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentLabelType(input string) (*IncidentLabelType, error) { vals := map[string]IncidentLabelType{ "autoassigned": IncidentLabelTypeAutoAssigned, @@ -192,6 +248,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, @@ -224,6 +293,19 @@ func PossibleValuesForIncidentStatus() []string { } } +func (s *IncidentStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentStatus(input string) (*IncidentStatus, error) { vals := map[string]IncidentStatus{ "active": IncidentStatusActive, @@ -255,6 +337,19 @@ func PossibleValuesForOwnerType() []string { } } +func (s *OwnerType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOwnerType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseOwnerType(input string) (*OwnerType, error) { vals := map[string]OwnerType{ "group": OwnerTypeGroup, diff --git a/resource-manager/securityinsights/2023-02-01/incidents/method_createorupdate.go b/resource-manager/securityinsights/2023-02-01/incidents/method_createorupdate.go new file mode 100644 index 00000000000..3fcc110ed02 --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/incidents/method_createorupdate.go @@ -0,0 +1,56 @@ +package incidents + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Incident +} + +// CreateOrUpdate ... +func (c IncidentsClient) CreateOrUpdate(ctx context.Context, id IncidentId, input Incident) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/incidents/method_createorupdate_autorest.go b/resource-manager/securityinsights/2023-02-01/incidents/method_createorupdate_autorest.go deleted file mode 100644 index 837aa7c92a0..00000000000 --- a/resource-manager/securityinsights/2023-02-01/incidents/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package incidents - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *Incident -} - -// CreateOrUpdate ... -func (c IncidentsClient) CreateOrUpdate(ctx context.Context, id IncidentId, input Incident) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c IncidentsClient) preparerForCreateOrUpdate(ctx context.Context, id IncidentId, input Incident) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c IncidentsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-02-01/incidents/method_delete.go b/resource-manager/securityinsights/2023-02-01/incidents/method_delete.go new file mode 100644 index 00000000000..9b3205af5fc --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/incidents/method_delete.go @@ -0,0 +1,47 @@ +package incidents + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c IncidentsClient) Delete(ctx context.Context, id IncidentId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/incidents/method_delete_autorest.go b/resource-manager/securityinsights/2023-02-01/incidents/method_delete_autorest.go deleted file mode 100644 index 280832422f8..00000000000 --- a/resource-manager/securityinsights/2023-02-01/incidents/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package incidents - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c IncidentsClient) Delete(ctx context.Context, id IncidentId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c IncidentsClient) preparerForDelete(ctx context.Context, id IncidentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c IncidentsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-02-01/incidents/method_get.go b/resource-manager/securityinsights/2023-02-01/incidents/method_get.go new file mode 100644 index 00000000000..e6d4e9e933b --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/incidents/method_get.go @@ -0,0 +1,51 @@ +package incidents + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Incident +} + +// Get ... +func (c IncidentsClient) Get(ctx context.Context, id IncidentId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/incidents/method_get_autorest.go b/resource-manager/securityinsights/2023-02-01/incidents/method_get_autorest.go deleted file mode 100644 index d8d2b7debeb..00000000000 --- a/resource-manager/securityinsights/2023-02-01/incidents/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package incidents - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *Incident -} - -// Get ... -func (c IncidentsClient) Get(ctx context.Context, id IncidentId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c IncidentsClient) preparerForGet(ctx context.Context, id IncidentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c IncidentsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-02-01/incidents/method_list.go b/resource-manager/securityinsights/2023-02-01/incidents/method_list.go new file mode 100644 index 00000000000..fe19cd4d9ff --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/incidents/method_list.go @@ -0,0 +1,127 @@ +package incidents + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Incident +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Incident +} + +type ListOperationOptions struct { + Filter *string + Orderby *string + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c IncidentsClient) List(ctx context.Context, id WorkspaceId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/incidents", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Incident `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c IncidentsClient) ListComplete(ctx context.Context, id WorkspaceId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, IncidentOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c IncidentsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ListOperationOptions, predicate IncidentOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Incident, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2023-02-01/incidents/method_list_autorest.go b/resource-manager/securityinsights/2023-02-01/incidents/method_list_autorest.go deleted file mode 100644 index 8d2f5acc547..00000000000 --- a/resource-manager/securityinsights/2023-02-01/incidents/method_list_autorest.go +++ /dev/null @@ -1,225 +0,0 @@ -package incidents - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]Incident - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []Incident -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ListOperationOptions struct { - Filter *string - Orderby *string - Top *int64 -} - -func DefaultListOperationOptions() ListOperationOptions { - return ListOperationOptions{} -} - -func (o ListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Filter != nil { - out["$filter"] = *o.Filter - } - - if o.Orderby != nil { - out["$orderby"] = *o.Orderby - } - - if o.Top != nil { - out["$top"] = *o.Top - } - - return out -} - -// List ... -func (c IncidentsClient) List(ctx context.Context, id WorkspaceId, options ListOperationOptions) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c IncidentsClient) preparerForList(ctx context.Context, id WorkspaceId, options ListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/incidents", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c IncidentsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c IncidentsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []Incident `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c IncidentsClient) ListComplete(ctx context.Context, id WorkspaceId, options ListOperationOptions) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, options, IncidentOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c IncidentsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ListOperationOptions, predicate IncidentOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]Incident, 0) - - page, err := c.List(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2023-02-01/metadata/client.go b/resource-manager/securityinsights/2023-02-01/metadata/client.go index 05f0e7940c0..59e4192159f 100644 --- a/resource-manager/securityinsights/2023-02-01/metadata/client.go +++ b/resource-manager/securityinsights/2023-02-01/metadata/client.go @@ -1,18 +1,26 @@ package metadata -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type MetadataClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewMetadataClientWithBaseURI(endpoint string) MetadataClient { - return MetadataClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewMetadataClientWithBaseURI(sdkApi sdkEnv.Api) (*MetadataClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "metadata", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating MetadataClient: %+v", err) } + + return &MetadataClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2023-02-01/metadata/constants.go b/resource-manager/securityinsights/2023-02-01/metadata/constants.go index 0773b1ddd6a..5cd159a8e2b 100644 --- a/resource-manager/securityinsights/2023-02-01/metadata/constants.go +++ b/resource-manager/securityinsights/2023-02-01/metadata/constants.go @@ -1,6 +1,10 @@ package metadata -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -19,6 +23,19 @@ func PossibleValuesForOperator() []string { } } +func (s *Operator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseOperator(input string) (*Operator, error) { vals := map[string]Operator{ "and": OperatorAND, @@ -51,6 +68,19 @@ func PossibleValuesForSourceKind() []string { } } +func (s *SourceKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSourceKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSourceKind(input string) (*SourceKind, error) { vals := map[string]SourceKind{ "community": SourceKindCommunity, @@ -83,6 +113,19 @@ func PossibleValuesForSupportTier() []string { } } +func (s *SupportTier) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSupportTier(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSupportTier(input string) (*SupportTier, error) { vals := map[string]SupportTier{ "community": SupportTierCommunity, diff --git a/resource-manager/securityinsights/2023-02-01/metadata/method_create.go b/resource-manager/securityinsights/2023-02-01/metadata/method_create.go new file mode 100644 index 00000000000..36522e6397c --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/metadata/method_create.go @@ -0,0 +1,56 @@ +package metadata + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *MetadataModel +} + +// Create ... +func (c MetadataClient) Create(ctx context.Context, id MetadataId, input MetadataModel) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/metadata/method_create_autorest.go b/resource-manager/securityinsights/2023-02-01/metadata/method_create_autorest.go deleted file mode 100644 index 1ae47584687..00000000000 --- a/resource-manager/securityinsights/2023-02-01/metadata/method_create_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package metadata - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOperationResponse struct { - HttpResponse *http.Response - Model *MetadataModel -} - -// Create ... -func (c MetadataClient) Create(ctx context.Context, id MetadataId, input MetadataModel) (result CreateOperationResponse, err error) { - req, err := c.preparerForCreate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Create", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Create", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Create", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreate prepares the Create request. -func (c MetadataClient) preparerForCreate(ctx context.Context, id MetadataId, input MetadataModel) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreate handles the response to the Create request. The method always -// closes the http.Response Body. -func (c MetadataClient) responderForCreate(resp *http.Response) (result CreateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-02-01/metadata/method_delete.go b/resource-manager/securityinsights/2023-02-01/metadata/method_delete.go new file mode 100644 index 00000000000..559f479cb03 --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/metadata/method_delete.go @@ -0,0 +1,47 @@ +package metadata + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c MetadataClient) Delete(ctx context.Context, id MetadataId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/metadata/method_delete_autorest.go b/resource-manager/securityinsights/2023-02-01/metadata/method_delete_autorest.go deleted file mode 100644 index 3a151eefd21..00000000000 --- a/resource-manager/securityinsights/2023-02-01/metadata/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package metadata - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c MetadataClient) Delete(ctx context.Context, id MetadataId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c MetadataClient) preparerForDelete(ctx context.Context, id MetadataId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c MetadataClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-02-01/metadata/method_get.go b/resource-manager/securityinsights/2023-02-01/metadata/method_get.go new file mode 100644 index 00000000000..a687bafec62 --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/metadata/method_get.go @@ -0,0 +1,51 @@ +package metadata + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *MetadataModel +} + +// Get ... +func (c MetadataClient) Get(ctx context.Context, id MetadataId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/metadata/method_get_autorest.go b/resource-manager/securityinsights/2023-02-01/metadata/method_get_autorest.go deleted file mode 100644 index 25827d74702..00000000000 --- a/resource-manager/securityinsights/2023-02-01/metadata/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package metadata - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *MetadataModel -} - -// Get ... -func (c MetadataClient) Get(ctx context.Context, id MetadataId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c MetadataClient) preparerForGet(ctx context.Context, id MetadataId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c MetadataClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-02-01/metadata/method_list.go b/resource-manager/securityinsights/2023-02-01/metadata/method_list.go new file mode 100644 index 00000000000..58267143629 --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/metadata/method_list.go @@ -0,0 +1,131 @@ +package metadata + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]MetadataModel +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []MetadataModel +} + +type ListOperationOptions struct { + Filter *string + Orderby *string + Skip *int64 + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c MetadataClient) List(ctx context.Context, id WorkspaceId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/metadata", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]MetadataModel `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c MetadataClient) ListComplete(ctx context.Context, id WorkspaceId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, MetadataModelOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c MetadataClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ListOperationOptions, predicate MetadataModelOperationPredicate) (result ListCompleteResult, err error) { + items := make([]MetadataModel, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2023-02-01/metadata/method_list_autorest.go b/resource-manager/securityinsights/2023-02-01/metadata/method_list_autorest.go deleted file mode 100644 index e5f025d62ee..00000000000 --- a/resource-manager/securityinsights/2023-02-01/metadata/method_list_autorest.go +++ /dev/null @@ -1,230 +0,0 @@ -package metadata - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]MetadataModel - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []MetadataModel -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ListOperationOptions struct { - Filter *string - Orderby *string - Skip *int64 - Top *int64 -} - -func DefaultListOperationOptions() ListOperationOptions { - return ListOperationOptions{} -} - -func (o ListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Filter != nil { - out["$filter"] = *o.Filter - } - - if o.Orderby != nil { - out["$orderby"] = *o.Orderby - } - - if o.Skip != nil { - out["$skip"] = *o.Skip - } - - if o.Top != nil { - out["$top"] = *o.Top - } - - return out -} - -// List ... -func (c MetadataClient) List(ctx context.Context, id WorkspaceId, options ListOperationOptions) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c MetadataClient) preparerForList(ctx context.Context, id WorkspaceId, options ListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/metadata", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c MetadataClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c MetadataClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []MetadataModel `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c MetadataClient) ListComplete(ctx context.Context, id WorkspaceId, options ListOperationOptions) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, options, MetadataModelOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c MetadataClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ListOperationOptions, predicate MetadataModelOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]MetadataModel, 0) - - page, err := c.List(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2023-02-01/metadata/method_update.go b/resource-manager/securityinsights/2023-02-01/metadata/method_update.go new file mode 100644 index 00000000000..47f777cee27 --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/metadata/method_update.go @@ -0,0 +1,55 @@ +package metadata + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *MetadataModel +} + +// Update ... +func (c MetadataClient) Update(ctx context.Context, id MetadataId, input MetadataPatch) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/metadata/method_update_autorest.go b/resource-manager/securityinsights/2023-02-01/metadata/method_update_autorest.go deleted file mode 100644 index a4bd18d08d6..00000000000 --- a/resource-manager/securityinsights/2023-02-01/metadata/method_update_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package metadata - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type UpdateOperationResponse struct { - HttpResponse *http.Response - Model *MetadataModel -} - -// Update ... -func (c MetadataClient) Update(ctx context.Context, id MetadataId, input MetadataPatch) (result UpdateOperationResponse, err error) { - req, err := c.preparerForUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Update", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Update", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Update", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForUpdate prepares the Update request. -func (c MetadataClient) preparerForUpdate(ctx context.Context, id MetadataId, input MetadataPatch) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPatch(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForUpdate handles the response to the Update request. The method always -// closes the http.Response Body. -func (c MetadataClient) responderForUpdate(resp *http.Response) (result UpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-02-01/securitymlanalyticssettings/client.go b/resource-manager/securityinsights/2023-02-01/securitymlanalyticssettings/client.go index 50d64fb429c..65b248a41f5 100644 --- a/resource-manager/securityinsights/2023-02-01/securitymlanalyticssettings/client.go +++ b/resource-manager/securityinsights/2023-02-01/securitymlanalyticssettings/client.go @@ -1,18 +1,26 @@ package securitymlanalyticssettings -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type SecurityMLAnalyticsSettingsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewSecurityMLAnalyticsSettingsClientWithBaseURI(endpoint string) SecurityMLAnalyticsSettingsClient { - return SecurityMLAnalyticsSettingsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewSecurityMLAnalyticsSettingsClientWithBaseURI(sdkApi sdkEnv.Api) (*SecurityMLAnalyticsSettingsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "securitymlanalyticssettings", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SecurityMLAnalyticsSettingsClient: %+v", err) } + + return &SecurityMLAnalyticsSettingsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2023-02-01/securitymlanalyticssettings/constants.go b/resource-manager/securityinsights/2023-02-01/securitymlanalyticssettings/constants.go index 47b13b875e2..e32d4d9875f 100644 --- a/resource-manager/securityinsights/2023-02-01/securitymlanalyticssettings/constants.go +++ b/resource-manager/securityinsights/2023-02-01/securitymlanalyticssettings/constants.go @@ -1,6 +1,10 @@ package securitymlanalyticssettings -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -49,6 +53,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -90,6 +107,19 @@ func PossibleValuesForSecurityMLAnalyticsSettingsKind() []string { } } +func (s *SecurityMLAnalyticsSettingsKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSecurityMLAnalyticsSettingsKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSecurityMLAnalyticsSettingsKind(input string) (*SecurityMLAnalyticsSettingsKind, error) { vals := map[string]SecurityMLAnalyticsSettingsKind{ "anomaly": SecurityMLAnalyticsSettingsKindAnomaly, @@ -117,6 +147,19 @@ func PossibleValuesForSettingsStatus() []string { } } +func (s *SettingsStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSettingsStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSettingsStatus(input string) (*SettingsStatus, error) { vals := map[string]SettingsStatus{ "flighting": SettingsStatusFlighting, diff --git a/resource-manager/securityinsights/2023-02-01/securitymlanalyticssettings/method_createorupdate.go b/resource-manager/securityinsights/2023-02-01/securitymlanalyticssettings/method_createorupdate.go new file mode 100644 index 00000000000..f08267b7fac --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/securitymlanalyticssettings/method_createorupdate.go @@ -0,0 +1,63 @@ +package securitymlanalyticssettings + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SecurityMLAnalyticsSetting +} + +// CreateOrUpdate ... +func (c SecurityMLAnalyticsSettingsClient) CreateOrUpdate(ctx context.Context, id SecurityMLAnalyticsSettingId, input SecurityMLAnalyticsSetting) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalSecurityMLAnalyticsSettingImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/securitymlanalyticssettings/method_createorupdate_autorest.go b/resource-manager/securityinsights/2023-02-01/securitymlanalyticssettings/method_createorupdate_autorest.go deleted file mode 100644 index e72d9bcb79b..00000000000 --- a/resource-manager/securityinsights/2023-02-01/securitymlanalyticssettings/method_createorupdate_autorest.go +++ /dev/null @@ -1,78 +0,0 @@ -package securitymlanalyticssettings - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *SecurityMLAnalyticsSetting -} - -// CreateOrUpdate ... -func (c SecurityMLAnalyticsSettingsClient) CreateOrUpdate(ctx context.Context, id SecurityMLAnalyticsSettingId, input SecurityMLAnalyticsSetting) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c SecurityMLAnalyticsSettingsClient) preparerForCreateOrUpdate(ctx context.Context, id SecurityMLAnalyticsSettingId, input SecurityMLAnalyticsSetting) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c SecurityMLAnalyticsSettingsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalSecurityMLAnalyticsSettingImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2023-02-01/securitymlanalyticssettings/method_delete.go b/resource-manager/securityinsights/2023-02-01/securitymlanalyticssettings/method_delete.go new file mode 100644 index 00000000000..36309ecb138 --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/securitymlanalyticssettings/method_delete.go @@ -0,0 +1,47 @@ +package securitymlanalyticssettings + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c SecurityMLAnalyticsSettingsClient) Delete(ctx context.Context, id SecurityMLAnalyticsSettingId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/securitymlanalyticssettings/method_delete_autorest.go b/resource-manager/securityinsights/2023-02-01/securitymlanalyticssettings/method_delete_autorest.go deleted file mode 100644 index a2b0d18f72f..00000000000 --- a/resource-manager/securityinsights/2023-02-01/securitymlanalyticssettings/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package securitymlanalyticssettings - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c SecurityMLAnalyticsSettingsClient) Delete(ctx context.Context, id SecurityMLAnalyticsSettingId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c SecurityMLAnalyticsSettingsClient) preparerForDelete(ctx context.Context, id SecurityMLAnalyticsSettingId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c SecurityMLAnalyticsSettingsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-02-01/securitymlanalyticssettings/method_get.go b/resource-manager/securityinsights/2023-02-01/securitymlanalyticssettings/method_get.go new file mode 100644 index 00000000000..9be89fdf974 --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/securitymlanalyticssettings/method_get.go @@ -0,0 +1,58 @@ +package securitymlanalyticssettings + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SecurityMLAnalyticsSetting +} + +// Get ... +func (c SecurityMLAnalyticsSettingsClient) Get(ctx context.Context, id SecurityMLAnalyticsSettingId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalSecurityMLAnalyticsSettingImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/securitymlanalyticssettings/method_get_autorest.go b/resource-manager/securityinsights/2023-02-01/securitymlanalyticssettings/method_get_autorest.go deleted file mode 100644 index 0157220a0eb..00000000000 --- a/resource-manager/securityinsights/2023-02-01/securitymlanalyticssettings/method_get_autorest.go +++ /dev/null @@ -1,77 +0,0 @@ -package securitymlanalyticssettings - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *SecurityMLAnalyticsSetting -} - -// Get ... -func (c SecurityMLAnalyticsSettingsClient) Get(ctx context.Context, id SecurityMLAnalyticsSettingId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c SecurityMLAnalyticsSettingsClient) preparerForGet(ctx context.Context, id SecurityMLAnalyticsSettingId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c SecurityMLAnalyticsSettingsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalSecurityMLAnalyticsSettingImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2023-02-01/securitymlanalyticssettings/method_list.go b/resource-manager/securityinsights/2023-02-01/securitymlanalyticssettings/method_list.go new file mode 100644 index 00000000000..49878345af3 --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/securitymlanalyticssettings/method_list.go @@ -0,0 +1,103 @@ +package securitymlanalyticssettings + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SecurityMLAnalyticsSetting +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []SecurityMLAnalyticsSetting +} + +// List ... +func (c SecurityMLAnalyticsSettingsClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/securityMLAnalyticsSettings", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]SecurityMLAnalyticsSetting, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalSecurityMLAnalyticsSettingImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for SecurityMLAnalyticsSetting (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// ListComplete retrieves all the results into a single object +func (c SecurityMLAnalyticsSettingsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, SecurityMLAnalyticsSettingOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SecurityMLAnalyticsSettingsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate SecurityMLAnalyticsSettingOperationPredicate) (result ListCompleteResult, err error) { + items := make([]SecurityMLAnalyticsSetting, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2023-02-01/securitymlanalyticssettings/method_list_autorest.go b/resource-manager/securityinsights/2023-02-01/securitymlanalyticssettings/method_list_autorest.go deleted file mode 100644 index 127297aa869..00000000000 --- a/resource-manager/securityinsights/2023-02-01/securitymlanalyticssettings/method_list_autorest.go +++ /dev/null @@ -1,196 +0,0 @@ -package securitymlanalyticssettings - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]SecurityMLAnalyticsSetting - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []SecurityMLAnalyticsSetting -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c SecurityMLAnalyticsSettingsClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c SecurityMLAnalyticsSettingsClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/securityMLAnalyticsSettings", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c SecurityMLAnalyticsSettingsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c SecurityMLAnalyticsSettingsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]SecurityMLAnalyticsSetting, 0) - for i, v := range respObj.Values { - val, err := unmarshalSecurityMLAnalyticsSettingImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for SecurityMLAnalyticsSetting (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c SecurityMLAnalyticsSettingsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, SecurityMLAnalyticsSettingOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c SecurityMLAnalyticsSettingsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate SecurityMLAnalyticsSettingOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]SecurityMLAnalyticsSetting, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2023-02-01/sentinelonboardingstates/client.go b/resource-manager/securityinsights/2023-02-01/sentinelonboardingstates/client.go index 0ae442ba3fa..94701ed853a 100644 --- a/resource-manager/securityinsights/2023-02-01/sentinelonboardingstates/client.go +++ b/resource-manager/securityinsights/2023-02-01/sentinelonboardingstates/client.go @@ -1,18 +1,26 @@ package sentinelonboardingstates -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type SentinelOnboardingStatesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewSentinelOnboardingStatesClientWithBaseURI(endpoint string) SentinelOnboardingStatesClient { - return SentinelOnboardingStatesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewSentinelOnboardingStatesClientWithBaseURI(sdkApi sdkEnv.Api) (*SentinelOnboardingStatesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sentinelonboardingstates", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SentinelOnboardingStatesClient: %+v", err) } + + return &SentinelOnboardingStatesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2023-02-01/sentinelonboardingstates/method_create.go b/resource-manager/securityinsights/2023-02-01/sentinelonboardingstates/method_create.go new file mode 100644 index 00000000000..af163a9d66b --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/sentinelonboardingstates/method_create.go @@ -0,0 +1,56 @@ +package sentinelonboardingstates + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SentinelOnboardingState +} + +// Create ... +func (c SentinelOnboardingStatesClient) Create(ctx context.Context, id OnboardingStateId, input SentinelOnboardingState) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/sentinelonboardingstates/method_create_autorest.go b/resource-manager/securityinsights/2023-02-01/sentinelonboardingstates/method_create_autorest.go deleted file mode 100644 index 9ad88e95157..00000000000 --- a/resource-manager/securityinsights/2023-02-01/sentinelonboardingstates/method_create_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package sentinelonboardingstates - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOperationResponse struct { - HttpResponse *http.Response - Model *SentinelOnboardingState -} - -// Create ... -func (c SentinelOnboardingStatesClient) Create(ctx context.Context, id OnboardingStateId, input SentinelOnboardingState) (result CreateOperationResponse, err error) { - req, err := c.preparerForCreate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Create", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Create", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Create", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreate prepares the Create request. -func (c SentinelOnboardingStatesClient) preparerForCreate(ctx context.Context, id OnboardingStateId, input SentinelOnboardingState) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreate handles the response to the Create request. The method always -// closes the http.Response Body. -func (c SentinelOnboardingStatesClient) responderForCreate(resp *http.Response) (result CreateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-02-01/sentinelonboardingstates/method_delete.go b/resource-manager/securityinsights/2023-02-01/sentinelonboardingstates/method_delete.go new file mode 100644 index 00000000000..1c6c5e372d7 --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/sentinelonboardingstates/method_delete.go @@ -0,0 +1,47 @@ +package sentinelonboardingstates + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c SentinelOnboardingStatesClient) Delete(ctx context.Context, id OnboardingStateId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/sentinelonboardingstates/method_delete_autorest.go b/resource-manager/securityinsights/2023-02-01/sentinelonboardingstates/method_delete_autorest.go deleted file mode 100644 index 65fa74282f7..00000000000 --- a/resource-manager/securityinsights/2023-02-01/sentinelonboardingstates/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package sentinelonboardingstates - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c SentinelOnboardingStatesClient) Delete(ctx context.Context, id OnboardingStateId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c SentinelOnboardingStatesClient) preparerForDelete(ctx context.Context, id OnboardingStateId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c SentinelOnboardingStatesClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-02-01/sentinelonboardingstates/method_get.go b/resource-manager/securityinsights/2023-02-01/sentinelonboardingstates/method_get.go new file mode 100644 index 00000000000..82165662910 --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/sentinelonboardingstates/method_get.go @@ -0,0 +1,51 @@ +package sentinelonboardingstates + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SentinelOnboardingState +} + +// Get ... +func (c SentinelOnboardingStatesClient) Get(ctx context.Context, id OnboardingStateId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/sentinelonboardingstates/method_get_autorest.go b/resource-manager/securityinsights/2023-02-01/sentinelonboardingstates/method_get_autorest.go deleted file mode 100644 index d6174a7522a..00000000000 --- a/resource-manager/securityinsights/2023-02-01/sentinelonboardingstates/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package sentinelonboardingstates - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *SentinelOnboardingState -} - -// Get ... -func (c SentinelOnboardingStatesClient) Get(ctx context.Context, id OnboardingStateId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c SentinelOnboardingStatesClient) preparerForGet(ctx context.Context, id OnboardingStateId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c SentinelOnboardingStatesClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-02-01/sentinelonboardingstates/method_list.go b/resource-manager/securityinsights/2023-02-01/sentinelonboardingstates/method_list.go new file mode 100644 index 00000000000..2efd1d41230 --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/sentinelonboardingstates/method_list.go @@ -0,0 +1,52 @@ +package sentinelonboardingstates + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SentinelOnboardingStatesList +} + +// List ... +func (c SentinelOnboardingStatesClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/onboardingStates", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/sentinelonboardingstates/method_list_autorest.go b/resource-manager/securityinsights/2023-02-01/sentinelonboardingstates/method_list_autorest.go deleted file mode 100644 index 6a00bb3d3fd..00000000000 --- a/resource-manager/securityinsights/2023-02-01/sentinelonboardingstates/method_list_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package sentinelonboardingstates - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *SentinelOnboardingStatesList -} - -// List ... -func (c SentinelOnboardingStatesClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForList prepares the List request. -func (c SentinelOnboardingStatesClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/onboardingStates", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c SentinelOnboardingStatesClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-02-01/threatintelligence/client.go b/resource-manager/securityinsights/2023-02-01/threatintelligence/client.go index 35caff31357..edf96c3143f 100644 --- a/resource-manager/securityinsights/2023-02-01/threatintelligence/client.go +++ b/resource-manager/securityinsights/2023-02-01/threatintelligence/client.go @@ -1,18 +1,26 @@ package threatintelligence -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type ThreatIntelligenceClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewThreatIntelligenceClientWithBaseURI(endpoint string) ThreatIntelligenceClient { - return ThreatIntelligenceClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewThreatIntelligenceClientWithBaseURI(sdkApi sdkEnv.Api) (*ThreatIntelligenceClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "threatintelligence", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ThreatIntelligenceClient: %+v", err) } + + return &ThreatIntelligenceClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2023-02-01/threatintelligence/constants.go b/resource-manager/securityinsights/2023-02-01/threatintelligence/constants.go index 76610b31101..8cef3ba3f75 100644 --- a/resource-manager/securityinsights/2023-02-01/threatintelligence/constants.go +++ b/resource-manager/securityinsights/2023-02-01/threatintelligence/constants.go @@ -1,6 +1,10 @@ package threatintelligence -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -17,6 +21,19 @@ func PossibleValuesForThreatIntelligenceResourceInnerKind() []string { } } +func (s *ThreatIntelligenceResourceInnerKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseThreatIntelligenceResourceInnerKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseThreatIntelligenceResourceInnerKind(input string) (*ThreatIntelligenceResourceInnerKind, error) { vals := map[string]ThreatIntelligenceResourceInnerKind{ "indicator": ThreatIntelligenceResourceInnerKindIndicator, @@ -46,6 +63,19 @@ func PossibleValuesForThreatIntelligenceSortingOrder() []string { } } +func (s *ThreatIntelligenceSortingOrder) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseThreatIntelligenceSortingOrder(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseThreatIntelligenceSortingOrder(input string) (*ThreatIntelligenceSortingOrder, error) { vals := map[string]ThreatIntelligenceSortingOrder{ "ascending": ThreatIntelligenceSortingOrderAscending, diff --git a/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatorappendtags.go b/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatorappendtags.go new file mode 100644 index 00000000000..4384327485d --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatorappendtags.go @@ -0,0 +1,51 @@ +package threatintelligence + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorAppendTagsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// IndicatorAppendTags ... +func (c ThreatIntelligenceClient) IndicatorAppendTags(ctx context.Context, id IndicatorId, input ThreatIntelligenceAppendTags) (result IndicatorAppendTagsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/appendTags", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatorappendtags_autorest.go b/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatorappendtags_autorest.go deleted file mode 100644 index 18b86a166fe..00000000000 --- a/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatorappendtags_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package threatintelligence - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorAppendTagsOperationResponse struct { - HttpResponse *http.Response -} - -// IndicatorAppendTags ... -func (c ThreatIntelligenceClient) IndicatorAppendTags(ctx context.Context, id IndicatorId, input ThreatIntelligenceAppendTags) (result IndicatorAppendTagsOperationResponse, err error) { - req, err := c.preparerForIndicatorAppendTags(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorAppendTags", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorAppendTags", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorAppendTags(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorAppendTags", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorAppendTags prepares the IndicatorAppendTags request. -func (c ThreatIntelligenceClient) preparerForIndicatorAppendTags(ctx context.Context, id IndicatorId, input ThreatIntelligenceAppendTags) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/appendTags", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorAppendTags handles the response to the IndicatorAppendTags request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorAppendTags(resp *http.Response) (result IndicatorAppendTagsOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatorcreate.go b/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatorcreate.go new file mode 100644 index 00000000000..3cee598931c --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatorcreate.go @@ -0,0 +1,63 @@ +package threatintelligence + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorCreateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ThreatIntelligenceInformation +} + +// IndicatorCreate ... +func (c ThreatIntelligenceClient) IndicatorCreate(ctx context.Context, id IndicatorId, input ThreatIntelligenceIndicatorModel) (result IndicatorCreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatorcreate_autorest.go b/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatorcreate_autorest.go deleted file mode 100644 index 98609062b7f..00000000000 --- a/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatorcreate_autorest.go +++ /dev/null @@ -1,78 +0,0 @@ -package threatintelligence - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorCreateOperationResponse struct { - HttpResponse *http.Response - Model *ThreatIntelligenceInformation -} - -// IndicatorCreate ... -func (c ThreatIntelligenceClient) IndicatorCreate(ctx context.Context, id IndicatorId, input ThreatIntelligenceIndicatorModel) (result IndicatorCreateOperationResponse, err error) { - req, err := c.preparerForIndicatorCreate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorCreate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorCreate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorCreate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorCreate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorCreate prepares the IndicatorCreate request. -func (c ThreatIntelligenceClient) preparerForIndicatorCreate(ctx context.Context, id IndicatorId, input ThreatIntelligenceIndicatorModel) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorCreate handles the response to the IndicatorCreate request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorCreate(resp *http.Response) (result IndicatorCreateOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatorcreateindicator.go b/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatorcreateindicator.go new file mode 100644 index 00000000000..0f3ab94c4f5 --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatorcreateindicator.go @@ -0,0 +1,63 @@ +package threatintelligence + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorCreateIndicatorOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ThreatIntelligenceInformation +} + +// IndicatorCreateIndicator ... +func (c ThreatIntelligenceClient) IndicatorCreateIndicator(ctx context.Context, id WorkspaceId, input ThreatIntelligenceIndicatorModel) (result IndicatorCreateIndicatorOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/createIndicator", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatorcreateindicator_autorest.go b/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatorcreateindicator_autorest.go deleted file mode 100644 index ecc76b88f5c..00000000000 --- a/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatorcreateindicator_autorest.go +++ /dev/null @@ -1,79 +0,0 @@ -package threatintelligence - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorCreateIndicatorOperationResponse struct { - HttpResponse *http.Response - Model *ThreatIntelligenceInformation -} - -// IndicatorCreateIndicator ... -func (c ThreatIntelligenceClient) IndicatorCreateIndicator(ctx context.Context, id WorkspaceId, input ThreatIntelligenceIndicatorModel) (result IndicatorCreateIndicatorOperationResponse, err error) { - req, err := c.preparerForIndicatorCreateIndicator(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorCreateIndicator", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorCreateIndicator", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorCreateIndicator(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorCreateIndicator", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorCreateIndicator prepares the IndicatorCreateIndicator request. -func (c ThreatIntelligenceClient) preparerForIndicatorCreateIndicator(ctx context.Context, id WorkspaceId, input ThreatIntelligenceIndicatorModel) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/createIndicator", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorCreateIndicator handles the response to the IndicatorCreateIndicator request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorCreateIndicator(resp *http.Response) (result IndicatorCreateIndicatorOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatordelete.go b/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatordelete.go new file mode 100644 index 00000000000..4de264524d5 --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatordelete.go @@ -0,0 +1,47 @@ +package threatintelligence + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// IndicatorDelete ... +func (c ThreatIntelligenceClient) IndicatorDelete(ctx context.Context, id IndicatorId) (result IndicatorDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatordelete_autorest.go b/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatordelete_autorest.go deleted file mode 100644 index 825d3b911ce..00000000000 --- a/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatordelete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package threatintelligence - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorDeleteOperationResponse struct { - HttpResponse *http.Response -} - -// IndicatorDelete ... -func (c ThreatIntelligenceClient) IndicatorDelete(ctx context.Context, id IndicatorId) (result IndicatorDeleteOperationResponse, err error) { - req, err := c.preparerForIndicatorDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorDelete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorDelete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorDelete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorDelete prepares the IndicatorDelete request. -func (c ThreatIntelligenceClient) preparerForIndicatorDelete(ctx context.Context, id IndicatorId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorDelete handles the response to the IndicatorDelete request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorDelete(resp *http.Response) (result IndicatorDeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatorget.go b/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatorget.go new file mode 100644 index 00000000000..3358363f139 --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatorget.go @@ -0,0 +1,58 @@ +package threatintelligence + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ThreatIntelligenceInformation +} + +// IndicatorGet ... +func (c ThreatIntelligenceClient) IndicatorGet(ctx context.Context, id IndicatorId) (result IndicatorGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatorget_autorest.go b/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatorget_autorest.go deleted file mode 100644 index ac1187fb285..00000000000 --- a/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatorget_autorest.go +++ /dev/null @@ -1,77 +0,0 @@ -package threatintelligence - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorGetOperationResponse struct { - HttpResponse *http.Response - Model *ThreatIntelligenceInformation -} - -// IndicatorGet ... -func (c ThreatIntelligenceClient) IndicatorGet(ctx context.Context, id IndicatorId) (result IndicatorGetOperationResponse, err error) { - req, err := c.preparerForIndicatorGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorGet", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorGet", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorGet", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorGet prepares the IndicatorGet request. -func (c ThreatIntelligenceClient) preparerForIndicatorGet(ctx context.Context, id IndicatorId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorGet handles the response to the IndicatorGet request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorGet(resp *http.Response) (result IndicatorGetOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatormetricslist.go b/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatormetricslist.go new file mode 100644 index 00000000000..688ff3c16d1 --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatormetricslist.go @@ -0,0 +1,52 @@ +package threatintelligence + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorMetricsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ThreatIntelligenceMetricsList +} + +// IndicatorMetricsList ... +func (c ThreatIntelligenceClient) IndicatorMetricsList(ctx context.Context, id WorkspaceId) (result IndicatorMetricsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/metrics", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatormetricslist_autorest.go b/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatormetricslist_autorest.go deleted file mode 100644 index 1835c26ed96..00000000000 --- a/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatormetricslist_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package threatintelligence - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorMetricsListOperationResponse struct { - HttpResponse *http.Response - Model *ThreatIntelligenceMetricsList -} - -// IndicatorMetricsList ... -func (c ThreatIntelligenceClient) IndicatorMetricsList(ctx context.Context, id WorkspaceId) (result IndicatorMetricsListOperationResponse, err error) { - req, err := c.preparerForIndicatorMetricsList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorMetricsList", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorMetricsList", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorMetricsList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorMetricsList", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorMetricsList prepares the IndicatorMetricsList request. -func (c ThreatIntelligenceClient) preparerForIndicatorMetricsList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/metrics", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorMetricsList handles the response to the IndicatorMetricsList request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorMetricsList(resp *http.Response) (result IndicatorMetricsListOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatorqueryindicators.go b/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatorqueryindicators.go new file mode 100644 index 00000000000..8ce639f2623 --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatorqueryindicators.go @@ -0,0 +1,103 @@ +package threatintelligence + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorQueryIndicatorsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ThreatIntelligenceInformation +} + +type IndicatorQueryIndicatorsCompleteResult struct { + LatestHttpResponse *http.Response + Items []ThreatIntelligenceInformation +} + +// IndicatorQueryIndicators ... +func (c ThreatIntelligenceClient) IndicatorQueryIndicators(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria) (result IndicatorQueryIndicatorsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/queryIndicators", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]ThreatIntelligenceInformation, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalThreatIntelligenceInformationImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for ThreatIntelligenceInformation (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// IndicatorQueryIndicatorsComplete retrieves all the results into a single object +func (c ThreatIntelligenceClient) IndicatorQueryIndicatorsComplete(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria) (IndicatorQueryIndicatorsCompleteResult, error) { + return c.IndicatorQueryIndicatorsCompleteMatchingPredicate(ctx, id, input, ThreatIntelligenceInformationOperationPredicate{}) +} + +// IndicatorQueryIndicatorsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ThreatIntelligenceClient) IndicatorQueryIndicatorsCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria, predicate ThreatIntelligenceInformationOperationPredicate) (result IndicatorQueryIndicatorsCompleteResult, err error) { + items := make([]ThreatIntelligenceInformation, 0) + + resp, err := c.IndicatorQueryIndicators(ctx, id, input) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = IndicatorQueryIndicatorsCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatorqueryindicators_autorest.go b/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatorqueryindicators_autorest.go deleted file mode 100644 index fcbe7c74758..00000000000 --- a/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatorqueryindicators_autorest.go +++ /dev/null @@ -1,197 +0,0 @@ -package threatintelligence - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorQueryIndicatorsOperationResponse struct { - HttpResponse *http.Response - Model *[]ThreatIntelligenceInformation - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (IndicatorQueryIndicatorsOperationResponse, error) -} - -type IndicatorQueryIndicatorsCompleteResult struct { - Items []ThreatIntelligenceInformation -} - -func (r IndicatorQueryIndicatorsOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r IndicatorQueryIndicatorsOperationResponse) LoadMore(ctx context.Context) (resp IndicatorQueryIndicatorsOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// IndicatorQueryIndicators ... -func (c ThreatIntelligenceClient) IndicatorQueryIndicators(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria) (resp IndicatorQueryIndicatorsOperationResponse, err error) { - req, err := c.preparerForIndicatorQueryIndicators(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorQueryIndicators", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorQueryIndicators", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForIndicatorQueryIndicators(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorQueryIndicators", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForIndicatorQueryIndicators prepares the IndicatorQueryIndicators request. -func (c ThreatIntelligenceClient) preparerForIndicatorQueryIndicators(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/queryIndicators", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForIndicatorQueryIndicatorsWithNextLink prepares the IndicatorQueryIndicators request with the given nextLink token. -func (c ThreatIntelligenceClient) preparerForIndicatorQueryIndicatorsWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorQueryIndicators handles the response to the IndicatorQueryIndicators request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorQueryIndicators(resp *http.Response) (result IndicatorQueryIndicatorsOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]ThreatIntelligenceInformation, 0) - for i, v := range respObj.Values { - val, err := unmarshalThreatIntelligenceInformationImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for ThreatIntelligenceInformation (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result IndicatorQueryIndicatorsOperationResponse, err error) { - req, err := c.preparerForIndicatorQueryIndicatorsWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorQueryIndicators", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorQueryIndicators", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorQueryIndicators(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorQueryIndicators", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// IndicatorQueryIndicatorsComplete retrieves all of the results into a single object -func (c ThreatIntelligenceClient) IndicatorQueryIndicatorsComplete(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria) (IndicatorQueryIndicatorsCompleteResult, error) { - return c.IndicatorQueryIndicatorsCompleteMatchingPredicate(ctx, id, input, ThreatIntelligenceInformationOperationPredicate{}) -} - -// IndicatorQueryIndicatorsCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c ThreatIntelligenceClient) IndicatorQueryIndicatorsCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria, predicate ThreatIntelligenceInformationOperationPredicate) (resp IndicatorQueryIndicatorsCompleteResult, err error) { - items := make([]ThreatIntelligenceInformation, 0) - - page, err := c.IndicatorQueryIndicators(ctx, id, input) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := IndicatorQueryIndicatorsCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatorreplacetags.go b/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatorreplacetags.go new file mode 100644 index 00000000000..052bbe7b66a --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatorreplacetags.go @@ -0,0 +1,63 @@ +package threatintelligence + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorReplaceTagsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ThreatIntelligenceInformation +} + +// IndicatorReplaceTags ... +func (c ThreatIntelligenceClient) IndicatorReplaceTags(ctx context.Context, id IndicatorId, input ThreatIntelligenceIndicatorModel) (result IndicatorReplaceTagsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/replaceTags", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatorreplacetags_autorest.go b/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatorreplacetags_autorest.go deleted file mode 100644 index 01efbe5b778..00000000000 --- a/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatorreplacetags_autorest.go +++ /dev/null @@ -1,79 +0,0 @@ -package threatintelligence - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorReplaceTagsOperationResponse struct { - HttpResponse *http.Response - Model *ThreatIntelligenceInformation -} - -// IndicatorReplaceTags ... -func (c ThreatIntelligenceClient) IndicatorReplaceTags(ctx context.Context, id IndicatorId, input ThreatIntelligenceIndicatorModel) (result IndicatorReplaceTagsOperationResponse, err error) { - req, err := c.preparerForIndicatorReplaceTags(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorReplaceTags", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorReplaceTags", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorReplaceTags(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorReplaceTags", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorReplaceTags prepares the IndicatorReplaceTags request. -func (c ThreatIntelligenceClient) preparerForIndicatorReplaceTags(ctx context.Context, id IndicatorId, input ThreatIntelligenceIndicatorModel) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/replaceTags", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorReplaceTags handles the response to the IndicatorReplaceTags request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorReplaceTags(resp *http.Response) (result IndicatorReplaceTagsOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatorslist.go b/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatorslist.go new file mode 100644 index 00000000000..860ecd26255 --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatorslist.go @@ -0,0 +1,139 @@ +package threatintelligence + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ThreatIntelligenceInformation +} + +type IndicatorsListCompleteResult struct { + LatestHttpResponse *http.Response + Items []ThreatIntelligenceInformation +} + +type IndicatorsListOperationOptions struct { + Filter *string + Orderby *string + Top *int64 +} + +func DefaultIndicatorsListOperationOptions() IndicatorsListOperationOptions { + return IndicatorsListOperationOptions{} +} + +func (o IndicatorsListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o IndicatorsListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o IndicatorsListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// IndicatorsList ... +func (c ThreatIntelligenceClient) IndicatorsList(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions) (result IndicatorsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/indicators", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]ThreatIntelligenceInformation, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalThreatIntelligenceInformationImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for ThreatIntelligenceInformation (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// IndicatorsListComplete retrieves all the results into a single object +func (c ThreatIntelligenceClient) IndicatorsListComplete(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions) (IndicatorsListCompleteResult, error) { + return c.IndicatorsListCompleteMatchingPredicate(ctx, id, options, ThreatIntelligenceInformationOperationPredicate{}) +} + +// IndicatorsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ThreatIntelligenceClient) IndicatorsListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions, predicate ThreatIntelligenceInformationOperationPredicate) (result IndicatorsListCompleteResult, err error) { + items := make([]ThreatIntelligenceInformation, 0) + + resp, err := c.IndicatorsList(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = IndicatorsListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatorslist_autorest.go b/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatorslist_autorest.go deleted file mode 100644 index 22ef9d7b193..00000000000 --- a/resource-manager/securityinsights/2023-02-01/threatintelligence/method_indicatorslist_autorest.go +++ /dev/null @@ -1,235 +0,0 @@ -package threatintelligence - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorsListOperationResponse struct { - HttpResponse *http.Response - Model *[]ThreatIntelligenceInformation - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (IndicatorsListOperationResponse, error) -} - -type IndicatorsListCompleteResult struct { - Items []ThreatIntelligenceInformation -} - -func (r IndicatorsListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r IndicatorsListOperationResponse) LoadMore(ctx context.Context) (resp IndicatorsListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type IndicatorsListOperationOptions struct { - Filter *string - Orderby *string - Top *int64 -} - -func DefaultIndicatorsListOperationOptions() IndicatorsListOperationOptions { - return IndicatorsListOperationOptions{} -} - -func (o IndicatorsListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o IndicatorsListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Filter != nil { - out["$filter"] = *o.Filter - } - - if o.Orderby != nil { - out["$orderby"] = *o.Orderby - } - - if o.Top != nil { - out["$top"] = *o.Top - } - - return out -} - -// IndicatorsList ... -func (c ThreatIntelligenceClient) IndicatorsList(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions) (resp IndicatorsListOperationResponse, err error) { - req, err := c.preparerForIndicatorsList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForIndicatorsList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForIndicatorsList prepares the IndicatorsList request. -func (c ThreatIntelligenceClient) preparerForIndicatorsList(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/indicators", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForIndicatorsListWithNextLink prepares the IndicatorsList request with the given nextLink token. -func (c ThreatIntelligenceClient) preparerForIndicatorsListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorsList handles the response to the IndicatorsList request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorsList(resp *http.Response) (result IndicatorsListOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]ThreatIntelligenceInformation, 0) - for i, v := range respObj.Values { - val, err := unmarshalThreatIntelligenceInformationImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for ThreatIntelligenceInformation (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result IndicatorsListOperationResponse, err error) { - req, err := c.preparerForIndicatorsListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorsList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// IndicatorsListComplete retrieves all of the results into a single object -func (c ThreatIntelligenceClient) IndicatorsListComplete(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions) (IndicatorsListCompleteResult, error) { - return c.IndicatorsListCompleteMatchingPredicate(ctx, id, options, ThreatIntelligenceInformationOperationPredicate{}) -} - -// IndicatorsListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c ThreatIntelligenceClient) IndicatorsListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions, predicate ThreatIntelligenceInformationOperationPredicate) (resp IndicatorsListCompleteResult, err error) { - items := make([]ThreatIntelligenceInformation, 0) - - page, err := c.IndicatorsList(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := IndicatorsListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2023-02-01/watchlistitems/client.go b/resource-manager/securityinsights/2023-02-01/watchlistitems/client.go index 9403755456e..d3193694a48 100644 --- a/resource-manager/securityinsights/2023-02-01/watchlistitems/client.go +++ b/resource-manager/securityinsights/2023-02-01/watchlistitems/client.go @@ -1,18 +1,26 @@ package watchlistitems -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type WatchlistItemsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewWatchlistItemsClientWithBaseURI(endpoint string) WatchlistItemsClient { - return WatchlistItemsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewWatchlistItemsClientWithBaseURI(sdkApi sdkEnv.Api) (*WatchlistItemsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "watchlistitems", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating WatchlistItemsClient: %+v", err) } + + return &WatchlistItemsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2023-02-01/watchlistitems/method_createorupdate.go b/resource-manager/securityinsights/2023-02-01/watchlistitems/method_createorupdate.go new file mode 100644 index 00000000000..d02782f71bc --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/watchlistitems/method_createorupdate.go @@ -0,0 +1,56 @@ +package watchlistitems + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *WatchlistItem +} + +// CreateOrUpdate ... +func (c WatchlistItemsClient) CreateOrUpdate(ctx context.Context, id WatchlistItemId, input WatchlistItem) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/watchlistitems/method_createorupdate_autorest.go b/resource-manager/securityinsights/2023-02-01/watchlistitems/method_createorupdate_autorest.go deleted file mode 100644 index 15d8fdcc2be..00000000000 --- a/resource-manager/securityinsights/2023-02-01/watchlistitems/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package watchlistitems - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *WatchlistItem -} - -// CreateOrUpdate ... -func (c WatchlistItemsClient) CreateOrUpdate(ctx context.Context, id WatchlistItemId, input WatchlistItem) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c WatchlistItemsClient) preparerForCreateOrUpdate(ctx context.Context, id WatchlistItemId, input WatchlistItem) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c WatchlistItemsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-02-01/watchlistitems/method_delete.go b/resource-manager/securityinsights/2023-02-01/watchlistitems/method_delete.go new file mode 100644 index 00000000000..5565b767fa5 --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/watchlistitems/method_delete.go @@ -0,0 +1,47 @@ +package watchlistitems + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c WatchlistItemsClient) Delete(ctx context.Context, id WatchlistItemId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/watchlistitems/method_delete_autorest.go b/resource-manager/securityinsights/2023-02-01/watchlistitems/method_delete_autorest.go deleted file mode 100644 index c9b8c46f9e5..00000000000 --- a/resource-manager/securityinsights/2023-02-01/watchlistitems/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package watchlistitems - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c WatchlistItemsClient) Delete(ctx context.Context, id WatchlistItemId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c WatchlistItemsClient) preparerForDelete(ctx context.Context, id WatchlistItemId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c WatchlistItemsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-02-01/watchlistitems/method_get.go b/resource-manager/securityinsights/2023-02-01/watchlistitems/method_get.go new file mode 100644 index 00000000000..ff9a8e143fa --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/watchlistitems/method_get.go @@ -0,0 +1,51 @@ +package watchlistitems + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *WatchlistItem +} + +// Get ... +func (c WatchlistItemsClient) Get(ctx context.Context, id WatchlistItemId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/watchlistitems/method_get_autorest.go b/resource-manager/securityinsights/2023-02-01/watchlistitems/method_get_autorest.go deleted file mode 100644 index b294f999f64..00000000000 --- a/resource-manager/securityinsights/2023-02-01/watchlistitems/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package watchlistitems - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *WatchlistItem -} - -// Get ... -func (c WatchlistItemsClient) Get(ctx context.Context, id WatchlistItemId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c WatchlistItemsClient) preparerForGet(ctx context.Context, id WatchlistItemId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c WatchlistItemsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-02-01/watchlistitems/method_list.go b/resource-manager/securityinsights/2023-02-01/watchlistitems/method_list.go new file mode 100644 index 00000000000..8a4d418ea0b --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/watchlistitems/method_list.go @@ -0,0 +1,91 @@ +package watchlistitems + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]WatchlistItem +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []WatchlistItem +} + +// List ... +func (c WatchlistItemsClient) List(ctx context.Context, id WatchlistId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/watchlistItems", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]WatchlistItem `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c WatchlistItemsClient) ListComplete(ctx context.Context, id WatchlistId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, WatchlistItemOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c WatchlistItemsClient) ListCompleteMatchingPredicate(ctx context.Context, id WatchlistId, predicate WatchlistItemOperationPredicate) (result ListCompleteResult, err error) { + items := make([]WatchlistItem, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2023-02-01/watchlistitems/method_list_autorest.go b/resource-manager/securityinsights/2023-02-01/watchlistitems/method_list_autorest.go deleted file mode 100644 index d8e4bf85bf1..00000000000 --- a/resource-manager/securityinsights/2023-02-01/watchlistitems/method_list_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package watchlistitems - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]WatchlistItem - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []WatchlistItem -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c WatchlistItemsClient) List(ctx context.Context, id WatchlistId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c WatchlistItemsClient) preparerForList(ctx context.Context, id WatchlistId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/watchlistItems", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c WatchlistItemsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c WatchlistItemsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []WatchlistItem `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c WatchlistItemsClient) ListComplete(ctx context.Context, id WatchlistId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, WatchlistItemOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c WatchlistItemsClient) ListCompleteMatchingPredicate(ctx context.Context, id WatchlistId, predicate WatchlistItemOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]WatchlistItem, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2023-02-01/watchlists/client.go b/resource-manager/securityinsights/2023-02-01/watchlists/client.go index 61cfa3d0ac3..45211175054 100644 --- a/resource-manager/securityinsights/2023-02-01/watchlists/client.go +++ b/resource-manager/securityinsights/2023-02-01/watchlists/client.go @@ -1,18 +1,26 @@ package watchlists -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type WatchlistsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewWatchlistsClientWithBaseURI(endpoint string) WatchlistsClient { - return WatchlistsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewWatchlistsClientWithBaseURI(sdkApi sdkEnv.Api) (*WatchlistsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "watchlists", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating WatchlistsClient: %+v", err) } + + return &WatchlistsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2023-02-01/watchlists/constants.go b/resource-manager/securityinsights/2023-02-01/watchlists/constants.go index 504c5ecef48..2ec351b8408 100644 --- a/resource-manager/securityinsights/2023-02-01/watchlists/constants.go +++ b/resource-manager/securityinsights/2023-02-01/watchlists/constants.go @@ -1,6 +1,10 @@ package watchlists -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -19,6 +23,19 @@ func PossibleValuesForSource() []string { } } +func (s *Source) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSource(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSource(input string) (*Source, error) { vals := map[string]Source{ "local file": SourceLocalFile, diff --git a/resource-manager/securityinsights/2023-02-01/watchlists/method_createorupdate.go b/resource-manager/securityinsights/2023-02-01/watchlists/method_createorupdate.go new file mode 100644 index 00000000000..cf0dc47e9d7 --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/watchlists/method_createorupdate.go @@ -0,0 +1,56 @@ +package watchlists + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Watchlist +} + +// CreateOrUpdate ... +func (c WatchlistsClient) CreateOrUpdate(ctx context.Context, id WatchlistId, input Watchlist) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/watchlists/method_createorupdate_autorest.go b/resource-manager/securityinsights/2023-02-01/watchlists/method_createorupdate_autorest.go deleted file mode 100644 index e6d8a5976b8..00000000000 --- a/resource-manager/securityinsights/2023-02-01/watchlists/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package watchlists - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *Watchlist -} - -// CreateOrUpdate ... -func (c WatchlistsClient) CreateOrUpdate(ctx context.Context, id WatchlistId, input Watchlist) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c WatchlistsClient) preparerForCreateOrUpdate(ctx context.Context, id WatchlistId, input Watchlist) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c WatchlistsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-02-01/watchlists/method_delete.go b/resource-manager/securityinsights/2023-02-01/watchlists/method_delete.go new file mode 100644 index 00000000000..9d495f99c57 --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/watchlists/method_delete.go @@ -0,0 +1,47 @@ +package watchlists + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c WatchlistsClient) Delete(ctx context.Context, id WatchlistId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/watchlists/method_delete_autorest.go b/resource-manager/securityinsights/2023-02-01/watchlists/method_delete_autorest.go deleted file mode 100644 index 56234124b82..00000000000 --- a/resource-manager/securityinsights/2023-02-01/watchlists/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package watchlists - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c WatchlistsClient) Delete(ctx context.Context, id WatchlistId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c WatchlistsClient) preparerForDelete(ctx context.Context, id WatchlistId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c WatchlistsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-02-01/watchlists/method_get.go b/resource-manager/securityinsights/2023-02-01/watchlists/method_get.go new file mode 100644 index 00000000000..39ec92feaeb --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/watchlists/method_get.go @@ -0,0 +1,51 @@ +package watchlists + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Watchlist +} + +// Get ... +func (c WatchlistsClient) Get(ctx context.Context, id WatchlistId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-02-01/watchlists/method_get_autorest.go b/resource-manager/securityinsights/2023-02-01/watchlists/method_get_autorest.go deleted file mode 100644 index d7253f62215..00000000000 --- a/resource-manager/securityinsights/2023-02-01/watchlists/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package watchlists - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *Watchlist -} - -// Get ... -func (c WatchlistsClient) Get(ctx context.Context, id WatchlistId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c WatchlistsClient) preparerForGet(ctx context.Context, id WatchlistId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c WatchlistsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-02-01/watchlists/method_list.go b/resource-manager/securityinsights/2023-02-01/watchlists/method_list.go new file mode 100644 index 00000000000..9122b014815 --- /dev/null +++ b/resource-manager/securityinsights/2023-02-01/watchlists/method_list.go @@ -0,0 +1,91 @@ +package watchlists + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Watchlist +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Watchlist +} + +// List ... +func (c WatchlistsClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/watchlists", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Watchlist `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c WatchlistsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, WatchlistOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c WatchlistsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate WatchlistOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Watchlist, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2023-02-01/watchlists/method_list_autorest.go b/resource-manager/securityinsights/2023-02-01/watchlists/method_list_autorest.go deleted file mode 100644 index a3a2c27c15e..00000000000 --- a/resource-manager/securityinsights/2023-02-01/watchlists/method_list_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package watchlists - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]Watchlist - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []Watchlist -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c WatchlistsClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c WatchlistsClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/watchlists", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c WatchlistsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c WatchlistsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []Watchlist `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c WatchlistsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, WatchlistOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c WatchlistsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate WatchlistOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]Watchlist, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2023-11-01/actions/client.go b/resource-manager/securityinsights/2023-11-01/actions/client.go index 9a66b55eb82..a2b7d01bfe1 100644 --- a/resource-manager/securityinsights/2023-11-01/actions/client.go +++ b/resource-manager/securityinsights/2023-11-01/actions/client.go @@ -1,18 +1,26 @@ package actions -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type ActionsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewActionsClientWithBaseURI(endpoint string) ActionsClient { - return ActionsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewActionsClientWithBaseURI(sdkApi sdkEnv.Api) (*ActionsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "actions", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ActionsClient: %+v", err) } + + return &ActionsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2023-11-01/actions/method_createorupdate.go b/resource-manager/securityinsights/2023-11-01/actions/method_createorupdate.go new file mode 100644 index 00000000000..1672bf99a0f --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/actions/method_createorupdate.go @@ -0,0 +1,56 @@ +package actions + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ActionResponse +} + +// CreateOrUpdate ... +func (c ActionsClient) CreateOrUpdate(ctx context.Context, id ActionId, input ActionRequest) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/actions/method_createorupdate_autorest.go b/resource-manager/securityinsights/2023-11-01/actions/method_createorupdate_autorest.go deleted file mode 100644 index f5145e1a555..00000000000 --- a/resource-manager/securityinsights/2023-11-01/actions/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package actions - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *ActionResponse -} - -// CreateOrUpdate ... -func (c ActionsClient) CreateOrUpdate(ctx context.Context, id ActionId, input ActionRequest) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c ActionsClient) preparerForCreateOrUpdate(ctx context.Context, id ActionId, input ActionRequest) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c ActionsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/actions/method_delete.go b/resource-manager/securityinsights/2023-11-01/actions/method_delete.go new file mode 100644 index 00000000000..0f8a28307c2 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/actions/method_delete.go @@ -0,0 +1,47 @@ +package actions + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c ActionsClient) Delete(ctx context.Context, id ActionId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/actions/method_delete_autorest.go b/resource-manager/securityinsights/2023-11-01/actions/method_delete_autorest.go deleted file mode 100644 index d142f9f3054..00000000000 --- a/resource-manager/securityinsights/2023-11-01/actions/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package actions - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c ActionsClient) Delete(ctx context.Context, id ActionId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c ActionsClient) preparerForDelete(ctx context.Context, id ActionId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c ActionsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/actions/method_get.go b/resource-manager/securityinsights/2023-11-01/actions/method_get.go new file mode 100644 index 00000000000..76d3593e1f1 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/actions/method_get.go @@ -0,0 +1,51 @@ +package actions + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ActionResponse +} + +// Get ... +func (c ActionsClient) Get(ctx context.Context, id ActionId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/actions/method_get_autorest.go b/resource-manager/securityinsights/2023-11-01/actions/method_get_autorest.go deleted file mode 100644 index aa1388a0c31..00000000000 --- a/resource-manager/securityinsights/2023-11-01/actions/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package actions - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *ActionResponse -} - -// Get ... -func (c ActionsClient) Get(ctx context.Context, id ActionId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c ActionsClient) preparerForGet(ctx context.Context, id ActionId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c ActionsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/actions/method_listbyalertrule.go b/resource-manager/securityinsights/2023-11-01/actions/method_listbyalertrule.go new file mode 100644 index 00000000000..09d32b9d82d --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/actions/method_listbyalertrule.go @@ -0,0 +1,91 @@ +package actions + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByAlertRuleOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ActionResponse +} + +type ListByAlertRuleCompleteResult struct { + LatestHttpResponse *http.Response + Items []ActionResponse +} + +// ListByAlertRule ... +func (c ActionsClient) ListByAlertRule(ctx context.Context, id AlertRuleId) (result ListByAlertRuleOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/actions", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ActionResponse `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByAlertRuleComplete retrieves all the results into a single object +func (c ActionsClient) ListByAlertRuleComplete(ctx context.Context, id AlertRuleId) (ListByAlertRuleCompleteResult, error) { + return c.ListByAlertRuleCompleteMatchingPredicate(ctx, id, ActionResponseOperationPredicate{}) +} + +// ListByAlertRuleCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ActionsClient) ListByAlertRuleCompleteMatchingPredicate(ctx context.Context, id AlertRuleId, predicate ActionResponseOperationPredicate) (result ListByAlertRuleCompleteResult, err error) { + items := make([]ActionResponse, 0) + + resp, err := c.ListByAlertRule(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByAlertRuleCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2023-11-01/actions/method_listbyalertrule_autorest.go b/resource-manager/securityinsights/2023-11-01/actions/method_listbyalertrule_autorest.go deleted file mode 100644 index a58a9738f1f..00000000000 --- a/resource-manager/securityinsights/2023-11-01/actions/method_listbyalertrule_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package actions - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListByAlertRuleOperationResponse struct { - HttpResponse *http.Response - Model *[]ActionResponse - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListByAlertRuleOperationResponse, error) -} - -type ListByAlertRuleCompleteResult struct { - Items []ActionResponse -} - -func (r ListByAlertRuleOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListByAlertRuleOperationResponse) LoadMore(ctx context.Context) (resp ListByAlertRuleOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// ListByAlertRule ... -func (c ActionsClient) ListByAlertRule(ctx context.Context, id AlertRuleId) (resp ListByAlertRuleOperationResponse, err error) { - req, err := c.preparerForListByAlertRule(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "ListByAlertRule", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "ListByAlertRule", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForListByAlertRule(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "ListByAlertRule", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForListByAlertRule prepares the ListByAlertRule request. -func (c ActionsClient) preparerForListByAlertRule(ctx context.Context, id AlertRuleId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/actions", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListByAlertRuleWithNextLink prepares the ListByAlertRule request with the given nextLink token. -func (c ActionsClient) preparerForListByAlertRuleWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForListByAlertRule handles the response to the ListByAlertRule request. The method always -// closes the http.Response Body. -func (c ActionsClient) responderForListByAlertRule(resp *http.Response) (result ListByAlertRuleOperationResponse, err error) { - type page struct { - Values []ActionResponse `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByAlertRuleOperationResponse, err error) { - req, err := c.preparerForListByAlertRuleWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "ListByAlertRule", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "ListByAlertRule", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForListByAlertRule(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "actions.ActionsClient", "ListByAlertRule", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListByAlertRuleComplete retrieves all of the results into a single object -func (c ActionsClient) ListByAlertRuleComplete(ctx context.Context, id AlertRuleId) (ListByAlertRuleCompleteResult, error) { - return c.ListByAlertRuleCompleteMatchingPredicate(ctx, id, ActionResponseOperationPredicate{}) -} - -// ListByAlertRuleCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c ActionsClient) ListByAlertRuleCompleteMatchingPredicate(ctx context.Context, id AlertRuleId, predicate ActionResponseOperationPredicate) (resp ListByAlertRuleCompleteResult, err error) { - items := make([]ActionResponse, 0) - - page, err := c.ListByAlertRule(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListByAlertRuleCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2023-11-01/alertrules/client.go b/resource-manager/securityinsights/2023-11-01/alertrules/client.go index 6e34bca2ce3..e6ca04af9da 100644 --- a/resource-manager/securityinsights/2023-11-01/alertrules/client.go +++ b/resource-manager/securityinsights/2023-11-01/alertrules/client.go @@ -1,18 +1,26 @@ package alertrules -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type AlertRulesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewAlertRulesClientWithBaseURI(endpoint string) AlertRulesClient { - return AlertRulesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewAlertRulesClientWithBaseURI(sdkApi sdkEnv.Api) (*AlertRulesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "alertrules", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AlertRulesClient: %+v", err) } + + return &AlertRulesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2023-11-01/alertrules/constants.go b/resource-manager/securityinsights/2023-11-01/alertrules/constants.go index 5d1bc78496f..fb693333ff0 100644 --- a/resource-manager/securityinsights/2023-11-01/alertrules/constants.go +++ b/resource-manager/securityinsights/2023-11-01/alertrules/constants.go @@ -1,6 +1,10 @@ package alertrules -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -19,6 +23,19 @@ func PossibleValuesForAlertDetail() []string { } } +func (s *AlertDetail) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertDetail(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertDetail(input string) (*AlertDetail, error) { vals := map[string]AlertDetail{ "displayname": AlertDetailDisplayName, @@ -61,6 +78,19 @@ func PossibleValuesForAlertProperty() []string { } } +func (s *AlertProperty) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertProperty(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertProperty(input string) (*AlertProperty, error) { vals := map[string]AlertProperty{ "alertlink": AlertPropertyAlertLink, @@ -98,6 +128,19 @@ func PossibleValuesForAlertRuleKind() []string { } } +func (s *AlertRuleKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertRuleKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertRuleKind(input string) (*AlertRuleKind, error) { vals := map[string]AlertRuleKind{ "fusion": AlertRuleKindFusion, @@ -131,6 +174,19 @@ func PossibleValuesForAlertSeverity() []string { } } +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertSeverity(input string) (*AlertSeverity, error) { vals := map[string]AlertSeverity{ "high": AlertSeverityHigh, @@ -191,6 +247,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -266,6 +335,19 @@ func PossibleValuesForEntityMappingType() []string { } } +func (s *EntityMappingType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityMappingType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityMappingType(input string) (*EntityMappingType, error) { vals := map[string]EntityMappingType{ "account": EntityMappingTypeAccount, @@ -310,6 +392,19 @@ func PossibleValuesForEventGroupingAggregationKind() []string { } } +func (s *EventGroupingAggregationKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEventGroupingAggregationKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEventGroupingAggregationKind(input string) (*EventGroupingAggregationKind, error) { vals := map[string]EventGroupingAggregationKind{ "alertperresult": EventGroupingAggregationKindAlertPerResult, @@ -340,6 +435,19 @@ func PossibleValuesForMatchingMethod() []string { } } +func (s *MatchingMethod) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMatchingMethod(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseMatchingMethod(input string) (*MatchingMethod, error) { vals := map[string]MatchingMethod{ "allentities": MatchingMethodAllEntities, @@ -375,6 +483,19 @@ func PossibleValuesForMicrosoftSecurityProductName() []string { } } +func (s *MicrosoftSecurityProductName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMicrosoftSecurityProductName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseMicrosoftSecurityProductName(input string) (*MicrosoftSecurityProductName, error) { vals := map[string]MicrosoftSecurityProductName{ "azure active directory identity protection": MicrosoftSecurityProductNameAzureActiveDirectoryIdentityProtection, @@ -410,6 +531,19 @@ func PossibleValuesForTriggerOperator() []string { } } +func (s *TriggerOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTriggerOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseTriggerOperator(input string) (*TriggerOperator, error) { vals := map[string]TriggerOperator{ "equal": TriggerOperatorEqual, diff --git a/resource-manager/securityinsights/2023-11-01/alertrules/method_createorupdate.go b/resource-manager/securityinsights/2023-11-01/alertrules/method_createorupdate.go new file mode 100644 index 00000000000..f77c7558d09 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/alertrules/method_createorupdate.go @@ -0,0 +1,63 @@ +package alertrules + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AlertRule +} + +// CreateOrUpdate ... +func (c AlertRulesClient) CreateOrUpdate(ctx context.Context, id AlertRuleId, input AlertRule) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalAlertRuleImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/alertrules/method_createorupdate_autorest.go b/resource-manager/securityinsights/2023-11-01/alertrules/method_createorupdate_autorest.go deleted file mode 100644 index 548f6c4ef37..00000000000 --- a/resource-manager/securityinsights/2023-11-01/alertrules/method_createorupdate_autorest.go +++ /dev/null @@ -1,78 +0,0 @@ -package alertrules - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *AlertRule -} - -// CreateOrUpdate ... -func (c AlertRulesClient) CreateOrUpdate(ctx context.Context, id AlertRuleId, input AlertRule) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c AlertRulesClient) preparerForCreateOrUpdate(ctx context.Context, id AlertRuleId, input AlertRule) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c AlertRulesClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalAlertRuleImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2023-11-01/alertrules/method_delete.go b/resource-manager/securityinsights/2023-11-01/alertrules/method_delete.go new file mode 100644 index 00000000000..aae7085c25e --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/alertrules/method_delete.go @@ -0,0 +1,47 @@ +package alertrules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c AlertRulesClient) Delete(ctx context.Context, id AlertRuleId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/alertrules/method_delete_autorest.go b/resource-manager/securityinsights/2023-11-01/alertrules/method_delete_autorest.go deleted file mode 100644 index 417e1a0017e..00000000000 --- a/resource-manager/securityinsights/2023-11-01/alertrules/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package alertrules - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c AlertRulesClient) Delete(ctx context.Context, id AlertRuleId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c AlertRulesClient) preparerForDelete(ctx context.Context, id AlertRuleId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c AlertRulesClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/alertrules/method_get.go b/resource-manager/securityinsights/2023-11-01/alertrules/method_get.go new file mode 100644 index 00000000000..945c07bfad1 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/alertrules/method_get.go @@ -0,0 +1,58 @@ +package alertrules + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AlertRule +} + +// Get ... +func (c AlertRulesClient) Get(ctx context.Context, id AlertRuleId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalAlertRuleImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/alertrules/method_get_autorest.go b/resource-manager/securityinsights/2023-11-01/alertrules/method_get_autorest.go deleted file mode 100644 index ddd1836d4de..00000000000 --- a/resource-manager/securityinsights/2023-11-01/alertrules/method_get_autorest.go +++ /dev/null @@ -1,77 +0,0 @@ -package alertrules - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *AlertRule -} - -// Get ... -func (c AlertRulesClient) Get(ctx context.Context, id AlertRuleId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c AlertRulesClient) preparerForGet(ctx context.Context, id AlertRuleId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c AlertRulesClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalAlertRuleImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2023-11-01/alertrules/method_list.go b/resource-manager/securityinsights/2023-11-01/alertrules/method_list.go new file mode 100644 index 00000000000..5ac99496167 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/alertrules/method_list.go @@ -0,0 +1,103 @@ +package alertrules + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AlertRule +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []AlertRule +} + +// List ... +func (c AlertRulesClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/alertRules", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]AlertRule, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalAlertRuleImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for AlertRule (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// ListComplete retrieves all the results into a single object +func (c AlertRulesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, AlertRuleOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AlertRulesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AlertRuleOperationPredicate) (result ListCompleteResult, err error) { + items := make([]AlertRule, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2023-11-01/alertrules/method_list_autorest.go b/resource-manager/securityinsights/2023-11-01/alertrules/method_list_autorest.go deleted file mode 100644 index f06cf0f6241..00000000000 --- a/resource-manager/securityinsights/2023-11-01/alertrules/method_list_autorest.go +++ /dev/null @@ -1,196 +0,0 @@ -package alertrules - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]AlertRule - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []AlertRule -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c AlertRulesClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c AlertRulesClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/alertRules", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c AlertRulesClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c AlertRulesClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]AlertRule, 0) - for i, v := range respObj.Values { - val, err := unmarshalAlertRuleImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for AlertRule (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertrules.AlertRulesClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c AlertRulesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, AlertRuleOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c AlertRulesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AlertRuleOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]AlertRule, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2023-11-01/alertruletemplates/client.go b/resource-manager/securityinsights/2023-11-01/alertruletemplates/client.go index c439e5a41c7..2932bf14a55 100644 --- a/resource-manager/securityinsights/2023-11-01/alertruletemplates/client.go +++ b/resource-manager/securityinsights/2023-11-01/alertruletemplates/client.go @@ -1,18 +1,26 @@ package alertruletemplates -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type AlertRuleTemplatesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewAlertRuleTemplatesClientWithBaseURI(endpoint string) AlertRuleTemplatesClient { - return AlertRuleTemplatesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewAlertRuleTemplatesClientWithBaseURI(sdkApi sdkEnv.Api) (*AlertRuleTemplatesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "alertruletemplates", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AlertRuleTemplatesClient: %+v", err) } + + return &AlertRuleTemplatesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2023-11-01/alertruletemplates/constants.go b/resource-manager/securityinsights/2023-11-01/alertruletemplates/constants.go index c69aaf1ed65..0f9acf0ddf0 100644 --- a/resource-manager/securityinsights/2023-11-01/alertruletemplates/constants.go +++ b/resource-manager/securityinsights/2023-11-01/alertruletemplates/constants.go @@ -1,6 +1,10 @@ package alertruletemplates -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -33,6 +37,19 @@ func PossibleValuesForAlertProperty() []string { } } +func (s *AlertProperty) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertProperty(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertProperty(input string) (*AlertProperty, error) { vals := map[string]AlertProperty{ "alertlink": AlertPropertyAlertLink, @@ -70,6 +87,19 @@ func PossibleValuesForAlertRuleKind() []string { } } +func (s *AlertRuleKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertRuleKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertRuleKind(input string) (*AlertRuleKind, error) { vals := map[string]AlertRuleKind{ "fusion": AlertRuleKindFusion, @@ -103,6 +133,19 @@ func PossibleValuesForAlertSeverity() []string { } } +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertSeverity(input string) (*AlertSeverity, error) { vals := map[string]AlertSeverity{ "high": AlertSeverityHigh, @@ -163,6 +206,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -238,6 +294,19 @@ func PossibleValuesForEntityMappingType() []string { } } +func (s *EntityMappingType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityMappingType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityMappingType(input string) (*EntityMappingType, error) { vals := map[string]EntityMappingType{ "account": EntityMappingTypeAccount, @@ -282,6 +351,19 @@ func PossibleValuesForEventGroupingAggregationKind() []string { } } +func (s *EventGroupingAggregationKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEventGroupingAggregationKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEventGroupingAggregationKind(input string) (*EventGroupingAggregationKind, error) { vals := map[string]EventGroupingAggregationKind{ "alertperresult": EventGroupingAggregationKindAlertPerResult, @@ -316,6 +398,19 @@ func PossibleValuesForMicrosoftSecurityProductName() []string { } } +func (s *MicrosoftSecurityProductName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMicrosoftSecurityProductName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseMicrosoftSecurityProductName(input string) (*MicrosoftSecurityProductName, error) { vals := map[string]MicrosoftSecurityProductName{ "azure active directory identity protection": MicrosoftSecurityProductNameAzureActiveDirectoryIdentityProtection, @@ -349,6 +444,19 @@ func PossibleValuesForTemplateStatus() []string { } } +func (s *TemplateStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTemplateStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseTemplateStatus(input string) (*TemplateStatus, error) { vals := map[string]TemplateStatus{ "available": TemplateStatusAvailable, @@ -382,6 +490,19 @@ func PossibleValuesForTriggerOperator() []string { } } +func (s *TriggerOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTriggerOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseTriggerOperator(input string) (*TriggerOperator, error) { vals := map[string]TriggerOperator{ "equal": TriggerOperatorEqual, diff --git a/resource-manager/securityinsights/2023-11-01/alertruletemplates/method_get.go b/resource-manager/securityinsights/2023-11-01/alertruletemplates/method_get.go new file mode 100644 index 00000000000..861712be66a --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/alertruletemplates/method_get.go @@ -0,0 +1,58 @@ +package alertruletemplates + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AlertRuleTemplate +} + +// Get ... +func (c AlertRuleTemplatesClient) Get(ctx context.Context, id AlertRuleTemplateId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalAlertRuleTemplateImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/alertruletemplates/method_get_autorest.go b/resource-manager/securityinsights/2023-11-01/alertruletemplates/method_get_autorest.go deleted file mode 100644 index ad4e0487d83..00000000000 --- a/resource-manager/securityinsights/2023-11-01/alertruletemplates/method_get_autorest.go +++ /dev/null @@ -1,77 +0,0 @@ -package alertruletemplates - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *AlertRuleTemplate -} - -// Get ... -func (c AlertRuleTemplatesClient) Get(ctx context.Context, id AlertRuleTemplateId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c AlertRuleTemplatesClient) preparerForGet(ctx context.Context, id AlertRuleTemplateId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c AlertRuleTemplatesClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalAlertRuleTemplateImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2023-11-01/alertruletemplates/method_list.go b/resource-manager/securityinsights/2023-11-01/alertruletemplates/method_list.go new file mode 100644 index 00000000000..21f9ceec3de --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/alertruletemplates/method_list.go @@ -0,0 +1,103 @@ +package alertruletemplates + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AlertRuleTemplate +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []AlertRuleTemplate +} + +// List ... +func (c AlertRuleTemplatesClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/alertRuleTemplates", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]AlertRuleTemplate, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalAlertRuleTemplateImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for AlertRuleTemplate (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// ListComplete retrieves all the results into a single object +func (c AlertRuleTemplatesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, AlertRuleTemplateOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AlertRuleTemplatesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AlertRuleTemplateOperationPredicate) (result ListCompleteResult, err error) { + items := make([]AlertRuleTemplate, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2023-11-01/alertruletemplates/method_list_autorest.go b/resource-manager/securityinsights/2023-11-01/alertruletemplates/method_list_autorest.go deleted file mode 100644 index 56794382966..00000000000 --- a/resource-manager/securityinsights/2023-11-01/alertruletemplates/method_list_autorest.go +++ /dev/null @@ -1,196 +0,0 @@ -package alertruletemplates - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]AlertRuleTemplate - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []AlertRuleTemplate -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c AlertRuleTemplatesClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c AlertRuleTemplatesClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/alertRuleTemplates", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c AlertRuleTemplatesClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c AlertRuleTemplatesClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]AlertRuleTemplate, 0) - for i, v := range respObj.Values { - val, err := unmarshalAlertRuleTemplateImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for AlertRuleTemplate (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "alertruletemplates.AlertRuleTemplatesClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c AlertRuleTemplatesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, AlertRuleTemplateOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c AlertRuleTemplatesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AlertRuleTemplateOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]AlertRuleTemplate, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2023-11-01/automationrules/client.go b/resource-manager/securityinsights/2023-11-01/automationrules/client.go index 960f049c387..18fafea1496 100644 --- a/resource-manager/securityinsights/2023-11-01/automationrules/client.go +++ b/resource-manager/securityinsights/2023-11-01/automationrules/client.go @@ -1,18 +1,26 @@ package automationrules -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type AutomationRulesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewAutomationRulesClientWithBaseURI(endpoint string) AutomationRulesClient { - return AutomationRulesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewAutomationRulesClientWithBaseURI(sdkApi sdkEnv.Api) (*AutomationRulesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "automationrules", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AutomationRulesClient: %+v", err) } + + return &AutomationRulesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2023-11-01/automationrules/constants.go b/resource-manager/securityinsights/2023-11-01/automationrules/constants.go index 42f2fc009f2..71480e3d3d7 100644 --- a/resource-manager/securityinsights/2023-11-01/automationrules/constants.go +++ b/resource-manager/securityinsights/2023-11-01/automationrules/constants.go @@ -1,6 +1,10 @@ package automationrules -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -19,6 +23,19 @@ func PossibleValuesForActionType() []string { } } +func (s *ActionType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseActionType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseActionType(input string) (*ActionType, error) { vals := map[string]ActionType{ "modifyproperties": ActionTypeModifyProperties, @@ -51,6 +68,19 @@ func PossibleValuesForAutomationRulePropertyArrayChangedConditionSupportedArrayT } } +func (s *AutomationRulePropertyArrayChangedConditionSupportedArrayType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRulePropertyArrayChangedConditionSupportedArrayType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAutomationRulePropertyArrayChangedConditionSupportedArrayType(input string) (*AutomationRulePropertyArrayChangedConditionSupportedArrayType, error) { vals := map[string]AutomationRulePropertyArrayChangedConditionSupportedArrayType{ "alerts": AutomationRulePropertyArrayChangedConditionSupportedArrayTypeAlerts, @@ -79,6 +109,19 @@ func PossibleValuesForAutomationRulePropertyArrayChangedConditionSupportedChange } } +func (s *AutomationRulePropertyArrayChangedConditionSupportedChangeType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRulePropertyArrayChangedConditionSupportedChangeType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAutomationRulePropertyArrayChangedConditionSupportedChangeType(input string) (*AutomationRulePropertyArrayChangedConditionSupportedChangeType, error) { vals := map[string]AutomationRulePropertyArrayChangedConditionSupportedChangeType{ "added": AutomationRulePropertyArrayChangedConditionSupportedChangeTypeAdded, @@ -106,6 +149,19 @@ func PossibleValuesForAutomationRulePropertyChangedConditionSupportedChangedType } } +func (s *AutomationRulePropertyChangedConditionSupportedChangedType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRulePropertyChangedConditionSupportedChangedType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAutomationRulePropertyChangedConditionSupportedChangedType(input string) (*AutomationRulePropertyChangedConditionSupportedChangedType, error) { vals := map[string]AutomationRulePropertyChangedConditionSupportedChangedType{ "changedfrom": AutomationRulePropertyChangedConditionSupportedChangedTypeChangedFrom, @@ -136,6 +192,19 @@ func PossibleValuesForAutomationRulePropertyChangedConditionSupportedPropertyTyp } } +func (s *AutomationRulePropertyChangedConditionSupportedPropertyType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRulePropertyChangedConditionSupportedPropertyType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAutomationRulePropertyChangedConditionSupportedPropertyType(input string) (*AutomationRulePropertyChangedConditionSupportedPropertyType, error) { vals := map[string]AutomationRulePropertyChangedConditionSupportedPropertyType{ "incidentowner": AutomationRulePropertyChangedConditionSupportedPropertyTypeIncidentOwner, @@ -177,6 +246,19 @@ func PossibleValuesForAutomationRulePropertyConditionSupportedOperator() []strin } } +func (s *AutomationRulePropertyConditionSupportedOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRulePropertyConditionSupportedOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAutomationRulePropertyConditionSupportedOperator(input string) (*AutomationRulePropertyConditionSupportedOperator, error) { vals := map[string]AutomationRulePropertyConditionSupportedOperator{ "contains": AutomationRulePropertyConditionSupportedOperatorContains, @@ -319,6 +401,19 @@ func PossibleValuesForAutomationRulePropertyConditionSupportedProperty() []strin } } +func (s *AutomationRulePropertyConditionSupportedProperty) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRulePropertyConditionSupportedProperty(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAutomationRulePropertyConditionSupportedProperty(input string) (*AutomationRulePropertyConditionSupportedProperty, error) { vals := map[string]AutomationRulePropertyConditionSupportedProperty{ "accountaadtenantid": AutomationRulePropertyConditionSupportedPropertyAccountAadTenantId, @@ -403,6 +498,19 @@ func PossibleValuesForConditionType() []string { } } +func (s *ConditionType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConditionType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConditionType(input string) (*ConditionType, error) { vals := map[string]ConditionType{ "property": ConditionTypeProperty, @@ -436,6 +544,19 @@ func PossibleValuesForIncidentClassification() []string { } } +func (s *IncidentClassification) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentClassification(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentClassification(input string) (*IncidentClassification, error) { vals := map[string]IncidentClassification{ "benignpositive": IncidentClassificationBenignPositive, @@ -470,6 +591,19 @@ func PossibleValuesForIncidentClassificationReason() []string { } } +func (s *IncidentClassificationReason) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentClassificationReason(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentClassificationReason(input string) (*IncidentClassificationReason, error) { vals := map[string]IncidentClassificationReason{ "inaccuratedata": IncidentClassificationReasonInaccurateData, @@ -500,6 +634,19 @@ func PossibleValuesForIncidentLabelType() []string { } } +func (s *IncidentLabelType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentLabelType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentLabelType(input string) (*IncidentLabelType, error) { vals := map[string]IncidentLabelType{ "autoassigned": IncidentLabelTypeAutoAssigned, @@ -532,6 +679,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, @@ -564,6 +724,19 @@ func PossibleValuesForIncidentStatus() []string { } } +func (s *IncidentStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentStatus(input string) (*IncidentStatus, error) { vals := map[string]IncidentStatus{ "active": IncidentStatusActive, @@ -595,6 +768,19 @@ func PossibleValuesForOwnerType() []string { } } +func (s *OwnerType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOwnerType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseOwnerType(input string) (*OwnerType, error) { vals := map[string]OwnerType{ "group": OwnerTypeGroup, @@ -624,6 +810,19 @@ func PossibleValuesForTriggersOn() []string { } } +func (s *TriggersOn) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTriggersOn(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseTriggersOn(input string) (*TriggersOn, error) { vals := map[string]TriggersOn{ "alerts": TriggersOnAlerts, @@ -652,6 +851,19 @@ func PossibleValuesForTriggersWhen() []string { } } +func (s *TriggersWhen) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTriggersWhen(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseTriggersWhen(input string) (*TriggersWhen, error) { vals := map[string]TriggersWhen{ "created": TriggersWhenCreated, diff --git a/resource-manager/securityinsights/2023-11-01/automationrules/method_createorupdate.go b/resource-manager/securityinsights/2023-11-01/automationrules/method_createorupdate.go new file mode 100644 index 00000000000..c0b3c44f2da --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/automationrules/method_createorupdate.go @@ -0,0 +1,56 @@ +package automationrules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AutomationRule +} + +// CreateOrUpdate ... +func (c AutomationRulesClient) CreateOrUpdate(ctx context.Context, id AutomationRuleId, input AutomationRule) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/automationrules/method_createorupdate_autorest.go b/resource-manager/securityinsights/2023-11-01/automationrules/method_createorupdate_autorest.go deleted file mode 100644 index 790f2ff99f9..00000000000 --- a/resource-manager/securityinsights/2023-11-01/automationrules/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package automationrules - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *AutomationRule -} - -// CreateOrUpdate ... -func (c AutomationRulesClient) CreateOrUpdate(ctx context.Context, id AutomationRuleId, input AutomationRule) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c AutomationRulesClient) preparerForCreateOrUpdate(ctx context.Context, id AutomationRuleId, input AutomationRule) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c AutomationRulesClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/automationrules/method_delete.go b/resource-manager/securityinsights/2023-11-01/automationrules/method_delete.go new file mode 100644 index 00000000000..682e97ed619 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/automationrules/method_delete.go @@ -0,0 +1,52 @@ +package automationrules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *interface{} +} + +// Delete ... +func (c AutomationRulesClient) Delete(ctx context.Context, id AutomationRuleId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/automationrules/method_delete_autorest.go b/resource-manager/securityinsights/2023-11-01/automationrules/method_delete_autorest.go deleted file mode 100644 index cd33f79070e..00000000000 --- a/resource-manager/securityinsights/2023-11-01/automationrules/method_delete_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package automationrules - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response - Model *interface{} -} - -// Delete ... -func (c AutomationRulesClient) Delete(ctx context.Context, id AutomationRuleId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c AutomationRulesClient) preparerForDelete(ctx context.Context, id AutomationRuleId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c AutomationRulesClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/automationrules/method_get.go b/resource-manager/securityinsights/2023-11-01/automationrules/method_get.go new file mode 100644 index 00000000000..0676dc80f40 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/automationrules/method_get.go @@ -0,0 +1,51 @@ +package automationrules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AutomationRule +} + +// Get ... +func (c AutomationRulesClient) Get(ctx context.Context, id AutomationRuleId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/automationrules/method_get_autorest.go b/resource-manager/securityinsights/2023-11-01/automationrules/method_get_autorest.go deleted file mode 100644 index 20f385aa8d7..00000000000 --- a/resource-manager/securityinsights/2023-11-01/automationrules/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package automationrules - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *AutomationRule -} - -// Get ... -func (c AutomationRulesClient) Get(ctx context.Context, id AutomationRuleId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c AutomationRulesClient) preparerForGet(ctx context.Context, id AutomationRuleId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c AutomationRulesClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/automationrules/method_list.go b/resource-manager/securityinsights/2023-11-01/automationrules/method_list.go new file mode 100644 index 00000000000..a3c7db4995a --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/automationrules/method_list.go @@ -0,0 +1,91 @@ +package automationrules + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AutomationRule +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []AutomationRule +} + +// List ... +func (c AutomationRulesClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/automationRules", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]AutomationRule `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c AutomationRulesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, AutomationRuleOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AutomationRulesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AutomationRuleOperationPredicate) (result ListCompleteResult, err error) { + items := make([]AutomationRule, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2023-11-01/automationrules/method_list_autorest.go b/resource-manager/securityinsights/2023-11-01/automationrules/method_list_autorest.go deleted file mode 100644 index e2818088fcf..00000000000 --- a/resource-manager/securityinsights/2023-11-01/automationrules/method_list_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package automationrules - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]AutomationRule - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []AutomationRule -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c AutomationRulesClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c AutomationRulesClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/automationRules", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c AutomationRulesClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c AutomationRulesClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []AutomationRule `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "automationrules.AutomationRulesClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c AutomationRulesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, AutomationRuleOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c AutomationRulesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AutomationRuleOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]AutomationRule, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2023-11-01/bookmarks/client.go b/resource-manager/securityinsights/2023-11-01/bookmarks/client.go index ee8ca229e2d..22469155649 100644 --- a/resource-manager/securityinsights/2023-11-01/bookmarks/client.go +++ b/resource-manager/securityinsights/2023-11-01/bookmarks/client.go @@ -1,18 +1,26 @@ package bookmarks -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type BookmarksClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewBookmarksClientWithBaseURI(endpoint string) BookmarksClient { - return BookmarksClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewBookmarksClientWithBaseURI(sdkApi sdkEnv.Api) (*BookmarksClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "bookmarks", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating BookmarksClient: %+v", err) } + + return &BookmarksClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2023-11-01/bookmarks/constants.go b/resource-manager/securityinsights/2023-11-01/bookmarks/constants.go index f3a9bf2482b..c057284aed1 100644 --- a/resource-manager/securityinsights/2023-11-01/bookmarks/constants.go +++ b/resource-manager/securityinsights/2023-11-01/bookmarks/constants.go @@ -1,6 +1,10 @@ package bookmarks -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -23,6 +27,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, diff --git a/resource-manager/securityinsights/2023-11-01/bookmarks/method_createorupdate.go b/resource-manager/securityinsights/2023-11-01/bookmarks/method_createorupdate.go new file mode 100644 index 00000000000..72b6987ce5b --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/bookmarks/method_createorupdate.go @@ -0,0 +1,56 @@ +package bookmarks + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Bookmark +} + +// CreateOrUpdate ... +func (c BookmarksClient) CreateOrUpdate(ctx context.Context, id BookmarkId, input Bookmark) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/bookmarks/method_createorupdate_autorest.go b/resource-manager/securityinsights/2023-11-01/bookmarks/method_createorupdate_autorest.go deleted file mode 100644 index 6bae46884df..00000000000 --- a/resource-manager/securityinsights/2023-11-01/bookmarks/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package bookmarks - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *Bookmark -} - -// CreateOrUpdate ... -func (c BookmarksClient) CreateOrUpdate(ctx context.Context, id BookmarkId, input Bookmark) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c BookmarksClient) preparerForCreateOrUpdate(ctx context.Context, id BookmarkId, input Bookmark) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c BookmarksClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/bookmarks/method_delete.go b/resource-manager/securityinsights/2023-11-01/bookmarks/method_delete.go new file mode 100644 index 00000000000..75eef715a7c --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/bookmarks/method_delete.go @@ -0,0 +1,47 @@ +package bookmarks + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c BookmarksClient) Delete(ctx context.Context, id BookmarkId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/bookmarks/method_delete_autorest.go b/resource-manager/securityinsights/2023-11-01/bookmarks/method_delete_autorest.go deleted file mode 100644 index aa1033f513c..00000000000 --- a/resource-manager/securityinsights/2023-11-01/bookmarks/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package bookmarks - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c BookmarksClient) Delete(ctx context.Context, id BookmarkId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c BookmarksClient) preparerForDelete(ctx context.Context, id BookmarkId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c BookmarksClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/bookmarks/method_get.go b/resource-manager/securityinsights/2023-11-01/bookmarks/method_get.go new file mode 100644 index 00000000000..b8db3d1b69f --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/bookmarks/method_get.go @@ -0,0 +1,51 @@ +package bookmarks + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Bookmark +} + +// Get ... +func (c BookmarksClient) Get(ctx context.Context, id BookmarkId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/bookmarks/method_get_autorest.go b/resource-manager/securityinsights/2023-11-01/bookmarks/method_get_autorest.go deleted file mode 100644 index c76a6c0c211..00000000000 --- a/resource-manager/securityinsights/2023-11-01/bookmarks/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package bookmarks - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *Bookmark -} - -// Get ... -func (c BookmarksClient) Get(ctx context.Context, id BookmarkId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c BookmarksClient) preparerForGet(ctx context.Context, id BookmarkId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c BookmarksClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/bookmarks/method_list.go b/resource-manager/securityinsights/2023-11-01/bookmarks/method_list.go new file mode 100644 index 00000000000..432b04c413a --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/bookmarks/method_list.go @@ -0,0 +1,91 @@ +package bookmarks + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Bookmark +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Bookmark +} + +// List ... +func (c BookmarksClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/bookmarks", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Bookmark `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c BookmarksClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, BookmarkOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c BookmarksClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate BookmarkOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Bookmark, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2023-11-01/bookmarks/method_list_autorest.go b/resource-manager/securityinsights/2023-11-01/bookmarks/method_list_autorest.go deleted file mode 100644 index 7c4a69eacea..00000000000 --- a/resource-manager/securityinsights/2023-11-01/bookmarks/method_list_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package bookmarks - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]Bookmark - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []Bookmark -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c BookmarksClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c BookmarksClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/bookmarks", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c BookmarksClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c BookmarksClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []Bookmark `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "bookmarks.BookmarksClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c BookmarksClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, BookmarkOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c BookmarksClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate BookmarkOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]Bookmark, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2023-11-01/client.go b/resource-manager/securityinsights/2023-11-01/client.go index 1b06526d379..849a24c81a2 100644 --- a/resource-manager/securityinsights/2023-11-01/client.go +++ b/resource-manager/securityinsights/2023-11-01/client.go @@ -4,7 +4,8 @@ package v2023_11_01 // Licensed under the MIT License. See NOTICE.txt in the project root for license information. import ( - "github.com/Azure/go-autorest/autorest" + "fmt" + "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2023-11-01/actions" "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2023-11-01/alertrules" "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2023-11-01/alertruletemplates" @@ -30,6 +31,8 @@ import ( "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2023-11-01/threatintelligence" "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2023-11-01/watchlistitems" "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2023-11-01/watchlists" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" ) type Client struct { @@ -60,108 +63,182 @@ type Client struct { Watchlists *watchlists.WatchlistsClient } -func NewClientWithBaseURI(endpoint string, configureAuthFunc func(c *autorest.Client)) Client { - - actionsClient := actions.NewActionsClientWithBaseURI(endpoint) - configureAuthFunc(&actionsClient.Client) - - alertRuleTemplatesClient := alertruletemplates.NewAlertRuleTemplatesClientWithBaseURI(endpoint) - configureAuthFunc(&alertRuleTemplatesClient.Client) +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + actionsClient, err := actions.NewActionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Actions client: %+v", err) + } + configureFunc(actionsClient.Client) - alertRulesClient := alertrules.NewAlertRulesClientWithBaseURI(endpoint) - configureAuthFunc(&alertRulesClient.Client) + alertRuleTemplatesClient, err := alertruletemplates.NewAlertRuleTemplatesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AlertRuleTemplates client: %+v", err) + } + configureFunc(alertRuleTemplatesClient.Client) - automationRulesClient := automationrules.NewAutomationRulesClientWithBaseURI(endpoint) - configureAuthFunc(&automationRulesClient.Client) + alertRulesClient, err := alertrules.NewAlertRulesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AlertRules client: %+v", err) + } + configureFunc(alertRulesClient.Client) - bookmarksClient := bookmarks.NewBookmarksClientWithBaseURI(endpoint) - configureAuthFunc(&bookmarksClient.Client) + automationRulesClient, err := automationrules.NewAutomationRulesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AutomationRules client: %+v", err) + } + configureFunc(automationRulesClient.Client) - contentPackagesClient := contentpackages.NewContentPackagesClientWithBaseURI(endpoint) - configureAuthFunc(&contentPackagesClient.Client) + bookmarksClient, err := bookmarks.NewBookmarksClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Bookmarks client: %+v", err) + } + configureFunc(bookmarksClient.Client) - contentProductPackagesClient := contentproductpackages.NewContentProductPackagesClientWithBaseURI(endpoint) - configureAuthFunc(&contentProductPackagesClient.Client) + contentPackagesClient, err := contentpackages.NewContentPackagesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ContentPackages client: %+v", err) + } + configureFunc(contentPackagesClient.Client) - contentProductTemplatesClient := contentproducttemplates.NewContentProductTemplatesClientWithBaseURI(endpoint) - configureAuthFunc(&contentProductTemplatesClient.Client) + contentProductPackagesClient, err := contentproductpackages.NewContentProductPackagesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ContentProductPackages client: %+v", err) + } + configureFunc(contentProductPackagesClient.Client) - contentTemplatesClient := contenttemplates.NewContentTemplatesClientWithBaseURI(endpoint) - configureAuthFunc(&contentTemplatesClient.Client) + contentProductTemplatesClient, err := contentproducttemplates.NewContentProductTemplatesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ContentProductTemplates client: %+v", err) + } + configureFunc(contentProductTemplatesClient.Client) - dataConnectorsClient := dataconnectors.NewDataConnectorsClientWithBaseURI(endpoint) - configureAuthFunc(&dataConnectorsClient.Client) + contentTemplatesClient, err := contenttemplates.NewContentTemplatesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ContentTemplates client: %+v", err) + } + configureFunc(contentTemplatesClient.Client) - entityTypesClient := entitytypes.NewEntityTypesClientWithBaseURI(endpoint) - configureAuthFunc(&entityTypesClient.Client) + dataConnectorsClient, err := dataconnectors.NewDataConnectorsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DataConnectors client: %+v", err) + } + configureFunc(dataConnectorsClient.Client) - incidentAlertsClient := incidentalerts.NewIncidentAlertsClientWithBaseURI(endpoint) - configureAuthFunc(&incidentAlertsClient.Client) + entityTypesClient, err := entitytypes.NewEntityTypesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building EntityTypes client: %+v", err) + } + configureFunc(entityTypesClient.Client) - incidentBookmarksClient := incidentbookmarks.NewIncidentBookmarksClientWithBaseURI(endpoint) - configureAuthFunc(&incidentBookmarksClient.Client) + incidentAlertsClient, err := incidentalerts.NewIncidentAlertsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IncidentAlerts client: %+v", err) + } + configureFunc(incidentAlertsClient.Client) - incidentCommentsClient := incidentcomments.NewIncidentCommentsClientWithBaseURI(endpoint) - configureAuthFunc(&incidentCommentsClient.Client) + incidentBookmarksClient, err := incidentbookmarks.NewIncidentBookmarksClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IncidentBookmarks client: %+v", err) + } + configureFunc(incidentBookmarksClient.Client) - incidentEntitiesClient := incidententities.NewIncidentEntitiesClientWithBaseURI(endpoint) - configureAuthFunc(&incidentEntitiesClient.Client) + incidentCommentsClient, err := incidentcomments.NewIncidentCommentsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IncidentComments client: %+v", err) + } + configureFunc(incidentCommentsClient.Client) - incidentRelationsClient := incidentrelations.NewIncidentRelationsClientWithBaseURI(endpoint) - configureAuthFunc(&incidentRelationsClient.Client) + incidentEntitiesClient, err := incidententities.NewIncidentEntitiesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IncidentEntities client: %+v", err) + } + configureFunc(incidentEntitiesClient.Client) - incidentsClient := incidents.NewIncidentsClientWithBaseURI(endpoint) - configureAuthFunc(&incidentsClient.Client) + incidentRelationsClient, err := incidentrelations.NewIncidentRelationsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IncidentRelations client: %+v", err) + } + configureFunc(incidentRelationsClient.Client) - metadataClient := metadata.NewMetadataClientWithBaseURI(endpoint) - configureAuthFunc(&metadataClient.Client) + incidentsClient, err := incidents.NewIncidentsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Incidents client: %+v", err) + } + configureFunc(incidentsClient.Client) - repositoriesClient := repositories.NewRepositoriesClientWithBaseURI(endpoint) - configureAuthFunc(&repositoriesClient.Client) + metadataClient, err := metadata.NewMetadataClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Metadata client: %+v", err) + } + configureFunc(metadataClient.Client) - securityMLAnalyticsSettingsClient := securitymlanalyticssettings.NewSecurityMLAnalyticsSettingsClientWithBaseURI(endpoint) - configureAuthFunc(&securityMLAnalyticsSettingsClient.Client) + repositoriesClient, err := repositories.NewRepositoriesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Repositories client: %+v", err) + } + configureFunc(repositoriesClient.Client) - sentinelOnboardingStatesClient := sentinelonboardingstates.NewSentinelOnboardingStatesClientWithBaseURI(endpoint) - configureAuthFunc(&sentinelOnboardingStatesClient.Client) + securityMLAnalyticsSettingsClient, err := securitymlanalyticssettings.NewSecurityMLAnalyticsSettingsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SecurityMLAnalyticsSettings client: %+v", err) + } + configureFunc(securityMLAnalyticsSettingsClient.Client) - sourceControlsClient := sourcecontrols.NewSourceControlsClientWithBaseURI(endpoint) - configureAuthFunc(&sourceControlsClient.Client) + sentinelOnboardingStatesClient, err := sentinelonboardingstates.NewSentinelOnboardingStatesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SentinelOnboardingStates client: %+v", err) + } + configureFunc(sentinelOnboardingStatesClient.Client) - threatIntelligenceClient := threatintelligence.NewThreatIntelligenceClientWithBaseURI(endpoint) - configureAuthFunc(&threatIntelligenceClient.Client) + sourceControlsClient, err := sourcecontrols.NewSourceControlsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SourceControls client: %+v", err) + } + configureFunc(sourceControlsClient.Client) - watchlistItemsClient := watchlistitems.NewWatchlistItemsClientWithBaseURI(endpoint) - configureAuthFunc(&watchlistItemsClient.Client) + threatIntelligenceClient, err := threatintelligence.NewThreatIntelligenceClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ThreatIntelligence client: %+v", err) + } + configureFunc(threatIntelligenceClient.Client) - watchlistsClient := watchlists.NewWatchlistsClientWithBaseURI(endpoint) - configureAuthFunc(&watchlistsClient.Client) + watchlistItemsClient, err := watchlistitems.NewWatchlistItemsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building WatchlistItems client: %+v", err) + } + configureFunc(watchlistItemsClient.Client) - return Client{ - Actions: &actionsClient, - AlertRuleTemplates: &alertRuleTemplatesClient, - AlertRules: &alertRulesClient, - AutomationRules: &automationRulesClient, - Bookmarks: &bookmarksClient, - ContentPackages: &contentPackagesClient, - ContentProductPackages: &contentProductPackagesClient, - ContentProductTemplates: &contentProductTemplatesClient, - ContentTemplates: &contentTemplatesClient, - DataConnectors: &dataConnectorsClient, - EntityTypes: &entityTypesClient, - IncidentAlerts: &incidentAlertsClient, - IncidentBookmarks: &incidentBookmarksClient, - IncidentComments: &incidentCommentsClient, - IncidentEntities: &incidentEntitiesClient, - IncidentRelations: &incidentRelationsClient, - Incidents: &incidentsClient, - Metadata: &metadataClient, - Repositories: &repositoriesClient, - SecurityMLAnalyticsSettings: &securityMLAnalyticsSettingsClient, - SentinelOnboardingStates: &sentinelOnboardingStatesClient, - SourceControls: &sourceControlsClient, - ThreatIntelligence: &threatIntelligenceClient, - WatchlistItems: &watchlistItemsClient, - Watchlists: &watchlistsClient, + watchlistsClient, err := watchlists.NewWatchlistsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Watchlists client: %+v", err) } + configureFunc(watchlistsClient.Client) + + return &Client{ + Actions: actionsClient, + AlertRuleTemplates: alertRuleTemplatesClient, + AlertRules: alertRulesClient, + AutomationRules: automationRulesClient, + Bookmarks: bookmarksClient, + ContentPackages: contentPackagesClient, + ContentProductPackages: contentProductPackagesClient, + ContentProductTemplates: contentProductTemplatesClient, + ContentTemplates: contentTemplatesClient, + DataConnectors: dataConnectorsClient, + EntityTypes: entityTypesClient, + IncidentAlerts: incidentAlertsClient, + IncidentBookmarks: incidentBookmarksClient, + IncidentComments: incidentCommentsClient, + IncidentEntities: incidentEntitiesClient, + IncidentRelations: incidentRelationsClient, + Incidents: incidentsClient, + Metadata: metadataClient, + Repositories: repositoriesClient, + SecurityMLAnalyticsSettings: securityMLAnalyticsSettingsClient, + SentinelOnboardingStates: sentinelOnboardingStatesClient, + SourceControls: sourceControlsClient, + ThreatIntelligence: threatIntelligenceClient, + WatchlistItems: watchlistItemsClient, + Watchlists: watchlistsClient, + }, nil } diff --git a/resource-manager/securityinsights/2023-11-01/contentpackages/client.go b/resource-manager/securityinsights/2023-11-01/contentpackages/client.go index c6421bd4b83..50bba58e93a 100644 --- a/resource-manager/securityinsights/2023-11-01/contentpackages/client.go +++ b/resource-manager/securityinsights/2023-11-01/contentpackages/client.go @@ -1,18 +1,26 @@ package contentpackages -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type ContentPackagesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewContentPackagesClientWithBaseURI(endpoint string) ContentPackagesClient { - return ContentPackagesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewContentPackagesClientWithBaseURI(sdkApi sdkEnv.Api) (*ContentPackagesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "contentpackages", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ContentPackagesClient: %+v", err) } + + return &ContentPackagesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2023-11-01/contentpackages/constants.go b/resource-manager/securityinsights/2023-11-01/contentpackages/constants.go index 56bb2d23bb5..fe7d2b838b2 100644 --- a/resource-manager/securityinsights/2023-11-01/contentpackages/constants.go +++ b/resource-manager/securityinsights/2023-11-01/contentpackages/constants.go @@ -1,6 +1,10 @@ package contentpackages -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -19,6 +23,19 @@ func PossibleValuesForFlag() []string { } } +func (s *Flag) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseFlag(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseFlag(input string) (*Flag, error) { vals := map[string]Flag{ "false": FlagFalse, @@ -77,6 +94,19 @@ func PossibleValuesForKind() []string { } } +func (s *Kind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseKind(input string) (*Kind, error) { vals := map[string]Kind{ "analyticsrule": KindAnalyticsRule, @@ -120,6 +150,19 @@ func PossibleValuesForOperator() []string { } } +func (s *Operator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseOperator(input string) (*Operator, error) { vals := map[string]Operator{ "and": OperatorAND, @@ -148,6 +191,19 @@ func PossibleValuesForPackageKind() []string { } } +func (s *PackageKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePackageKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parsePackageKind(input string) (*PackageKind, error) { vals := map[string]PackageKind{ "solution": PackageKindSolution, @@ -180,6 +236,19 @@ func PossibleValuesForSourceKind() []string { } } +func (s *SourceKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSourceKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSourceKind(input string) (*SourceKind, error) { vals := map[string]SourceKind{ "community": SourceKindCommunity, @@ -212,6 +281,19 @@ func PossibleValuesForSupportTier() []string { } } +func (s *SupportTier) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSupportTier(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSupportTier(input string) (*SupportTier, error) { vals := map[string]SupportTier{ "community": SupportTierCommunity, diff --git a/resource-manager/securityinsights/2023-11-01/contentpackages/method_contentpackageinstall.go b/resource-manager/securityinsights/2023-11-01/contentpackages/method_contentpackageinstall.go new file mode 100644 index 00000000000..bd81583c209 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/contentpackages/method_contentpackageinstall.go @@ -0,0 +1,56 @@ +package contentpackages + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContentPackageInstallOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PackageModel +} + +// ContentPackageInstall ... +func (c ContentPackagesClient) ContentPackageInstall(ctx context.Context, id ContentPackageId, input PackageModel) (result ContentPackageInstallOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/contentpackages/method_contentpackageinstall_autorest.go b/resource-manager/securityinsights/2023-11-01/contentpackages/method_contentpackageinstall_autorest.go deleted file mode 100644 index 4873fff0806..00000000000 --- a/resource-manager/securityinsights/2023-11-01/contentpackages/method_contentpackageinstall_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package contentpackages - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ContentPackageInstallOperationResponse struct { - HttpResponse *http.Response - Model *PackageModel -} - -// ContentPackageInstall ... -func (c ContentPackagesClient) ContentPackageInstall(ctx context.Context, id ContentPackageId, input PackageModel) (result ContentPackageInstallOperationResponse, err error) { - req, err := c.preparerForContentPackageInstall(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "contentpackages.ContentPackagesClient", "ContentPackageInstall", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "contentpackages.ContentPackagesClient", "ContentPackageInstall", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForContentPackageInstall(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "contentpackages.ContentPackagesClient", "ContentPackageInstall", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForContentPackageInstall prepares the ContentPackageInstall request. -func (c ContentPackagesClient) preparerForContentPackageInstall(ctx context.Context, id ContentPackageId, input PackageModel) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForContentPackageInstall handles the response to the ContentPackageInstall request. The method always -// closes the http.Response Body. -func (c ContentPackagesClient) responderForContentPackageInstall(resp *http.Response) (result ContentPackageInstallOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/contentpackages/method_contentpackageuninstall.go b/resource-manager/securityinsights/2023-11-01/contentpackages/method_contentpackageuninstall.go new file mode 100644 index 00000000000..2e8562c793f --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/contentpackages/method_contentpackageuninstall.go @@ -0,0 +1,47 @@ +package contentpackages + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContentPackageUninstallOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// ContentPackageUninstall ... +func (c ContentPackagesClient) ContentPackageUninstall(ctx context.Context, id ContentPackageId) (result ContentPackageUninstallOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/contentpackages/method_contentpackageuninstall_autorest.go b/resource-manager/securityinsights/2023-11-01/contentpackages/method_contentpackageuninstall_autorest.go deleted file mode 100644 index 57fed16a030..00000000000 --- a/resource-manager/securityinsights/2023-11-01/contentpackages/method_contentpackageuninstall_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package contentpackages - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ContentPackageUninstallOperationResponse struct { - HttpResponse *http.Response -} - -// ContentPackageUninstall ... -func (c ContentPackagesClient) ContentPackageUninstall(ctx context.Context, id ContentPackageId) (result ContentPackageUninstallOperationResponse, err error) { - req, err := c.preparerForContentPackageUninstall(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "contentpackages.ContentPackagesClient", "ContentPackageUninstall", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "contentpackages.ContentPackagesClient", "ContentPackageUninstall", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForContentPackageUninstall(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "contentpackages.ContentPackagesClient", "ContentPackageUninstall", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForContentPackageUninstall prepares the ContentPackageUninstall request. -func (c ContentPackagesClient) preparerForContentPackageUninstall(ctx context.Context, id ContentPackageId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForContentPackageUninstall handles the response to the ContentPackageUninstall request. The method always -// closes the http.Response Body. -func (c ContentPackagesClient) responderForContentPackageUninstall(resp *http.Response) (result ContentPackageUninstallOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/contentpackages/method_get.go b/resource-manager/securityinsights/2023-11-01/contentpackages/method_get.go new file mode 100644 index 00000000000..b2afe3492bc --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/contentpackages/method_get.go @@ -0,0 +1,51 @@ +package contentpackages + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PackageModel +} + +// Get ... +func (c ContentPackagesClient) Get(ctx context.Context, id ContentPackageId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/contentpackages/method_get_autorest.go b/resource-manager/securityinsights/2023-11-01/contentpackages/method_get_autorest.go deleted file mode 100644 index 2295de4a7a5..00000000000 --- a/resource-manager/securityinsights/2023-11-01/contentpackages/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package contentpackages - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *PackageModel -} - -// Get ... -func (c ContentPackagesClient) Get(ctx context.Context, id ContentPackageId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "contentpackages.ContentPackagesClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "contentpackages.ContentPackagesClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "contentpackages.ContentPackagesClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c ContentPackagesClient) preparerForGet(ctx context.Context, id ContentPackageId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c ContentPackagesClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/contentpackages/method_list.go b/resource-manager/securityinsights/2023-11-01/contentpackages/method_list.go new file mode 100644 index 00000000000..a3afadbb92b --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/contentpackages/method_list.go @@ -0,0 +1,139 @@ +package contentpackages + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PackageModel +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []PackageModel +} + +type ListOperationOptions struct { + Count *bool + Filter *string + Orderby *string + Search *string + Skip *int64 + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Count != nil { + out.Append("$count", fmt.Sprintf("%v", *o.Count)) + } + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Search != nil { + out.Append("$search", fmt.Sprintf("%v", *o.Search)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c ContentPackagesClient) List(ctx context.Context, id WorkspaceId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/contentPackages", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]PackageModel `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c ContentPackagesClient) ListComplete(ctx context.Context, id WorkspaceId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, PackageModelOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ContentPackagesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ListOperationOptions, predicate PackageModelOperationPredicate) (result ListCompleteResult, err error) { + items := make([]PackageModel, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2023-11-01/contentpackages/method_list_autorest.go b/resource-manager/securityinsights/2023-11-01/contentpackages/method_list_autorest.go deleted file mode 100644 index f77d567c46b..00000000000 --- a/resource-manager/securityinsights/2023-11-01/contentpackages/method_list_autorest.go +++ /dev/null @@ -1,240 +0,0 @@ -package contentpackages - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]PackageModel - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []PackageModel -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ListOperationOptions struct { - Count *bool - Filter *string - Orderby *string - Search *string - Skip *int64 - Top *int64 -} - -func DefaultListOperationOptions() ListOperationOptions { - return ListOperationOptions{} -} - -func (o ListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Count != nil { - out["$count"] = *o.Count - } - - if o.Filter != nil { - out["$filter"] = *o.Filter - } - - if o.Orderby != nil { - out["$orderby"] = *o.Orderby - } - - if o.Search != nil { - out["$search"] = *o.Search - } - - if o.Skip != nil { - out["$skip"] = *o.Skip - } - - if o.Top != nil { - out["$top"] = *o.Top - } - - return out -} - -// List ... -func (c ContentPackagesClient) List(ctx context.Context, id WorkspaceId, options ListOperationOptions) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "contentpackages.ContentPackagesClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "contentpackages.ContentPackagesClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "contentpackages.ContentPackagesClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c ContentPackagesClient) preparerForList(ctx context.Context, id WorkspaceId, options ListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/contentPackages", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c ContentPackagesClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c ContentPackagesClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []PackageModel `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "contentpackages.ContentPackagesClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "contentpackages.ContentPackagesClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "contentpackages.ContentPackagesClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c ContentPackagesClient) ListComplete(ctx context.Context, id WorkspaceId, options ListOperationOptions) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, options, PackageModelOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c ContentPackagesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ListOperationOptions, predicate PackageModelOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]PackageModel, 0) - - page, err := c.List(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2023-11-01/contentproductpackages/client.go b/resource-manager/securityinsights/2023-11-01/contentproductpackages/client.go index 5b951079202..b8bf58ba78d 100644 --- a/resource-manager/securityinsights/2023-11-01/contentproductpackages/client.go +++ b/resource-manager/securityinsights/2023-11-01/contentproductpackages/client.go @@ -1,18 +1,26 @@ package contentproductpackages -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type ContentProductPackagesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewContentProductPackagesClientWithBaseURI(endpoint string) ContentProductPackagesClient { - return ContentProductPackagesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewContentProductPackagesClientWithBaseURI(sdkApi sdkEnv.Api) (*ContentProductPackagesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "contentproductpackages", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ContentProductPackagesClient: %+v", err) } + + return &ContentProductPackagesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2023-11-01/contentproductpackages/constants.go b/resource-manager/securityinsights/2023-11-01/contentproductpackages/constants.go index 3007209b9cb..7b467a13cb0 100644 --- a/resource-manager/securityinsights/2023-11-01/contentproductpackages/constants.go +++ b/resource-manager/securityinsights/2023-11-01/contentproductpackages/constants.go @@ -1,6 +1,10 @@ package contentproductpackages -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -19,6 +23,19 @@ func PossibleValuesForFlag() []string { } } +func (s *Flag) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseFlag(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseFlag(input string) (*Flag, error) { vals := map[string]Flag{ "false": FlagFalse, @@ -77,6 +94,19 @@ func PossibleValuesForKind() []string { } } +func (s *Kind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseKind(input string) (*Kind, error) { vals := map[string]Kind{ "analyticsrule": KindAnalyticsRule, @@ -120,6 +150,19 @@ func PossibleValuesForOperator() []string { } } +func (s *Operator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseOperator(input string) (*Operator, error) { vals := map[string]Operator{ "and": OperatorAND, @@ -148,6 +191,19 @@ func PossibleValuesForPackageKind() []string { } } +func (s *PackageKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePackageKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parsePackageKind(input string) (*PackageKind, error) { vals := map[string]PackageKind{ "solution": PackageKindSolution, @@ -180,6 +236,19 @@ func PossibleValuesForSourceKind() []string { } } +func (s *SourceKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSourceKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSourceKind(input string) (*SourceKind, error) { vals := map[string]SourceKind{ "community": SourceKindCommunity, @@ -212,6 +281,19 @@ func PossibleValuesForSupportTier() []string { } } +func (s *SupportTier) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSupportTier(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSupportTier(input string) (*SupportTier, error) { vals := map[string]SupportTier{ "community": SupportTierCommunity, diff --git a/resource-manager/securityinsights/2023-11-01/contentproductpackages/method_productpackageget.go b/resource-manager/securityinsights/2023-11-01/contentproductpackages/method_productpackageget.go new file mode 100644 index 00000000000..208f21b2d25 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/contentproductpackages/method_productpackageget.go @@ -0,0 +1,51 @@ +package contentproductpackages + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProductPackageGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ProductPackageModel +} + +// ProductPackageGet ... +func (c ContentProductPackagesClient) ProductPackageGet(ctx context.Context, id ContentProductPackageId) (result ProductPackageGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/contentproductpackages/method_productpackageget_autorest.go b/resource-manager/securityinsights/2023-11-01/contentproductpackages/method_productpackageget_autorest.go deleted file mode 100644 index 2eac39e8647..00000000000 --- a/resource-manager/securityinsights/2023-11-01/contentproductpackages/method_productpackageget_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package contentproductpackages - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ProductPackageGetOperationResponse struct { - HttpResponse *http.Response - Model *ProductPackageModel -} - -// ProductPackageGet ... -func (c ContentProductPackagesClient) ProductPackageGet(ctx context.Context, id ContentProductPackageId) (result ProductPackageGetOperationResponse, err error) { - req, err := c.preparerForProductPackageGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "contentproductpackages.ContentProductPackagesClient", "ProductPackageGet", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "contentproductpackages.ContentProductPackagesClient", "ProductPackageGet", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForProductPackageGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "contentproductpackages.ContentProductPackagesClient", "ProductPackageGet", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForProductPackageGet prepares the ProductPackageGet request. -func (c ContentProductPackagesClient) preparerForProductPackageGet(ctx context.Context, id ContentProductPackageId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForProductPackageGet handles the response to the ProductPackageGet request. The method always -// closes the http.Response Body. -func (c ContentProductPackagesClient) responderForProductPackageGet(resp *http.Response) (result ProductPackageGetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/contentproductpackages/method_productpackageslist.go b/resource-manager/securityinsights/2023-11-01/contentproductpackages/method_productpackageslist.go new file mode 100644 index 00000000000..4872e9da727 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/contentproductpackages/method_productpackageslist.go @@ -0,0 +1,127 @@ +package contentproductpackages + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProductPackagesListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ProductPackageModel +} + +type ProductPackagesListCompleteResult struct { + LatestHttpResponse *http.Response + Items []ProductPackageModel +} + +type ProductPackagesListOperationOptions struct { + Filter *string + Orderby *string + Top *int64 +} + +func DefaultProductPackagesListOperationOptions() ProductPackagesListOperationOptions { + return ProductPackagesListOperationOptions{} +} + +func (o ProductPackagesListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ProductPackagesListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ProductPackagesListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ProductPackagesList ... +func (c ContentProductPackagesClient) ProductPackagesList(ctx context.Context, id WorkspaceId, options ProductPackagesListOperationOptions) (result ProductPackagesListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/contentProductPackages", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ProductPackageModel `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ProductPackagesListComplete retrieves all the results into a single object +func (c ContentProductPackagesClient) ProductPackagesListComplete(ctx context.Context, id WorkspaceId, options ProductPackagesListOperationOptions) (ProductPackagesListCompleteResult, error) { + return c.ProductPackagesListCompleteMatchingPredicate(ctx, id, options, ProductPackageModelOperationPredicate{}) +} + +// ProductPackagesListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ContentProductPackagesClient) ProductPackagesListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ProductPackagesListOperationOptions, predicate ProductPackageModelOperationPredicate) (result ProductPackagesListCompleteResult, err error) { + items := make([]ProductPackageModel, 0) + + resp, err := c.ProductPackagesList(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ProductPackagesListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2023-11-01/contentproductpackages/method_productpackageslist_autorest.go b/resource-manager/securityinsights/2023-11-01/contentproductpackages/method_productpackageslist_autorest.go deleted file mode 100644 index 8458b9bec8a..00000000000 --- a/resource-manager/securityinsights/2023-11-01/contentproductpackages/method_productpackageslist_autorest.go +++ /dev/null @@ -1,225 +0,0 @@ -package contentproductpackages - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ProductPackagesListOperationResponse struct { - HttpResponse *http.Response - Model *[]ProductPackageModel - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ProductPackagesListOperationResponse, error) -} - -type ProductPackagesListCompleteResult struct { - Items []ProductPackageModel -} - -func (r ProductPackagesListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ProductPackagesListOperationResponse) LoadMore(ctx context.Context) (resp ProductPackagesListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ProductPackagesListOperationOptions struct { - Filter *string - Orderby *string - Top *int64 -} - -func DefaultProductPackagesListOperationOptions() ProductPackagesListOperationOptions { - return ProductPackagesListOperationOptions{} -} - -func (o ProductPackagesListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ProductPackagesListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Filter != nil { - out["$filter"] = *o.Filter - } - - if o.Orderby != nil { - out["$orderby"] = *o.Orderby - } - - if o.Top != nil { - out["$top"] = *o.Top - } - - return out -} - -// ProductPackagesList ... -func (c ContentProductPackagesClient) ProductPackagesList(ctx context.Context, id WorkspaceId, options ProductPackagesListOperationOptions) (resp ProductPackagesListOperationResponse, err error) { - req, err := c.preparerForProductPackagesList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "contentproductpackages.ContentProductPackagesClient", "ProductPackagesList", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "contentproductpackages.ContentProductPackagesClient", "ProductPackagesList", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForProductPackagesList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "contentproductpackages.ContentProductPackagesClient", "ProductPackagesList", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForProductPackagesList prepares the ProductPackagesList request. -func (c ContentProductPackagesClient) preparerForProductPackagesList(ctx context.Context, id WorkspaceId, options ProductPackagesListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/contentProductPackages", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForProductPackagesListWithNextLink prepares the ProductPackagesList request with the given nextLink token. -func (c ContentProductPackagesClient) preparerForProductPackagesListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForProductPackagesList handles the response to the ProductPackagesList request. The method always -// closes the http.Response Body. -func (c ContentProductPackagesClient) responderForProductPackagesList(resp *http.Response) (result ProductPackagesListOperationResponse, err error) { - type page struct { - Values []ProductPackageModel `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ProductPackagesListOperationResponse, err error) { - req, err := c.preparerForProductPackagesListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "contentproductpackages.ContentProductPackagesClient", "ProductPackagesList", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "contentproductpackages.ContentProductPackagesClient", "ProductPackagesList", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForProductPackagesList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "contentproductpackages.ContentProductPackagesClient", "ProductPackagesList", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ProductPackagesListComplete retrieves all of the results into a single object -func (c ContentProductPackagesClient) ProductPackagesListComplete(ctx context.Context, id WorkspaceId, options ProductPackagesListOperationOptions) (ProductPackagesListCompleteResult, error) { - return c.ProductPackagesListCompleteMatchingPredicate(ctx, id, options, ProductPackageModelOperationPredicate{}) -} - -// ProductPackagesListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c ContentProductPackagesClient) ProductPackagesListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ProductPackagesListOperationOptions, predicate ProductPackageModelOperationPredicate) (resp ProductPackagesListCompleteResult, err error) { - items := make([]ProductPackageModel, 0) - - page, err := c.ProductPackagesList(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ProductPackagesListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2023-11-01/contentproducttemplates/client.go b/resource-manager/securityinsights/2023-11-01/contentproducttemplates/client.go index 1e2671672e4..26a626b34ce 100644 --- a/resource-manager/securityinsights/2023-11-01/contentproducttemplates/client.go +++ b/resource-manager/securityinsights/2023-11-01/contentproducttemplates/client.go @@ -1,18 +1,26 @@ package contentproducttemplates -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type ContentProductTemplatesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewContentProductTemplatesClientWithBaseURI(endpoint string) ContentProductTemplatesClient { - return ContentProductTemplatesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewContentProductTemplatesClientWithBaseURI(sdkApi sdkEnv.Api) (*ContentProductTemplatesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "contentproducttemplates", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ContentProductTemplatesClient: %+v", err) } + + return &ContentProductTemplatesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2023-11-01/contentproducttemplates/constants.go b/resource-manager/securityinsights/2023-11-01/contentproducttemplates/constants.go index dfd25d5c2a1..d6dbec0d517 100644 --- a/resource-manager/securityinsights/2023-11-01/contentproducttemplates/constants.go +++ b/resource-manager/securityinsights/2023-11-01/contentproducttemplates/constants.go @@ -1,6 +1,10 @@ package contentproducttemplates -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -19,6 +23,19 @@ func PossibleValuesForFlag() []string { } } +func (s *Flag) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseFlag(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseFlag(input string) (*Flag, error) { vals := map[string]Flag{ "false": FlagFalse, @@ -77,6 +94,19 @@ func PossibleValuesForKind() []string { } } +func (s *Kind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseKind(input string) (*Kind, error) { vals := map[string]Kind{ "analyticsrule": KindAnalyticsRule, @@ -120,6 +150,19 @@ func PossibleValuesForOperator() []string { } } +func (s *Operator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseOperator(input string) (*Operator, error) { vals := map[string]Operator{ "and": OperatorAND, @@ -148,6 +191,19 @@ func PossibleValuesForPackageKind() []string { } } +func (s *PackageKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePackageKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parsePackageKind(input string) (*PackageKind, error) { vals := map[string]PackageKind{ "solution": PackageKindSolution, @@ -180,6 +236,19 @@ func PossibleValuesForSourceKind() []string { } } +func (s *SourceKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSourceKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSourceKind(input string) (*SourceKind, error) { vals := map[string]SourceKind{ "community": SourceKindCommunity, @@ -212,6 +281,19 @@ func PossibleValuesForSupportTier() []string { } } +func (s *SupportTier) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSupportTier(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSupportTier(input string) (*SupportTier, error) { vals := map[string]SupportTier{ "community": SupportTierCommunity, diff --git a/resource-manager/securityinsights/2023-11-01/contentproducttemplates/method_producttemplateget.go b/resource-manager/securityinsights/2023-11-01/contentproducttemplates/method_producttemplateget.go new file mode 100644 index 00000000000..dad6eb309ff --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/contentproducttemplates/method_producttemplateget.go @@ -0,0 +1,51 @@ +package contentproducttemplates + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProductTemplateGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ProductTemplateModel +} + +// ProductTemplateGet ... +func (c ContentProductTemplatesClient) ProductTemplateGet(ctx context.Context, id ContentproducttemplateId) (result ProductTemplateGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/contentproducttemplates/method_producttemplateget_autorest.go b/resource-manager/securityinsights/2023-11-01/contentproducttemplates/method_producttemplateget_autorest.go deleted file mode 100644 index 3054d6161a3..00000000000 --- a/resource-manager/securityinsights/2023-11-01/contentproducttemplates/method_producttemplateget_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package contentproducttemplates - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ProductTemplateGetOperationResponse struct { - HttpResponse *http.Response - Model *ProductTemplateModel -} - -// ProductTemplateGet ... -func (c ContentProductTemplatesClient) ProductTemplateGet(ctx context.Context, id ContentproducttemplateId) (result ProductTemplateGetOperationResponse, err error) { - req, err := c.preparerForProductTemplateGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "contentproducttemplates.ContentProductTemplatesClient", "ProductTemplateGet", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "contentproducttemplates.ContentProductTemplatesClient", "ProductTemplateGet", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForProductTemplateGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "contentproducttemplates.ContentProductTemplatesClient", "ProductTemplateGet", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForProductTemplateGet prepares the ProductTemplateGet request. -func (c ContentProductTemplatesClient) preparerForProductTemplateGet(ctx context.Context, id ContentproducttemplateId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForProductTemplateGet handles the response to the ProductTemplateGet request. The method always -// closes the http.Response Body. -func (c ContentProductTemplatesClient) responderForProductTemplateGet(resp *http.Response) (result ProductTemplateGetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/contentproducttemplates/method_producttemplateslist.go b/resource-manager/securityinsights/2023-11-01/contentproducttemplates/method_producttemplateslist.go new file mode 100644 index 00000000000..185c273489e --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/contentproducttemplates/method_producttemplateslist.go @@ -0,0 +1,139 @@ +package contentproducttemplates + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProductTemplatesListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ProductTemplateModel +} + +type ProductTemplatesListCompleteResult struct { + LatestHttpResponse *http.Response + Items []ProductTemplateModel +} + +type ProductTemplatesListOperationOptions struct { + Count *bool + Filter *string + Orderby *string + Search *string + Skip *int64 + Top *int64 +} + +func DefaultProductTemplatesListOperationOptions() ProductTemplatesListOperationOptions { + return ProductTemplatesListOperationOptions{} +} + +func (o ProductTemplatesListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ProductTemplatesListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ProductTemplatesListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Count != nil { + out.Append("$count", fmt.Sprintf("%v", *o.Count)) + } + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Search != nil { + out.Append("$search", fmt.Sprintf("%v", *o.Search)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ProductTemplatesList ... +func (c ContentProductTemplatesClient) ProductTemplatesList(ctx context.Context, id WorkspaceId, options ProductTemplatesListOperationOptions) (result ProductTemplatesListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/contentProductTemplates", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ProductTemplateModel `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ProductTemplatesListComplete retrieves all the results into a single object +func (c ContentProductTemplatesClient) ProductTemplatesListComplete(ctx context.Context, id WorkspaceId, options ProductTemplatesListOperationOptions) (ProductTemplatesListCompleteResult, error) { + return c.ProductTemplatesListCompleteMatchingPredicate(ctx, id, options, ProductTemplateModelOperationPredicate{}) +} + +// ProductTemplatesListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ContentProductTemplatesClient) ProductTemplatesListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ProductTemplatesListOperationOptions, predicate ProductTemplateModelOperationPredicate) (result ProductTemplatesListCompleteResult, err error) { + items := make([]ProductTemplateModel, 0) + + resp, err := c.ProductTemplatesList(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ProductTemplatesListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2023-11-01/contentproducttemplates/method_producttemplateslist_autorest.go b/resource-manager/securityinsights/2023-11-01/contentproducttemplates/method_producttemplateslist_autorest.go deleted file mode 100644 index b7afab27e41..00000000000 --- a/resource-manager/securityinsights/2023-11-01/contentproducttemplates/method_producttemplateslist_autorest.go +++ /dev/null @@ -1,240 +0,0 @@ -package contentproducttemplates - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ProductTemplatesListOperationResponse struct { - HttpResponse *http.Response - Model *[]ProductTemplateModel - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ProductTemplatesListOperationResponse, error) -} - -type ProductTemplatesListCompleteResult struct { - Items []ProductTemplateModel -} - -func (r ProductTemplatesListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ProductTemplatesListOperationResponse) LoadMore(ctx context.Context) (resp ProductTemplatesListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ProductTemplatesListOperationOptions struct { - Count *bool - Filter *string - Orderby *string - Search *string - Skip *int64 - Top *int64 -} - -func DefaultProductTemplatesListOperationOptions() ProductTemplatesListOperationOptions { - return ProductTemplatesListOperationOptions{} -} - -func (o ProductTemplatesListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ProductTemplatesListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Count != nil { - out["$count"] = *o.Count - } - - if o.Filter != nil { - out["$filter"] = *o.Filter - } - - if o.Orderby != nil { - out["$orderby"] = *o.Orderby - } - - if o.Search != nil { - out["$search"] = *o.Search - } - - if o.Skip != nil { - out["$skip"] = *o.Skip - } - - if o.Top != nil { - out["$top"] = *o.Top - } - - return out -} - -// ProductTemplatesList ... -func (c ContentProductTemplatesClient) ProductTemplatesList(ctx context.Context, id WorkspaceId, options ProductTemplatesListOperationOptions) (resp ProductTemplatesListOperationResponse, err error) { - req, err := c.preparerForProductTemplatesList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "contentproducttemplates.ContentProductTemplatesClient", "ProductTemplatesList", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "contentproducttemplates.ContentProductTemplatesClient", "ProductTemplatesList", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForProductTemplatesList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "contentproducttemplates.ContentProductTemplatesClient", "ProductTemplatesList", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForProductTemplatesList prepares the ProductTemplatesList request. -func (c ContentProductTemplatesClient) preparerForProductTemplatesList(ctx context.Context, id WorkspaceId, options ProductTemplatesListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/contentProductTemplates", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForProductTemplatesListWithNextLink prepares the ProductTemplatesList request with the given nextLink token. -func (c ContentProductTemplatesClient) preparerForProductTemplatesListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForProductTemplatesList handles the response to the ProductTemplatesList request. The method always -// closes the http.Response Body. -func (c ContentProductTemplatesClient) responderForProductTemplatesList(resp *http.Response) (result ProductTemplatesListOperationResponse, err error) { - type page struct { - Values []ProductTemplateModel `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ProductTemplatesListOperationResponse, err error) { - req, err := c.preparerForProductTemplatesListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "contentproducttemplates.ContentProductTemplatesClient", "ProductTemplatesList", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "contentproducttemplates.ContentProductTemplatesClient", "ProductTemplatesList", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForProductTemplatesList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "contentproducttemplates.ContentProductTemplatesClient", "ProductTemplatesList", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ProductTemplatesListComplete retrieves all of the results into a single object -func (c ContentProductTemplatesClient) ProductTemplatesListComplete(ctx context.Context, id WorkspaceId, options ProductTemplatesListOperationOptions) (ProductTemplatesListCompleteResult, error) { - return c.ProductTemplatesListCompleteMatchingPredicate(ctx, id, options, ProductTemplateModelOperationPredicate{}) -} - -// ProductTemplatesListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c ContentProductTemplatesClient) ProductTemplatesListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ProductTemplatesListOperationOptions, predicate ProductTemplateModelOperationPredicate) (resp ProductTemplatesListCompleteResult, err error) { - items := make([]ProductTemplateModel, 0) - - page, err := c.ProductTemplatesList(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ProductTemplatesListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2023-11-01/contenttemplates/client.go b/resource-manager/securityinsights/2023-11-01/contenttemplates/client.go index 5acbd28411c..fde41e740cd 100644 --- a/resource-manager/securityinsights/2023-11-01/contenttemplates/client.go +++ b/resource-manager/securityinsights/2023-11-01/contenttemplates/client.go @@ -1,18 +1,26 @@ package contenttemplates -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type ContentTemplatesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewContentTemplatesClientWithBaseURI(endpoint string) ContentTemplatesClient { - return ContentTemplatesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewContentTemplatesClientWithBaseURI(sdkApi sdkEnv.Api) (*ContentTemplatesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "contenttemplates", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ContentTemplatesClient: %+v", err) } + + return &ContentTemplatesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2023-11-01/contenttemplates/constants.go b/resource-manager/securityinsights/2023-11-01/contenttemplates/constants.go index 52ba685da25..87c95f8bbbd 100644 --- a/resource-manager/securityinsights/2023-11-01/contenttemplates/constants.go +++ b/resource-manager/securityinsights/2023-11-01/contenttemplates/constants.go @@ -1,6 +1,10 @@ package contenttemplates -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -19,6 +23,19 @@ func PossibleValuesForFlag() []string { } } +func (s *Flag) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseFlag(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseFlag(input string) (*Flag, error) { vals := map[string]Flag{ "false": FlagFalse, @@ -77,6 +94,19 @@ func PossibleValuesForKind() []string { } } +func (s *Kind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseKind(input string) (*Kind, error) { vals := map[string]Kind{ "analyticsrule": KindAnalyticsRule, @@ -120,6 +150,19 @@ func PossibleValuesForOperator() []string { } } +func (s *Operator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseOperator(input string) (*Operator, error) { vals := map[string]Operator{ "and": OperatorAND, @@ -148,6 +191,19 @@ func PossibleValuesForPackageKind() []string { } } +func (s *PackageKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePackageKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parsePackageKind(input string) (*PackageKind, error) { vals := map[string]PackageKind{ "solution": PackageKindSolution, @@ -180,6 +236,19 @@ func PossibleValuesForSourceKind() []string { } } +func (s *SourceKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSourceKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSourceKind(input string) (*SourceKind, error) { vals := map[string]SourceKind{ "community": SourceKindCommunity, @@ -212,6 +281,19 @@ func PossibleValuesForSupportTier() []string { } } +func (s *SupportTier) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSupportTier(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSupportTier(input string) (*SupportTier, error) { vals := map[string]SupportTier{ "community": SupportTierCommunity, diff --git a/resource-manager/securityinsights/2023-11-01/contenttemplates/method_contenttemplatedelete.go b/resource-manager/securityinsights/2023-11-01/contenttemplates/method_contenttemplatedelete.go new file mode 100644 index 00000000000..efbfcdae5c7 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/contenttemplates/method_contenttemplatedelete.go @@ -0,0 +1,47 @@ +package contenttemplates + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContentTemplateDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// ContentTemplateDelete ... +func (c ContentTemplatesClient) ContentTemplateDelete(ctx context.Context, id ContentTemplateId) (result ContentTemplateDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/contenttemplates/method_contenttemplatedelete_autorest.go b/resource-manager/securityinsights/2023-11-01/contenttemplates/method_contenttemplatedelete_autorest.go deleted file mode 100644 index 802c2771497..00000000000 --- a/resource-manager/securityinsights/2023-11-01/contenttemplates/method_contenttemplatedelete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package contenttemplates - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ContentTemplateDeleteOperationResponse struct { - HttpResponse *http.Response -} - -// ContentTemplateDelete ... -func (c ContentTemplatesClient) ContentTemplateDelete(ctx context.Context, id ContentTemplateId) (result ContentTemplateDeleteOperationResponse, err error) { - req, err := c.preparerForContentTemplateDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "contenttemplates.ContentTemplatesClient", "ContentTemplateDelete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "contenttemplates.ContentTemplatesClient", "ContentTemplateDelete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForContentTemplateDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "contenttemplates.ContentTemplatesClient", "ContentTemplateDelete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForContentTemplateDelete prepares the ContentTemplateDelete request. -func (c ContentTemplatesClient) preparerForContentTemplateDelete(ctx context.Context, id ContentTemplateId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForContentTemplateDelete handles the response to the ContentTemplateDelete request. The method always -// closes the http.Response Body. -func (c ContentTemplatesClient) responderForContentTemplateDelete(resp *http.Response) (result ContentTemplateDeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/contenttemplates/method_contenttemplateget.go b/resource-manager/securityinsights/2023-11-01/contenttemplates/method_contenttemplateget.go new file mode 100644 index 00000000000..b6e23b79512 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/contenttemplates/method_contenttemplateget.go @@ -0,0 +1,51 @@ +package contenttemplates + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContentTemplateGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *TemplateModel +} + +// ContentTemplateGet ... +func (c ContentTemplatesClient) ContentTemplateGet(ctx context.Context, id ContentTemplateId) (result ContentTemplateGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/contenttemplates/method_contenttemplateget_autorest.go b/resource-manager/securityinsights/2023-11-01/contenttemplates/method_contenttemplateget_autorest.go deleted file mode 100644 index b15870c1793..00000000000 --- a/resource-manager/securityinsights/2023-11-01/contenttemplates/method_contenttemplateget_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package contenttemplates - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ContentTemplateGetOperationResponse struct { - HttpResponse *http.Response - Model *TemplateModel -} - -// ContentTemplateGet ... -func (c ContentTemplatesClient) ContentTemplateGet(ctx context.Context, id ContentTemplateId) (result ContentTemplateGetOperationResponse, err error) { - req, err := c.preparerForContentTemplateGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "contenttemplates.ContentTemplatesClient", "ContentTemplateGet", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "contenttemplates.ContentTemplatesClient", "ContentTemplateGet", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForContentTemplateGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "contenttemplates.ContentTemplatesClient", "ContentTemplateGet", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForContentTemplateGet prepares the ContentTemplateGet request. -func (c ContentTemplatesClient) preparerForContentTemplateGet(ctx context.Context, id ContentTemplateId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForContentTemplateGet handles the response to the ContentTemplateGet request. The method always -// closes the http.Response Body. -func (c ContentTemplatesClient) responderForContentTemplateGet(resp *http.Response) (result ContentTemplateGetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/contenttemplates/method_contenttemplateinstall.go b/resource-manager/securityinsights/2023-11-01/contenttemplates/method_contenttemplateinstall.go new file mode 100644 index 00000000000..21434c54fa1 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/contenttemplates/method_contenttemplateinstall.go @@ -0,0 +1,56 @@ +package contenttemplates + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContentTemplateInstallOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *TemplateModel +} + +// ContentTemplateInstall ... +func (c ContentTemplatesClient) ContentTemplateInstall(ctx context.Context, id ContentTemplateId, input TemplateModel) (result ContentTemplateInstallOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/contenttemplates/method_contenttemplateinstall_autorest.go b/resource-manager/securityinsights/2023-11-01/contenttemplates/method_contenttemplateinstall_autorest.go deleted file mode 100644 index 0a9040f4eea..00000000000 --- a/resource-manager/securityinsights/2023-11-01/contenttemplates/method_contenttemplateinstall_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package contenttemplates - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ContentTemplateInstallOperationResponse struct { - HttpResponse *http.Response - Model *TemplateModel -} - -// ContentTemplateInstall ... -func (c ContentTemplatesClient) ContentTemplateInstall(ctx context.Context, id ContentTemplateId, input TemplateModel) (result ContentTemplateInstallOperationResponse, err error) { - req, err := c.preparerForContentTemplateInstall(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "contenttemplates.ContentTemplatesClient", "ContentTemplateInstall", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "contenttemplates.ContentTemplatesClient", "ContentTemplateInstall", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForContentTemplateInstall(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "contenttemplates.ContentTemplatesClient", "ContentTemplateInstall", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForContentTemplateInstall prepares the ContentTemplateInstall request. -func (c ContentTemplatesClient) preparerForContentTemplateInstall(ctx context.Context, id ContentTemplateId, input TemplateModel) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForContentTemplateInstall handles the response to the ContentTemplateInstall request. The method always -// closes the http.Response Body. -func (c ContentTemplatesClient) responderForContentTemplateInstall(resp *http.Response) (result ContentTemplateInstallOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/contenttemplates/method_list.go b/resource-manager/securityinsights/2023-11-01/contenttemplates/method_list.go new file mode 100644 index 00000000000..f254d04210a --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/contenttemplates/method_list.go @@ -0,0 +1,143 @@ +package contenttemplates + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]TemplateModel +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []TemplateModel +} + +type ListOperationOptions struct { + Count *bool + Expand *string + Filter *string + Orderby *string + Search *string + Skip *int64 + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Count != nil { + out.Append("$count", fmt.Sprintf("%v", *o.Count)) + } + if o.Expand != nil { + out.Append("$expand", fmt.Sprintf("%v", *o.Expand)) + } + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Search != nil { + out.Append("$search", fmt.Sprintf("%v", *o.Search)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c ContentTemplatesClient) List(ctx context.Context, id WorkspaceId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/contentTemplates", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]TemplateModel `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c ContentTemplatesClient) ListComplete(ctx context.Context, id WorkspaceId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, TemplateModelOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ContentTemplatesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ListOperationOptions, predicate TemplateModelOperationPredicate) (result ListCompleteResult, err error) { + items := make([]TemplateModel, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2023-11-01/contenttemplates/method_list_autorest.go b/resource-manager/securityinsights/2023-11-01/contenttemplates/method_list_autorest.go deleted file mode 100644 index b03ea05d736..00000000000 --- a/resource-manager/securityinsights/2023-11-01/contenttemplates/method_list_autorest.go +++ /dev/null @@ -1,245 +0,0 @@ -package contenttemplates - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]TemplateModel - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []TemplateModel -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ListOperationOptions struct { - Count *bool - Expand *string - Filter *string - Orderby *string - Search *string - Skip *int64 - Top *int64 -} - -func DefaultListOperationOptions() ListOperationOptions { - return ListOperationOptions{} -} - -func (o ListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Count != nil { - out["$count"] = *o.Count - } - - if o.Expand != nil { - out["$expand"] = *o.Expand - } - - if o.Filter != nil { - out["$filter"] = *o.Filter - } - - if o.Orderby != nil { - out["$orderby"] = *o.Orderby - } - - if o.Search != nil { - out["$search"] = *o.Search - } - - if o.Skip != nil { - out["$skip"] = *o.Skip - } - - if o.Top != nil { - out["$top"] = *o.Top - } - - return out -} - -// List ... -func (c ContentTemplatesClient) List(ctx context.Context, id WorkspaceId, options ListOperationOptions) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "contenttemplates.ContentTemplatesClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "contenttemplates.ContentTemplatesClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "contenttemplates.ContentTemplatesClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c ContentTemplatesClient) preparerForList(ctx context.Context, id WorkspaceId, options ListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/contentTemplates", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c ContentTemplatesClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c ContentTemplatesClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []TemplateModel `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "contenttemplates.ContentTemplatesClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "contenttemplates.ContentTemplatesClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "contenttemplates.ContentTemplatesClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c ContentTemplatesClient) ListComplete(ctx context.Context, id WorkspaceId, options ListOperationOptions) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, options, TemplateModelOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c ContentTemplatesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ListOperationOptions, predicate TemplateModelOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]TemplateModel, 0) - - page, err := c.List(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2023-11-01/dataconnectors/client.go b/resource-manager/securityinsights/2023-11-01/dataconnectors/client.go index cf334b72568..8ed0120c79a 100644 --- a/resource-manager/securityinsights/2023-11-01/dataconnectors/client.go +++ b/resource-manager/securityinsights/2023-11-01/dataconnectors/client.go @@ -1,18 +1,26 @@ package dataconnectors -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type DataConnectorsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewDataConnectorsClientWithBaseURI(endpoint string) DataConnectorsClient { - return DataConnectorsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewDataConnectorsClientWithBaseURI(sdkApi sdkEnv.Api) (*DataConnectorsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "dataconnectors", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DataConnectorsClient: %+v", err) } + + return &DataConnectorsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2023-11-01/dataconnectors/constants.go b/resource-manager/securityinsights/2023-11-01/dataconnectors/constants.go index db98dc83577..3fb78689b33 100644 --- a/resource-manager/securityinsights/2023-11-01/dataconnectors/constants.go +++ b/resource-manager/securityinsights/2023-11-01/dataconnectors/constants.go @@ -1,6 +1,10 @@ package dataconnectors -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -31,6 +35,19 @@ func PossibleValuesForDataConnectorKind() []string { } } +func (s *DataConnectorKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataConnectorKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDataConnectorKind(input string) (*DataConnectorKind, error) { vals := map[string]DataConnectorKind{ "amazonwebservicescloudtrail": DataConnectorKindAmazonWebServicesCloudTrail, @@ -65,6 +82,19 @@ func PossibleValuesForDataTypeState() []string { } } +func (s *DataTypeState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataTypeState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDataTypeState(input string) (*DataTypeState, error) { vals := map[string]DataTypeState{ "disabled": DataTypeStateDisabled, diff --git a/resource-manager/securityinsights/2023-11-01/dataconnectors/method_createorupdate.go b/resource-manager/securityinsights/2023-11-01/dataconnectors/method_createorupdate.go new file mode 100644 index 00000000000..c5f6e5d1503 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/dataconnectors/method_createorupdate.go @@ -0,0 +1,63 @@ +package dataconnectors + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DataConnector +} + +// CreateOrUpdate ... +func (c DataConnectorsClient) CreateOrUpdate(ctx context.Context, id DataConnectorId, input DataConnector) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalDataConnectorImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/dataconnectors/method_createorupdate_autorest.go b/resource-manager/securityinsights/2023-11-01/dataconnectors/method_createorupdate_autorest.go deleted file mode 100644 index 1f259eca36c..00000000000 --- a/resource-manager/securityinsights/2023-11-01/dataconnectors/method_createorupdate_autorest.go +++ /dev/null @@ -1,78 +0,0 @@ -package dataconnectors - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *DataConnector -} - -// CreateOrUpdate ... -func (c DataConnectorsClient) CreateOrUpdate(ctx context.Context, id DataConnectorId, input DataConnector) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c DataConnectorsClient) preparerForCreateOrUpdate(ctx context.Context, id DataConnectorId, input DataConnector) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c DataConnectorsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalDataConnectorImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2023-11-01/dataconnectors/method_delete.go b/resource-manager/securityinsights/2023-11-01/dataconnectors/method_delete.go new file mode 100644 index 00000000000..8461ec6d8a1 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/dataconnectors/method_delete.go @@ -0,0 +1,47 @@ +package dataconnectors + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c DataConnectorsClient) Delete(ctx context.Context, id DataConnectorId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/dataconnectors/method_delete_autorest.go b/resource-manager/securityinsights/2023-11-01/dataconnectors/method_delete_autorest.go deleted file mode 100644 index ac4ddf57441..00000000000 --- a/resource-manager/securityinsights/2023-11-01/dataconnectors/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package dataconnectors - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c DataConnectorsClient) Delete(ctx context.Context, id DataConnectorId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c DataConnectorsClient) preparerForDelete(ctx context.Context, id DataConnectorId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c DataConnectorsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/dataconnectors/method_get.go b/resource-manager/securityinsights/2023-11-01/dataconnectors/method_get.go new file mode 100644 index 00000000000..3511ba85477 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/dataconnectors/method_get.go @@ -0,0 +1,58 @@ +package dataconnectors + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DataConnector +} + +// Get ... +func (c DataConnectorsClient) Get(ctx context.Context, id DataConnectorId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalDataConnectorImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/dataconnectors/method_get_autorest.go b/resource-manager/securityinsights/2023-11-01/dataconnectors/method_get_autorest.go deleted file mode 100644 index af56be19c9c..00000000000 --- a/resource-manager/securityinsights/2023-11-01/dataconnectors/method_get_autorest.go +++ /dev/null @@ -1,77 +0,0 @@ -package dataconnectors - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *DataConnector -} - -// Get ... -func (c DataConnectorsClient) Get(ctx context.Context, id DataConnectorId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c DataConnectorsClient) preparerForGet(ctx context.Context, id DataConnectorId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c DataConnectorsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalDataConnectorImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2023-11-01/dataconnectors/method_list.go b/resource-manager/securityinsights/2023-11-01/dataconnectors/method_list.go new file mode 100644 index 00000000000..6975384fdee --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/dataconnectors/method_list.go @@ -0,0 +1,103 @@ +package dataconnectors + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DataConnector +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []DataConnector +} + +// List ... +func (c DataConnectorsClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/dataConnectors", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]DataConnector, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalDataConnectorImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for DataConnector (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// ListComplete retrieves all the results into a single object +func (c DataConnectorsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, DataConnectorOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DataConnectorsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate DataConnectorOperationPredicate) (result ListCompleteResult, err error) { + items := make([]DataConnector, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2023-11-01/dataconnectors/method_list_autorest.go b/resource-manager/securityinsights/2023-11-01/dataconnectors/method_list_autorest.go deleted file mode 100644 index e08d153a6eb..00000000000 --- a/resource-manager/securityinsights/2023-11-01/dataconnectors/method_list_autorest.go +++ /dev/null @@ -1,196 +0,0 @@ -package dataconnectors - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]DataConnector - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []DataConnector -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c DataConnectorsClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c DataConnectorsClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/dataConnectors", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c DataConnectorsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c DataConnectorsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]DataConnector, 0) - for i, v := range respObj.Values { - val, err := unmarshalDataConnectorImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for DataConnector (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "dataconnectors.DataConnectorsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c DataConnectorsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, DataConnectorOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c DataConnectorsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate DataConnectorOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]DataConnector, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2023-11-01/entitytypes/client.go b/resource-manager/securityinsights/2023-11-01/entitytypes/client.go index 60583ea834f..bcdd09e4029 100644 --- a/resource-manager/securityinsights/2023-11-01/entitytypes/client.go +++ b/resource-manager/securityinsights/2023-11-01/entitytypes/client.go @@ -1,18 +1,26 @@ package entitytypes -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type EntityTypesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewEntityTypesClientWithBaseURI(endpoint string) EntityTypesClient { - return EntityTypesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewEntityTypesClientWithBaseURI(sdkApi sdkEnv.Api) (*EntityTypesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "entitytypes", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating EntityTypesClient: %+v", err) } + + return &EntityTypesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2023-11-01/entitytypes/constants.go b/resource-manager/securityinsights/2023-11-01/entitytypes/constants.go index fbe60ce0f02..2f194a6f29d 100644 --- a/resource-manager/securityinsights/2023-11-01/entitytypes/constants.go +++ b/resource-manager/securityinsights/2023-11-01/entitytypes/constants.go @@ -1,6 +1,10 @@ package entitytypes -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -23,6 +27,19 @@ func PossibleValuesForAlertSeverity() []string { } } +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertSeverity(input string) (*AlertSeverity, error) { vals := map[string]AlertSeverity{ "high": AlertSeverityHigh, @@ -59,6 +76,19 @@ func PossibleValuesForAlertStatus() []string { } } +func (s *AlertStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertStatus(input string) (*AlertStatus, error) { vals := map[string]AlertStatus{ "dismissed": AlertStatusDismissed, @@ -94,6 +124,19 @@ func PossibleValuesForAntispamMailDirection() []string { } } +func (s *AntispamMailDirection) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAntispamMailDirection(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAntispamMailDirection(input string) (*AntispamMailDirection, error) { vals := map[string]AntispamMailDirection{ "inbound": AntispamMailDirectionInbound, @@ -154,6 +197,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -199,6 +255,19 @@ func PossibleValuesForConfidenceLevel() []string { } } +func (s *ConfidenceLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceLevel(input string) (*ConfidenceLevel, error) { vals := map[string]ConfidenceLevel{ "high": ConfidenceLevelHigh, @@ -232,6 +301,19 @@ func PossibleValuesForConfidenceScoreStatus() []string { } } +func (s *ConfidenceScoreStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceScoreStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceScoreStatus(input string) (*ConfidenceScoreStatus, error) { vals := map[string]ConfidenceScoreStatus{ "final": ConfidenceScoreStatusFinal, @@ -266,6 +348,19 @@ func PossibleValuesForCreatedByType() []string { } } +func (s *CreatedByType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCreatedByType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseCreatedByType(input string) (*CreatedByType, error) { vals := map[string]CreatedByType{ "application": CreatedByTypeApplication, @@ -302,6 +397,19 @@ func PossibleValuesForDeliveryAction() []string { } } +func (s *DeliveryAction) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeliveryAction(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDeliveryAction(input string) (*DeliveryAction, error) { vals := map[string]DeliveryAction{ "blocked": DeliveryActionBlocked, @@ -347,6 +455,19 @@ func PossibleValuesForDeliveryLocation() []string { } } +func (s *DeliveryLocation) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeliveryLocation(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDeliveryLocation(input string) (*DeliveryLocation, error) { vals := map[string]DeliveryLocation{ "deletedfolder": DeliveryLocationDeletedFolder, @@ -384,6 +505,19 @@ func PossibleValuesForElevationToken() []string { } } +func (s *ElevationToken) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseElevationToken(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseElevationToken(input string) (*ElevationToken, error) { vals := map[string]ElevationToken{ "default": ElevationTokenDefault, @@ -451,6 +585,19 @@ func PossibleValuesForEntityKindEnum() []string { } } +func (s *EntityKindEnum) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityKindEnum(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityKindEnum(input string) (*EntityKindEnum, error) { vals := map[string]EntityKindEnum{ "account": EntityKindEnumAccount, @@ -504,6 +651,19 @@ func PossibleValuesForFileHashAlgorithm() []string { } } +func (s *FileHashAlgorithm) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseFileHashAlgorithm(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseFileHashAlgorithm(input string) (*FileHashAlgorithm, error) { vals := map[string]FileHashAlgorithm{ "md5": FileHashAlgorithmMDFive, @@ -539,6 +699,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, @@ -593,6 +766,19 @@ func PossibleValuesForKillChainIntent() []string { } } +func (s *KillChainIntent) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKillChainIntent(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseKillChainIntent(input string) (*KillChainIntent, error) { vals := map[string]KillChainIntent{ "collection": KillChainIntentCollection, @@ -639,6 +825,19 @@ func PossibleValuesForOSFamily() []string { } } +func (s *OSFamily) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOSFamily(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseOSFamily(input string) (*OSFamily, error) { vals := map[string]OSFamily{ "android": OSFamilyAndroid, @@ -686,6 +885,19 @@ func PossibleValuesForRegistryHive() []string { } } +func (s *RegistryHive) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRegistryHive(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseRegistryHive(input string) (*RegistryHive, error) { vals := map[string]RegistryHive{ "hkey_a": RegistryHiveHKEYA, @@ -734,6 +946,19 @@ func PossibleValuesForRegistryValueKind() []string { } } +func (s *RegistryValueKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRegistryValueKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseRegistryValueKind(input string) (*RegistryValueKind, error) { vals := map[string]RegistryValueKind{ "binary": RegistryValueKindBinary, diff --git a/resource-manager/securityinsights/2023-11-01/incidentalerts/client.go b/resource-manager/securityinsights/2023-11-01/incidentalerts/client.go index ae19637d473..53dc2b4cd4e 100644 --- a/resource-manager/securityinsights/2023-11-01/incidentalerts/client.go +++ b/resource-manager/securityinsights/2023-11-01/incidentalerts/client.go @@ -1,18 +1,26 @@ package incidentalerts -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type IncidentAlertsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewIncidentAlertsClientWithBaseURI(endpoint string) IncidentAlertsClient { - return IncidentAlertsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewIncidentAlertsClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentAlertsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidentalerts", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentAlertsClient: %+v", err) } + + return &IncidentAlertsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2023-11-01/incidentalerts/constants.go b/resource-manager/securityinsights/2023-11-01/incidentalerts/constants.go index 8f605bb09d5..3673d5b1163 100644 --- a/resource-manager/securityinsights/2023-11-01/incidentalerts/constants.go +++ b/resource-manager/securityinsights/2023-11-01/incidentalerts/constants.go @@ -1,6 +1,10 @@ package incidentalerts -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -23,6 +27,19 @@ func PossibleValuesForAlertSeverity() []string { } } +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertSeverity(input string) (*AlertSeverity, error) { vals := map[string]AlertSeverity{ "high": AlertSeverityHigh, @@ -59,6 +76,19 @@ func PossibleValuesForAlertStatus() []string { } } +func (s *AlertStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertStatus(input string) (*AlertStatus, error) { vals := map[string]AlertStatus{ "dismissed": AlertStatusDismissed, @@ -120,6 +150,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -165,6 +208,19 @@ func PossibleValuesForConfidenceLevel() []string { } } +func (s *ConfidenceLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceLevel(input string) (*ConfidenceLevel, error) { vals := map[string]ConfidenceLevel{ "high": ConfidenceLevelHigh, @@ -198,6 +254,19 @@ func PossibleValuesForConfidenceScoreStatus() []string { } } +func (s *ConfidenceScoreStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceScoreStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceScoreStatus(input string) (*ConfidenceScoreStatus, error) { vals := map[string]ConfidenceScoreStatus{ "final": ConfidenceScoreStatusFinal, @@ -266,6 +335,19 @@ func PossibleValuesForEntityKindEnum() []string { } } +func (s *EntityKindEnum) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityKindEnum(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityKindEnum(input string) (*EntityKindEnum, error) { vals := map[string]EntityKindEnum{ "account": EntityKindEnumAccount, @@ -317,6 +399,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, @@ -371,6 +466,19 @@ func PossibleValuesForKillChainIntent() []string { } } +func (s *KillChainIntent) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKillChainIntent(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseKillChainIntent(input string) (*KillChainIntent, error) { vals := map[string]KillChainIntent{ "collection": KillChainIntentCollection, diff --git a/resource-manager/securityinsights/2023-11-01/incidentalerts/method_incidentslistalerts.go b/resource-manager/securityinsights/2023-11-01/incidentalerts/method_incidentslistalerts.go new file mode 100644 index 00000000000..fe83693eae2 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/incidentalerts/method_incidentslistalerts.go @@ -0,0 +1,52 @@ +package incidentalerts + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentsListAlertsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IncidentAlertList +} + +// IncidentsListAlerts ... +func (c IncidentAlertsClient) IncidentsListAlerts(ctx context.Context, id IncidentId) (result IncidentsListAlertsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/alerts", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/incidentalerts/method_incidentslistalerts_autorest.go b/resource-manager/securityinsights/2023-11-01/incidentalerts/method_incidentslistalerts_autorest.go deleted file mode 100644 index de6c08e09a2..00000000000 --- a/resource-manager/securityinsights/2023-11-01/incidentalerts/method_incidentslistalerts_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package incidentalerts - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IncidentsListAlertsOperationResponse struct { - HttpResponse *http.Response - Model *IncidentAlertList -} - -// IncidentsListAlerts ... -func (c IncidentAlertsClient) IncidentsListAlerts(ctx context.Context, id IncidentId) (result IncidentsListAlertsOperationResponse, err error) { - req, err := c.preparerForIncidentsListAlerts(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentalerts.IncidentAlertsClient", "IncidentsListAlerts", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentalerts.IncidentAlertsClient", "IncidentsListAlerts", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIncidentsListAlerts(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentalerts.IncidentAlertsClient", "IncidentsListAlerts", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIncidentsListAlerts prepares the IncidentsListAlerts request. -func (c IncidentAlertsClient) preparerForIncidentsListAlerts(ctx context.Context, id IncidentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/alerts", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIncidentsListAlerts handles the response to the IncidentsListAlerts request. The method always -// closes the http.Response Body. -func (c IncidentAlertsClient) responderForIncidentsListAlerts(resp *http.Response) (result IncidentsListAlertsOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/incidentbookmarks/client.go b/resource-manager/securityinsights/2023-11-01/incidentbookmarks/client.go index e2fcca6728b..e6a60ede52d 100644 --- a/resource-manager/securityinsights/2023-11-01/incidentbookmarks/client.go +++ b/resource-manager/securityinsights/2023-11-01/incidentbookmarks/client.go @@ -1,18 +1,26 @@ package incidentbookmarks -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type IncidentBookmarksClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewIncidentBookmarksClientWithBaseURI(endpoint string) IncidentBookmarksClient { - return IncidentBookmarksClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewIncidentBookmarksClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentBookmarksClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidentbookmarks", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentBookmarksClient: %+v", err) } + + return &IncidentBookmarksClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2023-11-01/incidentbookmarks/constants.go b/resource-manager/securityinsights/2023-11-01/incidentbookmarks/constants.go index 7080e0657bc..27f31cfcc5e 100644 --- a/resource-manager/securityinsights/2023-11-01/incidentbookmarks/constants.go +++ b/resource-manager/securityinsights/2023-11-01/incidentbookmarks/constants.go @@ -1,6 +1,10 @@ package incidentbookmarks -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -23,6 +27,19 @@ func PossibleValuesForAlertSeverity() []string { } } +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertSeverity(input string) (*AlertSeverity, error) { vals := map[string]AlertSeverity{ "high": AlertSeverityHigh, @@ -59,6 +76,19 @@ func PossibleValuesForAlertStatus() []string { } } +func (s *AlertStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertStatus(input string) (*AlertStatus, error) { vals := map[string]AlertStatus{ "dismissed": AlertStatusDismissed, @@ -120,6 +150,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -165,6 +208,19 @@ func PossibleValuesForConfidenceLevel() []string { } } +func (s *ConfidenceLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceLevel(input string) (*ConfidenceLevel, error) { vals := map[string]ConfidenceLevel{ "high": ConfidenceLevelHigh, @@ -198,6 +254,19 @@ func PossibleValuesForConfidenceScoreStatus() []string { } } +func (s *ConfidenceScoreStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceScoreStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceScoreStatus(input string) (*ConfidenceScoreStatus, error) { vals := map[string]ConfidenceScoreStatus{ "final": ConfidenceScoreStatusFinal, @@ -266,6 +335,19 @@ func PossibleValuesForEntityKindEnum() []string { } } +func (s *EntityKindEnum) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityKindEnum(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityKindEnum(input string) (*EntityKindEnum, error) { vals := map[string]EntityKindEnum{ "account": EntityKindEnumAccount, @@ -317,6 +399,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, @@ -371,6 +466,19 @@ func PossibleValuesForKillChainIntent() []string { } } +func (s *KillChainIntent) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKillChainIntent(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseKillChainIntent(input string) (*KillChainIntent, error) { vals := map[string]KillChainIntent{ "collection": KillChainIntentCollection, diff --git a/resource-manager/securityinsights/2023-11-01/incidentbookmarks/method_incidentslistbookmarks.go b/resource-manager/securityinsights/2023-11-01/incidentbookmarks/method_incidentslistbookmarks.go new file mode 100644 index 00000000000..3ac7b9e8b2e --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/incidentbookmarks/method_incidentslistbookmarks.go @@ -0,0 +1,52 @@ +package incidentbookmarks + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentsListBookmarksOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IncidentBookmarkList +} + +// IncidentsListBookmarks ... +func (c IncidentBookmarksClient) IncidentsListBookmarks(ctx context.Context, id IncidentId) (result IncidentsListBookmarksOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/bookmarks", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/incidentbookmarks/method_incidentslistbookmarks_autorest.go b/resource-manager/securityinsights/2023-11-01/incidentbookmarks/method_incidentslistbookmarks_autorest.go deleted file mode 100644 index a5c3a89a09c..00000000000 --- a/resource-manager/securityinsights/2023-11-01/incidentbookmarks/method_incidentslistbookmarks_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package incidentbookmarks - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IncidentsListBookmarksOperationResponse struct { - HttpResponse *http.Response - Model *IncidentBookmarkList -} - -// IncidentsListBookmarks ... -func (c IncidentBookmarksClient) IncidentsListBookmarks(ctx context.Context, id IncidentId) (result IncidentsListBookmarksOperationResponse, err error) { - req, err := c.preparerForIncidentsListBookmarks(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentbookmarks.IncidentBookmarksClient", "IncidentsListBookmarks", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentbookmarks.IncidentBookmarksClient", "IncidentsListBookmarks", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIncidentsListBookmarks(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentbookmarks.IncidentBookmarksClient", "IncidentsListBookmarks", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIncidentsListBookmarks prepares the IncidentsListBookmarks request. -func (c IncidentBookmarksClient) preparerForIncidentsListBookmarks(ctx context.Context, id IncidentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/bookmarks", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIncidentsListBookmarks handles the response to the IncidentsListBookmarks request. The method always -// closes the http.Response Body. -func (c IncidentBookmarksClient) responderForIncidentsListBookmarks(resp *http.Response) (result IncidentsListBookmarksOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/incidentcomments/client.go b/resource-manager/securityinsights/2023-11-01/incidentcomments/client.go index 4006779247d..981e6f75216 100644 --- a/resource-manager/securityinsights/2023-11-01/incidentcomments/client.go +++ b/resource-manager/securityinsights/2023-11-01/incidentcomments/client.go @@ -1,18 +1,26 @@ package incidentcomments -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type IncidentCommentsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewIncidentCommentsClientWithBaseURI(endpoint string) IncidentCommentsClient { - return IncidentCommentsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewIncidentCommentsClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentCommentsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidentcomments", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentCommentsClient: %+v", err) } + + return &IncidentCommentsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2023-11-01/incidentcomments/method_createorupdate.go b/resource-manager/securityinsights/2023-11-01/incidentcomments/method_createorupdate.go new file mode 100644 index 00000000000..5c59b2be8d3 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/incidentcomments/method_createorupdate.go @@ -0,0 +1,56 @@ +package incidentcomments + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IncidentComment +} + +// CreateOrUpdate ... +func (c IncidentCommentsClient) CreateOrUpdate(ctx context.Context, id CommentId, input IncidentComment) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/incidentcomments/method_createorupdate_autorest.go b/resource-manager/securityinsights/2023-11-01/incidentcomments/method_createorupdate_autorest.go deleted file mode 100644 index b27777aad2c..00000000000 --- a/resource-manager/securityinsights/2023-11-01/incidentcomments/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package incidentcomments - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *IncidentComment -} - -// CreateOrUpdate ... -func (c IncidentCommentsClient) CreateOrUpdate(ctx context.Context, id CommentId, input IncidentComment) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c IncidentCommentsClient) preparerForCreateOrUpdate(ctx context.Context, id CommentId, input IncidentComment) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c IncidentCommentsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/incidentcomments/method_delete.go b/resource-manager/securityinsights/2023-11-01/incidentcomments/method_delete.go new file mode 100644 index 00000000000..78412a13e76 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/incidentcomments/method_delete.go @@ -0,0 +1,47 @@ +package incidentcomments + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c IncidentCommentsClient) Delete(ctx context.Context, id CommentId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/incidentcomments/method_delete_autorest.go b/resource-manager/securityinsights/2023-11-01/incidentcomments/method_delete_autorest.go deleted file mode 100644 index 6bbb4c92cbf..00000000000 --- a/resource-manager/securityinsights/2023-11-01/incidentcomments/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package incidentcomments - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c IncidentCommentsClient) Delete(ctx context.Context, id CommentId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c IncidentCommentsClient) preparerForDelete(ctx context.Context, id CommentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c IncidentCommentsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/incidentcomments/method_get.go b/resource-manager/securityinsights/2023-11-01/incidentcomments/method_get.go new file mode 100644 index 00000000000..e8d11306ddb --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/incidentcomments/method_get.go @@ -0,0 +1,51 @@ +package incidentcomments + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IncidentComment +} + +// Get ... +func (c IncidentCommentsClient) Get(ctx context.Context, id CommentId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/incidentcomments/method_get_autorest.go b/resource-manager/securityinsights/2023-11-01/incidentcomments/method_get_autorest.go deleted file mode 100644 index 8402ed77e94..00000000000 --- a/resource-manager/securityinsights/2023-11-01/incidentcomments/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package incidentcomments - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *IncidentComment -} - -// Get ... -func (c IncidentCommentsClient) Get(ctx context.Context, id CommentId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c IncidentCommentsClient) preparerForGet(ctx context.Context, id CommentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c IncidentCommentsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/incidentcomments/method_list.go b/resource-manager/securityinsights/2023-11-01/incidentcomments/method_list.go new file mode 100644 index 00000000000..b4c16058b38 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/incidentcomments/method_list.go @@ -0,0 +1,127 @@ +package incidentcomments + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]IncidentComment +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []IncidentComment +} + +type ListOperationOptions struct { + Filter *string + Orderby *string + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c IncidentCommentsClient) List(ctx context.Context, id IncidentId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/comments", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]IncidentComment `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c IncidentCommentsClient) ListComplete(ctx context.Context, id IncidentId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, IncidentCommentOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c IncidentCommentsClient) ListCompleteMatchingPredicate(ctx context.Context, id IncidentId, options ListOperationOptions, predicate IncidentCommentOperationPredicate) (result ListCompleteResult, err error) { + items := make([]IncidentComment, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2023-11-01/incidentcomments/method_list_autorest.go b/resource-manager/securityinsights/2023-11-01/incidentcomments/method_list_autorest.go deleted file mode 100644 index 24fb8d1d7e7..00000000000 --- a/resource-manager/securityinsights/2023-11-01/incidentcomments/method_list_autorest.go +++ /dev/null @@ -1,225 +0,0 @@ -package incidentcomments - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]IncidentComment - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []IncidentComment -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ListOperationOptions struct { - Filter *string - Orderby *string - Top *int64 -} - -func DefaultListOperationOptions() ListOperationOptions { - return ListOperationOptions{} -} - -func (o ListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Filter != nil { - out["$filter"] = *o.Filter - } - - if o.Orderby != nil { - out["$orderby"] = *o.Orderby - } - - if o.Top != nil { - out["$top"] = *o.Top - } - - return out -} - -// List ... -func (c IncidentCommentsClient) List(ctx context.Context, id IncidentId, options ListOperationOptions) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c IncidentCommentsClient) preparerForList(ctx context.Context, id IncidentId, options ListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/comments", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c IncidentCommentsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c IncidentCommentsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []IncidentComment `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentcomments.IncidentCommentsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c IncidentCommentsClient) ListComplete(ctx context.Context, id IncidentId, options ListOperationOptions) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, options, IncidentCommentOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c IncidentCommentsClient) ListCompleteMatchingPredicate(ctx context.Context, id IncidentId, options ListOperationOptions, predicate IncidentCommentOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]IncidentComment, 0) - - page, err := c.List(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2023-11-01/incidententities/client.go b/resource-manager/securityinsights/2023-11-01/incidententities/client.go index 5f0eaf07782..740e7b81755 100644 --- a/resource-manager/securityinsights/2023-11-01/incidententities/client.go +++ b/resource-manager/securityinsights/2023-11-01/incidententities/client.go @@ -1,18 +1,26 @@ package incidententities -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type IncidentEntitiesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewIncidentEntitiesClientWithBaseURI(endpoint string) IncidentEntitiesClient { - return IncidentEntitiesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewIncidentEntitiesClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentEntitiesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidententities", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentEntitiesClient: %+v", err) } + + return &IncidentEntitiesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2023-11-01/incidententities/constants.go b/resource-manager/securityinsights/2023-11-01/incidententities/constants.go index cb1b487a229..a1d54eb28d0 100644 --- a/resource-manager/securityinsights/2023-11-01/incidententities/constants.go +++ b/resource-manager/securityinsights/2023-11-01/incidententities/constants.go @@ -1,6 +1,10 @@ package incidententities -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -23,6 +27,19 @@ func PossibleValuesForAlertSeverity() []string { } } +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertSeverity(input string) (*AlertSeverity, error) { vals := map[string]AlertSeverity{ "high": AlertSeverityHigh, @@ -59,6 +76,19 @@ func PossibleValuesForAlertStatus() []string { } } +func (s *AlertStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAlertStatus(input string) (*AlertStatus, error) { vals := map[string]AlertStatus{ "dismissed": AlertStatusDismissed, @@ -120,6 +150,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -165,6 +208,19 @@ func PossibleValuesForConfidenceLevel() []string { } } +func (s *ConfidenceLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceLevel(input string) (*ConfidenceLevel, error) { vals := map[string]ConfidenceLevel{ "high": ConfidenceLevelHigh, @@ -198,6 +254,19 @@ func PossibleValuesForConfidenceScoreStatus() []string { } } +func (s *ConfidenceScoreStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceScoreStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConfidenceScoreStatus(input string) (*ConfidenceScoreStatus, error) { vals := map[string]ConfidenceScoreStatus{ "final": ConfidenceScoreStatusFinal, @@ -266,6 +335,19 @@ func PossibleValuesForEntityKindEnum() []string { } } +func (s *EntityKindEnum) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityKindEnum(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEntityKindEnum(input string) (*EntityKindEnum, error) { vals := map[string]EntityKindEnum{ "account": EntityKindEnumAccount, @@ -317,6 +399,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, @@ -371,6 +466,19 @@ func PossibleValuesForKillChainIntent() []string { } } +func (s *KillChainIntent) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKillChainIntent(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseKillChainIntent(input string) (*KillChainIntent, error) { vals := map[string]KillChainIntent{ "collection": KillChainIntentCollection, diff --git a/resource-manager/securityinsights/2023-11-01/incidententities/method_incidentslistentities.go b/resource-manager/securityinsights/2023-11-01/incidententities/method_incidentslistentities.go new file mode 100644 index 00000000000..36ec8f0c75b --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/incidententities/method_incidentslistentities.go @@ -0,0 +1,52 @@ +package incidententities + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentsListEntitiesOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IncidentEntitiesResponse +} + +// IncidentsListEntities ... +func (c IncidentEntitiesClient) IncidentsListEntities(ctx context.Context, id IncidentId) (result IncidentsListEntitiesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/entities", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/incidententities/method_incidentslistentities_autorest.go b/resource-manager/securityinsights/2023-11-01/incidententities/method_incidentslistentities_autorest.go deleted file mode 100644 index 9d796d431cb..00000000000 --- a/resource-manager/securityinsights/2023-11-01/incidententities/method_incidentslistentities_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package incidententities - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IncidentsListEntitiesOperationResponse struct { - HttpResponse *http.Response - Model *IncidentEntitiesResponse -} - -// IncidentsListEntities ... -func (c IncidentEntitiesClient) IncidentsListEntities(ctx context.Context, id IncidentId) (result IncidentsListEntitiesOperationResponse, err error) { - req, err := c.preparerForIncidentsListEntities(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidententities.IncidentEntitiesClient", "IncidentsListEntities", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidententities.IncidentEntitiesClient", "IncidentsListEntities", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIncidentsListEntities(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidententities.IncidentEntitiesClient", "IncidentsListEntities", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIncidentsListEntities prepares the IncidentsListEntities request. -func (c IncidentEntitiesClient) preparerForIncidentsListEntities(ctx context.Context, id IncidentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/entities", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIncidentsListEntities handles the response to the IncidentsListEntities request. The method always -// closes the http.Response Body. -func (c IncidentEntitiesClient) responderForIncidentsListEntities(resp *http.Response) (result IncidentsListEntitiesOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/incidentrelations/client.go b/resource-manager/securityinsights/2023-11-01/incidentrelations/client.go index 58aa27c43e8..4e8fbfeb71d 100644 --- a/resource-manager/securityinsights/2023-11-01/incidentrelations/client.go +++ b/resource-manager/securityinsights/2023-11-01/incidentrelations/client.go @@ -1,18 +1,26 @@ package incidentrelations -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type IncidentRelationsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewIncidentRelationsClientWithBaseURI(endpoint string) IncidentRelationsClient { - return IncidentRelationsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewIncidentRelationsClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentRelationsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidentrelations", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentRelationsClient: %+v", err) } + + return &IncidentRelationsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2023-11-01/incidentrelations/method_createorupdate.go b/resource-manager/securityinsights/2023-11-01/incidentrelations/method_createorupdate.go new file mode 100644 index 00000000000..4b4ff3d56f8 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/incidentrelations/method_createorupdate.go @@ -0,0 +1,56 @@ +package incidentrelations + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Relation +} + +// CreateOrUpdate ... +func (c IncidentRelationsClient) CreateOrUpdate(ctx context.Context, id RelationId, input Relation) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/incidentrelations/method_createorupdate_autorest.go b/resource-manager/securityinsights/2023-11-01/incidentrelations/method_createorupdate_autorest.go deleted file mode 100644 index 79cf52b5347..00000000000 --- a/resource-manager/securityinsights/2023-11-01/incidentrelations/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package incidentrelations - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *Relation -} - -// CreateOrUpdate ... -func (c IncidentRelationsClient) CreateOrUpdate(ctx context.Context, id RelationId, input Relation) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c IncidentRelationsClient) preparerForCreateOrUpdate(ctx context.Context, id RelationId, input Relation) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c IncidentRelationsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/incidentrelations/method_delete.go b/resource-manager/securityinsights/2023-11-01/incidentrelations/method_delete.go new file mode 100644 index 00000000000..de3afbf47c9 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/incidentrelations/method_delete.go @@ -0,0 +1,47 @@ +package incidentrelations + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c IncidentRelationsClient) Delete(ctx context.Context, id RelationId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/incidentrelations/method_delete_autorest.go b/resource-manager/securityinsights/2023-11-01/incidentrelations/method_delete_autorest.go deleted file mode 100644 index 9003689e999..00000000000 --- a/resource-manager/securityinsights/2023-11-01/incidentrelations/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package incidentrelations - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c IncidentRelationsClient) Delete(ctx context.Context, id RelationId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c IncidentRelationsClient) preparerForDelete(ctx context.Context, id RelationId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c IncidentRelationsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/incidentrelations/method_get.go b/resource-manager/securityinsights/2023-11-01/incidentrelations/method_get.go new file mode 100644 index 00000000000..7cc37b68825 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/incidentrelations/method_get.go @@ -0,0 +1,51 @@ +package incidentrelations + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Relation +} + +// Get ... +func (c IncidentRelationsClient) Get(ctx context.Context, id RelationId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/incidentrelations/method_get_autorest.go b/resource-manager/securityinsights/2023-11-01/incidentrelations/method_get_autorest.go deleted file mode 100644 index a8b88ddecb4..00000000000 --- a/resource-manager/securityinsights/2023-11-01/incidentrelations/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package incidentrelations - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *Relation -} - -// Get ... -func (c IncidentRelationsClient) Get(ctx context.Context, id RelationId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c IncidentRelationsClient) preparerForGet(ctx context.Context, id RelationId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c IncidentRelationsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/incidentrelations/method_list.go b/resource-manager/securityinsights/2023-11-01/incidentrelations/method_list.go new file mode 100644 index 00000000000..80873d441b4 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/incidentrelations/method_list.go @@ -0,0 +1,127 @@ +package incidentrelations + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Relation +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Relation +} + +type ListOperationOptions struct { + Filter *string + Orderby *string + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c IncidentRelationsClient) List(ctx context.Context, id IncidentId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/relations", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Relation `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c IncidentRelationsClient) ListComplete(ctx context.Context, id IncidentId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, RelationOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c IncidentRelationsClient) ListCompleteMatchingPredicate(ctx context.Context, id IncidentId, options ListOperationOptions, predicate RelationOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Relation, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2023-11-01/incidentrelations/method_list_autorest.go b/resource-manager/securityinsights/2023-11-01/incidentrelations/method_list_autorest.go deleted file mode 100644 index a270a442886..00000000000 --- a/resource-manager/securityinsights/2023-11-01/incidentrelations/method_list_autorest.go +++ /dev/null @@ -1,225 +0,0 @@ -package incidentrelations - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]Relation - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []Relation -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ListOperationOptions struct { - Filter *string - Orderby *string - Top *int64 -} - -func DefaultListOperationOptions() ListOperationOptions { - return ListOperationOptions{} -} - -func (o ListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Filter != nil { - out["$filter"] = *o.Filter - } - - if o.Orderby != nil { - out["$orderby"] = *o.Orderby - } - - if o.Top != nil { - out["$top"] = *o.Top - } - - return out -} - -// List ... -func (c IncidentRelationsClient) List(ctx context.Context, id IncidentId, options ListOperationOptions) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c IncidentRelationsClient) preparerForList(ctx context.Context, id IncidentId, options ListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/relations", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c IncidentRelationsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c IncidentRelationsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []Relation `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidentrelations.IncidentRelationsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c IncidentRelationsClient) ListComplete(ctx context.Context, id IncidentId, options ListOperationOptions) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, options, RelationOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c IncidentRelationsClient) ListCompleteMatchingPredicate(ctx context.Context, id IncidentId, options ListOperationOptions, predicate RelationOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]Relation, 0) - - page, err := c.List(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2023-11-01/incidents/client.go b/resource-manager/securityinsights/2023-11-01/incidents/client.go index 659897d18d7..aaf38071c39 100644 --- a/resource-manager/securityinsights/2023-11-01/incidents/client.go +++ b/resource-manager/securityinsights/2023-11-01/incidents/client.go @@ -1,18 +1,26 @@ package incidents -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type IncidentsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewIncidentsClientWithBaseURI(endpoint string) IncidentsClient { - return IncidentsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewIncidentsClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidents", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentsClient: %+v", err) } + + return &IncidentsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2023-11-01/incidents/constants.go b/resource-manager/securityinsights/2023-11-01/incidents/constants.go index 82782d4107f..ce046b9edba 100644 --- a/resource-manager/securityinsights/2023-11-01/incidents/constants.go +++ b/resource-manager/securityinsights/2023-11-01/incidents/constants.go @@ -1,6 +1,10 @@ package incidents -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -49,6 +53,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -96,6 +113,19 @@ func PossibleValuesForIncidentClassification() []string { } } +func (s *IncidentClassification) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentClassification(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentClassification(input string) (*IncidentClassification, error) { vals := map[string]IncidentClassification{ "benignpositive": IncidentClassificationBenignPositive, @@ -130,6 +160,19 @@ func PossibleValuesForIncidentClassificationReason() []string { } } +func (s *IncidentClassificationReason) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentClassificationReason(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentClassificationReason(input string) (*IncidentClassificationReason, error) { vals := map[string]IncidentClassificationReason{ "inaccuratedata": IncidentClassificationReasonInaccurateData, @@ -160,6 +203,19 @@ func PossibleValuesForIncidentLabelType() []string { } } +func (s *IncidentLabelType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentLabelType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentLabelType(input string) (*IncidentLabelType, error) { vals := map[string]IncidentLabelType{ "autoassigned": IncidentLabelTypeAutoAssigned, @@ -192,6 +248,19 @@ func PossibleValuesForIncidentSeverity() []string { } } +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentSeverity(input string) (*IncidentSeverity, error) { vals := map[string]IncidentSeverity{ "high": IncidentSeverityHigh, @@ -224,6 +293,19 @@ func PossibleValuesForIncidentStatus() []string { } } +func (s *IncidentStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseIncidentStatus(input string) (*IncidentStatus, error) { vals := map[string]IncidentStatus{ "active": IncidentStatusActive, @@ -255,6 +337,19 @@ func PossibleValuesForOwnerType() []string { } } +func (s *OwnerType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOwnerType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseOwnerType(input string) (*OwnerType, error) { vals := map[string]OwnerType{ "group": OwnerTypeGroup, diff --git a/resource-manager/securityinsights/2023-11-01/incidents/method_createorupdate.go b/resource-manager/securityinsights/2023-11-01/incidents/method_createorupdate.go new file mode 100644 index 00000000000..3fcc110ed02 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/incidents/method_createorupdate.go @@ -0,0 +1,56 @@ +package incidents + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Incident +} + +// CreateOrUpdate ... +func (c IncidentsClient) CreateOrUpdate(ctx context.Context, id IncidentId, input Incident) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/incidents/method_createorupdate_autorest.go b/resource-manager/securityinsights/2023-11-01/incidents/method_createorupdate_autorest.go deleted file mode 100644 index 837aa7c92a0..00000000000 --- a/resource-manager/securityinsights/2023-11-01/incidents/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package incidents - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *Incident -} - -// CreateOrUpdate ... -func (c IncidentsClient) CreateOrUpdate(ctx context.Context, id IncidentId, input Incident) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c IncidentsClient) preparerForCreateOrUpdate(ctx context.Context, id IncidentId, input Incident) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c IncidentsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/incidents/method_delete.go b/resource-manager/securityinsights/2023-11-01/incidents/method_delete.go new file mode 100644 index 00000000000..9b3205af5fc --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/incidents/method_delete.go @@ -0,0 +1,47 @@ +package incidents + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c IncidentsClient) Delete(ctx context.Context, id IncidentId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/incidents/method_delete_autorest.go b/resource-manager/securityinsights/2023-11-01/incidents/method_delete_autorest.go deleted file mode 100644 index 280832422f8..00000000000 --- a/resource-manager/securityinsights/2023-11-01/incidents/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package incidents - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c IncidentsClient) Delete(ctx context.Context, id IncidentId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c IncidentsClient) preparerForDelete(ctx context.Context, id IncidentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c IncidentsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/incidents/method_get.go b/resource-manager/securityinsights/2023-11-01/incidents/method_get.go new file mode 100644 index 00000000000..e6d4e9e933b --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/incidents/method_get.go @@ -0,0 +1,51 @@ +package incidents + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Incident +} + +// Get ... +func (c IncidentsClient) Get(ctx context.Context, id IncidentId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/incidents/method_get_autorest.go b/resource-manager/securityinsights/2023-11-01/incidents/method_get_autorest.go deleted file mode 100644 index d8d2b7debeb..00000000000 --- a/resource-manager/securityinsights/2023-11-01/incidents/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package incidents - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *Incident -} - -// Get ... -func (c IncidentsClient) Get(ctx context.Context, id IncidentId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c IncidentsClient) preparerForGet(ctx context.Context, id IncidentId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c IncidentsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/incidents/method_list.go b/resource-manager/securityinsights/2023-11-01/incidents/method_list.go new file mode 100644 index 00000000000..fe19cd4d9ff --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/incidents/method_list.go @@ -0,0 +1,127 @@ +package incidents + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Incident +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Incident +} + +type ListOperationOptions struct { + Filter *string + Orderby *string + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c IncidentsClient) List(ctx context.Context, id WorkspaceId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/incidents", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Incident `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c IncidentsClient) ListComplete(ctx context.Context, id WorkspaceId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, IncidentOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c IncidentsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ListOperationOptions, predicate IncidentOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Incident, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2023-11-01/incidents/method_list_autorest.go b/resource-manager/securityinsights/2023-11-01/incidents/method_list_autorest.go deleted file mode 100644 index 8d2f5acc547..00000000000 --- a/resource-manager/securityinsights/2023-11-01/incidents/method_list_autorest.go +++ /dev/null @@ -1,225 +0,0 @@ -package incidents - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]Incident - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []Incident -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ListOperationOptions struct { - Filter *string - Orderby *string - Top *int64 -} - -func DefaultListOperationOptions() ListOperationOptions { - return ListOperationOptions{} -} - -func (o ListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Filter != nil { - out["$filter"] = *o.Filter - } - - if o.Orderby != nil { - out["$orderby"] = *o.Orderby - } - - if o.Top != nil { - out["$top"] = *o.Top - } - - return out -} - -// List ... -func (c IncidentsClient) List(ctx context.Context, id WorkspaceId, options ListOperationOptions) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c IncidentsClient) preparerForList(ctx context.Context, id WorkspaceId, options ListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/incidents", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c IncidentsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c IncidentsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []Incident `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "incidents.IncidentsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c IncidentsClient) ListComplete(ctx context.Context, id WorkspaceId, options ListOperationOptions) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, options, IncidentOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c IncidentsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ListOperationOptions, predicate IncidentOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]Incident, 0) - - page, err := c.List(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2023-11-01/metadata/client.go b/resource-manager/securityinsights/2023-11-01/metadata/client.go index 05f0e7940c0..59e4192159f 100644 --- a/resource-manager/securityinsights/2023-11-01/metadata/client.go +++ b/resource-manager/securityinsights/2023-11-01/metadata/client.go @@ -1,18 +1,26 @@ package metadata -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type MetadataClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewMetadataClientWithBaseURI(endpoint string) MetadataClient { - return MetadataClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewMetadataClientWithBaseURI(sdkApi sdkEnv.Api) (*MetadataClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "metadata", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating MetadataClient: %+v", err) } + + return &MetadataClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2023-11-01/metadata/constants.go b/resource-manager/securityinsights/2023-11-01/metadata/constants.go index d64c8db1b25..e1a5d1b92ff 100644 --- a/resource-manager/securityinsights/2023-11-01/metadata/constants.go +++ b/resource-manager/securityinsights/2023-11-01/metadata/constants.go @@ -1,6 +1,10 @@ package metadata -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -49,6 +53,19 @@ func PossibleValuesForKind() []string { } } +func (s *Kind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseKind(input string) (*Kind, error) { vals := map[string]Kind{ "analyticsrule": KindAnalyticsRule, @@ -92,6 +109,19 @@ func PossibleValuesForOperator() []string { } } +func (s *Operator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseOperator(input string) (*Operator, error) { vals := map[string]Operator{ "and": OperatorAND, @@ -124,6 +154,19 @@ func PossibleValuesForSourceKind() []string { } } +func (s *SourceKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSourceKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSourceKind(input string) (*SourceKind, error) { vals := map[string]SourceKind{ "community": SourceKindCommunity, @@ -156,6 +199,19 @@ func PossibleValuesForSupportTier() []string { } } +func (s *SupportTier) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSupportTier(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSupportTier(input string) (*SupportTier, error) { vals := map[string]SupportTier{ "community": SupportTierCommunity, diff --git a/resource-manager/securityinsights/2023-11-01/metadata/method_create.go b/resource-manager/securityinsights/2023-11-01/metadata/method_create.go new file mode 100644 index 00000000000..36522e6397c --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/metadata/method_create.go @@ -0,0 +1,56 @@ +package metadata + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *MetadataModel +} + +// Create ... +func (c MetadataClient) Create(ctx context.Context, id MetadataId, input MetadataModel) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/metadata/method_create_autorest.go b/resource-manager/securityinsights/2023-11-01/metadata/method_create_autorest.go deleted file mode 100644 index 1ae47584687..00000000000 --- a/resource-manager/securityinsights/2023-11-01/metadata/method_create_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package metadata - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOperationResponse struct { - HttpResponse *http.Response - Model *MetadataModel -} - -// Create ... -func (c MetadataClient) Create(ctx context.Context, id MetadataId, input MetadataModel) (result CreateOperationResponse, err error) { - req, err := c.preparerForCreate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Create", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Create", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Create", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreate prepares the Create request. -func (c MetadataClient) preparerForCreate(ctx context.Context, id MetadataId, input MetadataModel) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreate handles the response to the Create request. The method always -// closes the http.Response Body. -func (c MetadataClient) responderForCreate(resp *http.Response) (result CreateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/metadata/method_delete.go b/resource-manager/securityinsights/2023-11-01/metadata/method_delete.go new file mode 100644 index 00000000000..559f479cb03 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/metadata/method_delete.go @@ -0,0 +1,47 @@ +package metadata + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c MetadataClient) Delete(ctx context.Context, id MetadataId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/metadata/method_delete_autorest.go b/resource-manager/securityinsights/2023-11-01/metadata/method_delete_autorest.go deleted file mode 100644 index 3a151eefd21..00000000000 --- a/resource-manager/securityinsights/2023-11-01/metadata/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package metadata - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c MetadataClient) Delete(ctx context.Context, id MetadataId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c MetadataClient) preparerForDelete(ctx context.Context, id MetadataId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c MetadataClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/metadata/method_get.go b/resource-manager/securityinsights/2023-11-01/metadata/method_get.go new file mode 100644 index 00000000000..a687bafec62 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/metadata/method_get.go @@ -0,0 +1,51 @@ +package metadata + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *MetadataModel +} + +// Get ... +func (c MetadataClient) Get(ctx context.Context, id MetadataId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/metadata/method_get_autorest.go b/resource-manager/securityinsights/2023-11-01/metadata/method_get_autorest.go deleted file mode 100644 index 25827d74702..00000000000 --- a/resource-manager/securityinsights/2023-11-01/metadata/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package metadata - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *MetadataModel -} - -// Get ... -func (c MetadataClient) Get(ctx context.Context, id MetadataId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c MetadataClient) preparerForGet(ctx context.Context, id MetadataId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c MetadataClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/metadata/method_list.go b/resource-manager/securityinsights/2023-11-01/metadata/method_list.go new file mode 100644 index 00000000000..58267143629 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/metadata/method_list.go @@ -0,0 +1,131 @@ +package metadata + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]MetadataModel +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []MetadataModel +} + +type ListOperationOptions struct { + Filter *string + Orderby *string + Skip *int64 + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c MetadataClient) List(ctx context.Context, id WorkspaceId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/metadata", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]MetadataModel `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c MetadataClient) ListComplete(ctx context.Context, id WorkspaceId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, MetadataModelOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c MetadataClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ListOperationOptions, predicate MetadataModelOperationPredicate) (result ListCompleteResult, err error) { + items := make([]MetadataModel, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2023-11-01/metadata/method_list_autorest.go b/resource-manager/securityinsights/2023-11-01/metadata/method_list_autorest.go deleted file mode 100644 index e5f025d62ee..00000000000 --- a/resource-manager/securityinsights/2023-11-01/metadata/method_list_autorest.go +++ /dev/null @@ -1,230 +0,0 @@ -package metadata - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]MetadataModel - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []MetadataModel -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ListOperationOptions struct { - Filter *string - Orderby *string - Skip *int64 - Top *int64 -} - -func DefaultListOperationOptions() ListOperationOptions { - return ListOperationOptions{} -} - -func (o ListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Filter != nil { - out["$filter"] = *o.Filter - } - - if o.Orderby != nil { - out["$orderby"] = *o.Orderby - } - - if o.Skip != nil { - out["$skip"] = *o.Skip - } - - if o.Top != nil { - out["$top"] = *o.Top - } - - return out -} - -// List ... -func (c MetadataClient) List(ctx context.Context, id WorkspaceId, options ListOperationOptions) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c MetadataClient) preparerForList(ctx context.Context, id WorkspaceId, options ListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/metadata", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c MetadataClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c MetadataClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []MetadataModel `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c MetadataClient) ListComplete(ctx context.Context, id WorkspaceId, options ListOperationOptions) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, options, MetadataModelOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c MetadataClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ListOperationOptions, predicate MetadataModelOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]MetadataModel, 0) - - page, err := c.List(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2023-11-01/metadata/method_update.go b/resource-manager/securityinsights/2023-11-01/metadata/method_update.go new file mode 100644 index 00000000000..47f777cee27 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/metadata/method_update.go @@ -0,0 +1,55 @@ +package metadata + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *MetadataModel +} + +// Update ... +func (c MetadataClient) Update(ctx context.Context, id MetadataId, input MetadataPatch) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/metadata/method_update_autorest.go b/resource-manager/securityinsights/2023-11-01/metadata/method_update_autorest.go deleted file mode 100644 index a4bd18d08d6..00000000000 --- a/resource-manager/securityinsights/2023-11-01/metadata/method_update_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package metadata - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type UpdateOperationResponse struct { - HttpResponse *http.Response - Model *MetadataModel -} - -// Update ... -func (c MetadataClient) Update(ctx context.Context, id MetadataId, input MetadataPatch) (result UpdateOperationResponse, err error) { - req, err := c.preparerForUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Update", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Update", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Update", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForUpdate prepares the Update request. -func (c MetadataClient) preparerForUpdate(ctx context.Context, id MetadataId, input MetadataPatch) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPatch(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForUpdate handles the response to the Update request. The method always -// closes the http.Response Body. -func (c MetadataClient) responderForUpdate(resp *http.Response) (result UpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/repositories/client.go b/resource-manager/securityinsights/2023-11-01/repositories/client.go index 562953712b0..62b7be88387 100644 --- a/resource-manager/securityinsights/2023-11-01/repositories/client.go +++ b/resource-manager/securityinsights/2023-11-01/repositories/client.go @@ -1,18 +1,26 @@ package repositories -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type RepositoriesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewRepositoriesClientWithBaseURI(endpoint string) RepositoriesClient { - return RepositoriesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewRepositoriesClientWithBaseURI(sdkApi sdkEnv.Api) (*RepositoriesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "repositories", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating RepositoriesClient: %+v", err) } + + return &RepositoriesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2023-11-01/repositories/constants.go b/resource-manager/securityinsights/2023-11-01/repositories/constants.go index d95ce47c736..02231d76221 100644 --- a/resource-manager/securityinsights/2023-11-01/repositories/constants.go +++ b/resource-manager/securityinsights/2023-11-01/repositories/constants.go @@ -1,6 +1,10 @@ package repositories -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -21,6 +25,19 @@ func PossibleValuesForRepositoryAccessKind() []string { } } +func (s *RepositoryAccessKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRepositoryAccessKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseRepositoryAccessKind(input string) (*RepositoryAccessKind, error) { vals := map[string]RepositoryAccessKind{ "app": RepositoryAccessKindApp, diff --git a/resource-manager/securityinsights/2023-11-01/repositories/method_sourcecontrollistrepositories.go b/resource-manager/securityinsights/2023-11-01/repositories/method_sourcecontrollistrepositories.go new file mode 100644 index 00000000000..2ba9f22f421 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/repositories/method_sourcecontrollistrepositories.go @@ -0,0 +1,91 @@ +package repositories + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SourceControllistRepositoriesOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Repo +} + +type SourceControllistRepositoriesCompleteResult struct { + LatestHttpResponse *http.Response + Items []Repo +} + +// SourceControllistRepositories ... +func (c RepositoriesClient) SourceControllistRepositories(ctx context.Context, id WorkspaceId, input RepositoryAccessProperties) (result SourceControllistRepositoriesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/listRepositories", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Repo `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// SourceControllistRepositoriesComplete retrieves all the results into a single object +func (c RepositoriesClient) SourceControllistRepositoriesComplete(ctx context.Context, id WorkspaceId, input RepositoryAccessProperties) (SourceControllistRepositoriesCompleteResult, error) { + return c.SourceControllistRepositoriesCompleteMatchingPredicate(ctx, id, input, RepoOperationPredicate{}) +} + +// SourceControllistRepositoriesCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c RepositoriesClient) SourceControllistRepositoriesCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, input RepositoryAccessProperties, predicate RepoOperationPredicate) (result SourceControllistRepositoriesCompleteResult, err error) { + items := make([]Repo, 0) + + resp, err := c.SourceControllistRepositories(ctx, id, input) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = SourceControllistRepositoriesCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2023-11-01/repositories/method_sourcecontrollistrepositories_autorest.go b/resource-manager/securityinsights/2023-11-01/repositories/method_sourcecontrollistrepositories_autorest.go deleted file mode 100644 index c86f9dea30b..00000000000 --- a/resource-manager/securityinsights/2023-11-01/repositories/method_sourcecontrollistrepositories_autorest.go +++ /dev/null @@ -1,187 +0,0 @@ -package repositories - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type SourceControllistRepositoriesOperationResponse struct { - HttpResponse *http.Response - Model *[]Repo - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (SourceControllistRepositoriesOperationResponse, error) -} - -type SourceControllistRepositoriesCompleteResult struct { - Items []Repo -} - -func (r SourceControllistRepositoriesOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r SourceControllistRepositoriesOperationResponse) LoadMore(ctx context.Context) (resp SourceControllistRepositoriesOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// SourceControllistRepositories ... -func (c RepositoriesClient) SourceControllistRepositories(ctx context.Context, id WorkspaceId, input RepositoryAccessProperties) (resp SourceControllistRepositoriesOperationResponse, err error) { - req, err := c.preparerForSourceControllistRepositories(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "repositories.RepositoriesClient", "SourceControllistRepositories", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "repositories.RepositoriesClient", "SourceControllistRepositories", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForSourceControllistRepositories(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "repositories.RepositoriesClient", "SourceControllistRepositories", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForSourceControllistRepositories prepares the SourceControllistRepositories request. -func (c RepositoriesClient) preparerForSourceControllistRepositories(ctx context.Context, id WorkspaceId, input RepositoryAccessProperties) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/listRepositories", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForSourceControllistRepositoriesWithNextLink prepares the SourceControllistRepositories request with the given nextLink token. -func (c RepositoriesClient) preparerForSourceControllistRepositoriesWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForSourceControllistRepositories handles the response to the SourceControllistRepositories request. The method always -// closes the http.Response Body. -func (c RepositoriesClient) responderForSourceControllistRepositories(resp *http.Response) (result SourceControllistRepositoriesOperationResponse, err error) { - type page struct { - Values []Repo `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result SourceControllistRepositoriesOperationResponse, err error) { - req, err := c.preparerForSourceControllistRepositoriesWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "repositories.RepositoriesClient", "SourceControllistRepositories", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "repositories.RepositoriesClient", "SourceControllistRepositories", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForSourceControllistRepositories(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "repositories.RepositoriesClient", "SourceControllistRepositories", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// SourceControllistRepositoriesComplete retrieves all of the results into a single object -func (c RepositoriesClient) SourceControllistRepositoriesComplete(ctx context.Context, id WorkspaceId, input RepositoryAccessProperties) (SourceControllistRepositoriesCompleteResult, error) { - return c.SourceControllistRepositoriesCompleteMatchingPredicate(ctx, id, input, RepoOperationPredicate{}) -} - -// SourceControllistRepositoriesCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c RepositoriesClient) SourceControllistRepositoriesCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, input RepositoryAccessProperties, predicate RepoOperationPredicate) (resp SourceControllistRepositoriesCompleteResult, err error) { - items := make([]Repo, 0) - - page, err := c.SourceControllistRepositories(ctx, id, input) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := SourceControllistRepositoriesCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2023-11-01/securitymlanalyticssettings/client.go b/resource-manager/securityinsights/2023-11-01/securitymlanalyticssettings/client.go index 50d64fb429c..65b248a41f5 100644 --- a/resource-manager/securityinsights/2023-11-01/securitymlanalyticssettings/client.go +++ b/resource-manager/securityinsights/2023-11-01/securitymlanalyticssettings/client.go @@ -1,18 +1,26 @@ package securitymlanalyticssettings -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type SecurityMLAnalyticsSettingsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewSecurityMLAnalyticsSettingsClientWithBaseURI(endpoint string) SecurityMLAnalyticsSettingsClient { - return SecurityMLAnalyticsSettingsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewSecurityMLAnalyticsSettingsClientWithBaseURI(sdkApi sdkEnv.Api) (*SecurityMLAnalyticsSettingsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "securitymlanalyticssettings", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SecurityMLAnalyticsSettingsClient: %+v", err) } + + return &SecurityMLAnalyticsSettingsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2023-11-01/securitymlanalyticssettings/constants.go b/resource-manager/securityinsights/2023-11-01/securitymlanalyticssettings/constants.go index 47b13b875e2..e32d4d9875f 100644 --- a/resource-manager/securityinsights/2023-11-01/securitymlanalyticssettings/constants.go +++ b/resource-manager/securityinsights/2023-11-01/securitymlanalyticssettings/constants.go @@ -1,6 +1,10 @@ package securitymlanalyticssettings -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -49,6 +53,19 @@ func PossibleValuesForAttackTactic() []string { } } +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAttackTactic(input string) (*AttackTactic, error) { vals := map[string]AttackTactic{ "collection": AttackTacticCollection, @@ -90,6 +107,19 @@ func PossibleValuesForSecurityMLAnalyticsSettingsKind() []string { } } +func (s *SecurityMLAnalyticsSettingsKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSecurityMLAnalyticsSettingsKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSecurityMLAnalyticsSettingsKind(input string) (*SecurityMLAnalyticsSettingsKind, error) { vals := map[string]SecurityMLAnalyticsSettingsKind{ "anomaly": SecurityMLAnalyticsSettingsKindAnomaly, @@ -117,6 +147,19 @@ func PossibleValuesForSettingsStatus() []string { } } +func (s *SettingsStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSettingsStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSettingsStatus(input string) (*SettingsStatus, error) { vals := map[string]SettingsStatus{ "flighting": SettingsStatusFlighting, diff --git a/resource-manager/securityinsights/2023-11-01/securitymlanalyticssettings/method_createorupdate.go b/resource-manager/securityinsights/2023-11-01/securitymlanalyticssettings/method_createorupdate.go new file mode 100644 index 00000000000..f08267b7fac --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/securitymlanalyticssettings/method_createorupdate.go @@ -0,0 +1,63 @@ +package securitymlanalyticssettings + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SecurityMLAnalyticsSetting +} + +// CreateOrUpdate ... +func (c SecurityMLAnalyticsSettingsClient) CreateOrUpdate(ctx context.Context, id SecurityMLAnalyticsSettingId, input SecurityMLAnalyticsSetting) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalSecurityMLAnalyticsSettingImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/securitymlanalyticssettings/method_createorupdate_autorest.go b/resource-manager/securityinsights/2023-11-01/securitymlanalyticssettings/method_createorupdate_autorest.go deleted file mode 100644 index e72d9bcb79b..00000000000 --- a/resource-manager/securityinsights/2023-11-01/securitymlanalyticssettings/method_createorupdate_autorest.go +++ /dev/null @@ -1,78 +0,0 @@ -package securitymlanalyticssettings - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *SecurityMLAnalyticsSetting -} - -// CreateOrUpdate ... -func (c SecurityMLAnalyticsSettingsClient) CreateOrUpdate(ctx context.Context, id SecurityMLAnalyticsSettingId, input SecurityMLAnalyticsSetting) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c SecurityMLAnalyticsSettingsClient) preparerForCreateOrUpdate(ctx context.Context, id SecurityMLAnalyticsSettingId, input SecurityMLAnalyticsSetting) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c SecurityMLAnalyticsSettingsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalSecurityMLAnalyticsSettingImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2023-11-01/securitymlanalyticssettings/method_delete.go b/resource-manager/securityinsights/2023-11-01/securitymlanalyticssettings/method_delete.go new file mode 100644 index 00000000000..36309ecb138 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/securitymlanalyticssettings/method_delete.go @@ -0,0 +1,47 @@ +package securitymlanalyticssettings + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c SecurityMLAnalyticsSettingsClient) Delete(ctx context.Context, id SecurityMLAnalyticsSettingId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/securitymlanalyticssettings/method_delete_autorest.go b/resource-manager/securityinsights/2023-11-01/securitymlanalyticssettings/method_delete_autorest.go deleted file mode 100644 index a2b0d18f72f..00000000000 --- a/resource-manager/securityinsights/2023-11-01/securitymlanalyticssettings/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package securitymlanalyticssettings - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c SecurityMLAnalyticsSettingsClient) Delete(ctx context.Context, id SecurityMLAnalyticsSettingId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c SecurityMLAnalyticsSettingsClient) preparerForDelete(ctx context.Context, id SecurityMLAnalyticsSettingId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c SecurityMLAnalyticsSettingsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/securitymlanalyticssettings/method_get.go b/resource-manager/securityinsights/2023-11-01/securitymlanalyticssettings/method_get.go new file mode 100644 index 00000000000..9be89fdf974 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/securitymlanalyticssettings/method_get.go @@ -0,0 +1,58 @@ +package securitymlanalyticssettings + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SecurityMLAnalyticsSetting +} + +// Get ... +func (c SecurityMLAnalyticsSettingsClient) Get(ctx context.Context, id SecurityMLAnalyticsSettingId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalSecurityMLAnalyticsSettingImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/securitymlanalyticssettings/method_get_autorest.go b/resource-manager/securityinsights/2023-11-01/securitymlanalyticssettings/method_get_autorest.go deleted file mode 100644 index 0157220a0eb..00000000000 --- a/resource-manager/securityinsights/2023-11-01/securitymlanalyticssettings/method_get_autorest.go +++ /dev/null @@ -1,77 +0,0 @@ -package securitymlanalyticssettings - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *SecurityMLAnalyticsSetting -} - -// Get ... -func (c SecurityMLAnalyticsSettingsClient) Get(ctx context.Context, id SecurityMLAnalyticsSettingId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c SecurityMLAnalyticsSettingsClient) preparerForGet(ctx context.Context, id SecurityMLAnalyticsSettingId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c SecurityMLAnalyticsSettingsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalSecurityMLAnalyticsSettingImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2023-11-01/securitymlanalyticssettings/method_list.go b/resource-manager/securityinsights/2023-11-01/securitymlanalyticssettings/method_list.go new file mode 100644 index 00000000000..49878345af3 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/securitymlanalyticssettings/method_list.go @@ -0,0 +1,103 @@ +package securitymlanalyticssettings + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SecurityMLAnalyticsSetting +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []SecurityMLAnalyticsSetting +} + +// List ... +func (c SecurityMLAnalyticsSettingsClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/securityMLAnalyticsSettings", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]SecurityMLAnalyticsSetting, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalSecurityMLAnalyticsSettingImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for SecurityMLAnalyticsSetting (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// ListComplete retrieves all the results into a single object +func (c SecurityMLAnalyticsSettingsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, SecurityMLAnalyticsSettingOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SecurityMLAnalyticsSettingsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate SecurityMLAnalyticsSettingOperationPredicate) (result ListCompleteResult, err error) { + items := make([]SecurityMLAnalyticsSetting, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2023-11-01/securitymlanalyticssettings/method_list_autorest.go b/resource-manager/securityinsights/2023-11-01/securitymlanalyticssettings/method_list_autorest.go deleted file mode 100644 index 127297aa869..00000000000 --- a/resource-manager/securityinsights/2023-11-01/securitymlanalyticssettings/method_list_autorest.go +++ /dev/null @@ -1,196 +0,0 @@ -package securitymlanalyticssettings - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]SecurityMLAnalyticsSetting - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []SecurityMLAnalyticsSetting -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c SecurityMLAnalyticsSettingsClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c SecurityMLAnalyticsSettingsClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/securityMLAnalyticsSettings", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c SecurityMLAnalyticsSettingsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c SecurityMLAnalyticsSettingsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]SecurityMLAnalyticsSetting, 0) - for i, v := range respObj.Values { - val, err := unmarshalSecurityMLAnalyticsSettingImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for SecurityMLAnalyticsSetting (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c SecurityMLAnalyticsSettingsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, SecurityMLAnalyticsSettingOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c SecurityMLAnalyticsSettingsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate SecurityMLAnalyticsSettingOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]SecurityMLAnalyticsSetting, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2023-11-01/sentinelonboardingstates/client.go b/resource-manager/securityinsights/2023-11-01/sentinelonboardingstates/client.go index 0ae442ba3fa..94701ed853a 100644 --- a/resource-manager/securityinsights/2023-11-01/sentinelonboardingstates/client.go +++ b/resource-manager/securityinsights/2023-11-01/sentinelonboardingstates/client.go @@ -1,18 +1,26 @@ package sentinelonboardingstates -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type SentinelOnboardingStatesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewSentinelOnboardingStatesClientWithBaseURI(endpoint string) SentinelOnboardingStatesClient { - return SentinelOnboardingStatesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewSentinelOnboardingStatesClientWithBaseURI(sdkApi sdkEnv.Api) (*SentinelOnboardingStatesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sentinelonboardingstates", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SentinelOnboardingStatesClient: %+v", err) } + + return &SentinelOnboardingStatesClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2023-11-01/sentinelonboardingstates/method_create.go b/resource-manager/securityinsights/2023-11-01/sentinelonboardingstates/method_create.go new file mode 100644 index 00000000000..af163a9d66b --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/sentinelonboardingstates/method_create.go @@ -0,0 +1,56 @@ +package sentinelonboardingstates + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SentinelOnboardingState +} + +// Create ... +func (c SentinelOnboardingStatesClient) Create(ctx context.Context, id OnboardingStateId, input SentinelOnboardingState) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/sentinelonboardingstates/method_create_autorest.go b/resource-manager/securityinsights/2023-11-01/sentinelonboardingstates/method_create_autorest.go deleted file mode 100644 index 9ad88e95157..00000000000 --- a/resource-manager/securityinsights/2023-11-01/sentinelonboardingstates/method_create_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package sentinelonboardingstates - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOperationResponse struct { - HttpResponse *http.Response - Model *SentinelOnboardingState -} - -// Create ... -func (c SentinelOnboardingStatesClient) Create(ctx context.Context, id OnboardingStateId, input SentinelOnboardingState) (result CreateOperationResponse, err error) { - req, err := c.preparerForCreate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Create", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Create", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Create", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreate prepares the Create request. -func (c SentinelOnboardingStatesClient) preparerForCreate(ctx context.Context, id OnboardingStateId, input SentinelOnboardingState) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreate handles the response to the Create request. The method always -// closes the http.Response Body. -func (c SentinelOnboardingStatesClient) responderForCreate(resp *http.Response) (result CreateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/sentinelonboardingstates/method_delete.go b/resource-manager/securityinsights/2023-11-01/sentinelonboardingstates/method_delete.go new file mode 100644 index 00000000000..1c6c5e372d7 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/sentinelonboardingstates/method_delete.go @@ -0,0 +1,47 @@ +package sentinelonboardingstates + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c SentinelOnboardingStatesClient) Delete(ctx context.Context, id OnboardingStateId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/sentinelonboardingstates/method_delete_autorest.go b/resource-manager/securityinsights/2023-11-01/sentinelonboardingstates/method_delete_autorest.go deleted file mode 100644 index 65fa74282f7..00000000000 --- a/resource-manager/securityinsights/2023-11-01/sentinelonboardingstates/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package sentinelonboardingstates - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c SentinelOnboardingStatesClient) Delete(ctx context.Context, id OnboardingStateId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c SentinelOnboardingStatesClient) preparerForDelete(ctx context.Context, id OnboardingStateId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c SentinelOnboardingStatesClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/sentinelonboardingstates/method_get.go b/resource-manager/securityinsights/2023-11-01/sentinelonboardingstates/method_get.go new file mode 100644 index 00000000000..82165662910 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/sentinelonboardingstates/method_get.go @@ -0,0 +1,51 @@ +package sentinelonboardingstates + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SentinelOnboardingState +} + +// Get ... +func (c SentinelOnboardingStatesClient) Get(ctx context.Context, id OnboardingStateId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/sentinelonboardingstates/method_get_autorest.go b/resource-manager/securityinsights/2023-11-01/sentinelonboardingstates/method_get_autorest.go deleted file mode 100644 index d6174a7522a..00000000000 --- a/resource-manager/securityinsights/2023-11-01/sentinelonboardingstates/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package sentinelonboardingstates - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *SentinelOnboardingState -} - -// Get ... -func (c SentinelOnboardingStatesClient) Get(ctx context.Context, id OnboardingStateId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c SentinelOnboardingStatesClient) preparerForGet(ctx context.Context, id OnboardingStateId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c SentinelOnboardingStatesClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/sentinelonboardingstates/method_list.go b/resource-manager/securityinsights/2023-11-01/sentinelonboardingstates/method_list.go new file mode 100644 index 00000000000..2efd1d41230 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/sentinelonboardingstates/method_list.go @@ -0,0 +1,52 @@ +package sentinelonboardingstates + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SentinelOnboardingStatesList +} + +// List ... +func (c SentinelOnboardingStatesClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/onboardingStates", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/sentinelonboardingstates/method_list_autorest.go b/resource-manager/securityinsights/2023-11-01/sentinelonboardingstates/method_list_autorest.go deleted file mode 100644 index 6a00bb3d3fd..00000000000 --- a/resource-manager/securityinsights/2023-11-01/sentinelonboardingstates/method_list_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package sentinelonboardingstates - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *SentinelOnboardingStatesList -} - -// List ... -func (c SentinelOnboardingStatesClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sentinelonboardingstates.SentinelOnboardingStatesClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForList prepares the List request. -func (c SentinelOnboardingStatesClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/onboardingStates", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c SentinelOnboardingStatesClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/sourcecontrols/client.go b/resource-manager/securityinsights/2023-11-01/sourcecontrols/client.go index c0d5d5424c2..9bfd651a63a 100644 --- a/resource-manager/securityinsights/2023-11-01/sourcecontrols/client.go +++ b/resource-manager/securityinsights/2023-11-01/sourcecontrols/client.go @@ -1,18 +1,26 @@ package sourcecontrols -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type SourceControlsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewSourceControlsClientWithBaseURI(endpoint string) SourceControlsClient { - return SourceControlsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewSourceControlsClientWithBaseURI(sdkApi sdkEnv.Api) (*SourceControlsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sourcecontrols", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SourceControlsClient: %+v", err) } + + return &SourceControlsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2023-11-01/sourcecontrols/constants.go b/resource-manager/securityinsights/2023-11-01/sourcecontrols/constants.go index 1d52da56ea1..bdd26da2237 100644 --- a/resource-manager/securityinsights/2023-11-01/sourcecontrols/constants.go +++ b/resource-manager/securityinsights/2023-11-01/sourcecontrols/constants.go @@ -1,6 +1,10 @@ package sourcecontrols -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -27,6 +31,19 @@ func PossibleValuesForContentType() []string { } } +func (s *ContentType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseContentType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseContentType(input string) (*ContentType, error) { vals := map[string]ContentType{ "analyticrule": ContentTypeAnalyticRule, @@ -61,6 +78,19 @@ func PossibleValuesForDeploymentFetchStatus() []string { } } +func (s *DeploymentFetchStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeploymentFetchStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDeploymentFetchStatus(input string) (*DeploymentFetchStatus, error) { vals := map[string]DeploymentFetchStatus{ "notfound": DeploymentFetchStatusNotFound, @@ -92,6 +122,19 @@ func PossibleValuesForDeploymentResult() []string { } } +func (s *DeploymentResult) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeploymentResult(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDeploymentResult(input string) (*DeploymentResult, error) { vals := map[string]DeploymentResult{ "canceled": DeploymentResultCanceled, @@ -125,6 +168,19 @@ func PossibleValuesForDeploymentState() []string { } } +func (s *DeploymentState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeploymentState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDeploymentState(input string) (*DeploymentState, error) { vals := map[string]DeploymentState{ "canceling": DeploymentStateCanceling, @@ -155,6 +211,19 @@ func PossibleValuesForRepoType() []string { } } +func (s *RepoType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRepoType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseRepoType(input string) (*RepoType, error) { vals := map[string]RepoType{ "azuredevops": RepoTypeAzureDevOps, @@ -185,6 +254,19 @@ func PossibleValuesForRepositoryAccessKind() []string { } } +func (s *RepositoryAccessKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRepositoryAccessKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseRepositoryAccessKind(input string) (*RepositoryAccessKind, error) { vals := map[string]RepositoryAccessKind{ "app": RepositoryAccessKindApp, @@ -214,6 +296,19 @@ func PossibleValuesForState() []string { } } +func (s *State) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseState(input string) (*State, error) { vals := map[string]State{ "closed": StateClosed, @@ -242,6 +337,19 @@ func PossibleValuesForVersion() []string { } } +func (s *Version) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVersion(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseVersion(input string) (*Version, error) { vals := map[string]Version{ "v1": VersionVOne, @@ -276,6 +384,19 @@ func PossibleValuesForWarningCode() []string { } } +func (s *WarningCode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseWarningCode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseWarningCode(input string) (*WarningCode, error) { vals := map[string]WarningCode{ "sourcecontrol_deletedwithwarnings": WarningCodeSourceControlDeletedWithWarnings, diff --git a/resource-manager/securityinsights/2023-11-01/sourcecontrols/method_create.go b/resource-manager/securityinsights/2023-11-01/sourcecontrols/method_create.go new file mode 100644 index 00000000000..ee70a7cb64f --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/sourcecontrols/method_create.go @@ -0,0 +1,56 @@ +package sourcecontrols + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SourceControl +} + +// Create ... +func (c SourceControlsClient) Create(ctx context.Context, id SourceControlId, input SourceControl) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/sourcecontrols/method_create_autorest.go b/resource-manager/securityinsights/2023-11-01/sourcecontrols/method_create_autorest.go deleted file mode 100644 index fbf91a3cc21..00000000000 --- a/resource-manager/securityinsights/2023-11-01/sourcecontrols/method_create_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package sourcecontrols - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOperationResponse struct { - HttpResponse *http.Response - Model *SourceControl -} - -// Create ... -func (c SourceControlsClient) Create(ctx context.Context, id SourceControlId, input SourceControl) (result CreateOperationResponse, err error) { - req, err := c.preparerForCreate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "Create", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "Create", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "Create", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreate prepares the Create request. -func (c SourceControlsClient) preparerForCreate(ctx context.Context, id SourceControlId, input SourceControl) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreate handles the response to the Create request. The method always -// closes the http.Response Body. -func (c SourceControlsClient) responderForCreate(resp *http.Response) (result CreateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/sourcecontrols/method_delete.go b/resource-manager/securityinsights/2023-11-01/sourcecontrols/method_delete.go new file mode 100644 index 00000000000..326fc29968e --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/sourcecontrols/method_delete.go @@ -0,0 +1,56 @@ +package sourcecontrols + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Warning +} + +// Delete ... +func (c SourceControlsClient) Delete(ctx context.Context, id SourceControlId, input RepositoryAccessProperties) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/delete", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/sourcecontrols/method_delete_autorest.go b/resource-manager/securityinsights/2023-11-01/sourcecontrols/method_delete_autorest.go deleted file mode 100644 index 14192c1205a..00000000000 --- a/resource-manager/securityinsights/2023-11-01/sourcecontrols/method_delete_autorest.go +++ /dev/null @@ -1,70 +0,0 @@ -package sourcecontrols - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response - Model *Warning -} - -// Delete ... -func (c SourceControlsClient) Delete(ctx context.Context, id SourceControlId, input RepositoryAccessProperties) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c SourceControlsClient) preparerForDelete(ctx context.Context, id SourceControlId, input RepositoryAccessProperties) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/delete", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c SourceControlsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/sourcecontrols/method_get.go b/resource-manager/securityinsights/2023-11-01/sourcecontrols/method_get.go new file mode 100644 index 00000000000..3a1cb1bf276 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/sourcecontrols/method_get.go @@ -0,0 +1,51 @@ +package sourcecontrols + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SourceControl +} + +// Get ... +func (c SourceControlsClient) Get(ctx context.Context, id SourceControlId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/sourcecontrols/method_get_autorest.go b/resource-manager/securityinsights/2023-11-01/sourcecontrols/method_get_autorest.go deleted file mode 100644 index 80b8d99a662..00000000000 --- a/resource-manager/securityinsights/2023-11-01/sourcecontrols/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package sourcecontrols - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *SourceControl -} - -// Get ... -func (c SourceControlsClient) Get(ctx context.Context, id SourceControlId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c SourceControlsClient) preparerForGet(ctx context.Context, id SourceControlId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c SourceControlsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/sourcecontrols/method_list.go b/resource-manager/securityinsights/2023-11-01/sourcecontrols/method_list.go new file mode 100644 index 00000000000..f058d0ec61e --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/sourcecontrols/method_list.go @@ -0,0 +1,91 @@ +package sourcecontrols + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SourceControl +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []SourceControl +} + +// List ... +func (c SourceControlsClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/sourceControls", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]SourceControl `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c SourceControlsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, SourceControlOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SourceControlsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate SourceControlOperationPredicate) (result ListCompleteResult, err error) { + items := make([]SourceControl, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2023-11-01/sourcecontrols/method_list_autorest.go b/resource-manager/securityinsights/2023-11-01/sourcecontrols/method_list_autorest.go deleted file mode 100644 index 04f2a205623..00000000000 --- a/resource-manager/securityinsights/2023-11-01/sourcecontrols/method_list_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package sourcecontrols - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]SourceControl - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []SourceControl -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c SourceControlsClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c SourceControlsClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/sourceControls", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c SourceControlsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c SourceControlsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []SourceControl `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sourcecontrols.SourceControlsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c SourceControlsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, SourceControlOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c SourceControlsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate SourceControlOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]SourceControl, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2023-11-01/threatintelligence/client.go b/resource-manager/securityinsights/2023-11-01/threatintelligence/client.go index 35caff31357..edf96c3143f 100644 --- a/resource-manager/securityinsights/2023-11-01/threatintelligence/client.go +++ b/resource-manager/securityinsights/2023-11-01/threatintelligence/client.go @@ -1,18 +1,26 @@ package threatintelligence -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type ThreatIntelligenceClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewThreatIntelligenceClientWithBaseURI(endpoint string) ThreatIntelligenceClient { - return ThreatIntelligenceClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewThreatIntelligenceClientWithBaseURI(sdkApi sdkEnv.Api) (*ThreatIntelligenceClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "threatintelligence", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ThreatIntelligenceClient: %+v", err) } + + return &ThreatIntelligenceClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2023-11-01/threatintelligence/constants.go b/resource-manager/securityinsights/2023-11-01/threatintelligence/constants.go index 76610b31101..8cef3ba3f75 100644 --- a/resource-manager/securityinsights/2023-11-01/threatintelligence/constants.go +++ b/resource-manager/securityinsights/2023-11-01/threatintelligence/constants.go @@ -1,6 +1,10 @@ package threatintelligence -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -17,6 +21,19 @@ func PossibleValuesForThreatIntelligenceResourceInnerKind() []string { } } +func (s *ThreatIntelligenceResourceInnerKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseThreatIntelligenceResourceInnerKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseThreatIntelligenceResourceInnerKind(input string) (*ThreatIntelligenceResourceInnerKind, error) { vals := map[string]ThreatIntelligenceResourceInnerKind{ "indicator": ThreatIntelligenceResourceInnerKindIndicator, @@ -46,6 +63,19 @@ func PossibleValuesForThreatIntelligenceSortingOrder() []string { } } +func (s *ThreatIntelligenceSortingOrder) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseThreatIntelligenceSortingOrder(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseThreatIntelligenceSortingOrder(input string) (*ThreatIntelligenceSortingOrder, error) { vals := map[string]ThreatIntelligenceSortingOrder{ "ascending": ThreatIntelligenceSortingOrderAscending, diff --git a/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatorappendtags.go b/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatorappendtags.go new file mode 100644 index 00000000000..4384327485d --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatorappendtags.go @@ -0,0 +1,51 @@ +package threatintelligence + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorAppendTagsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// IndicatorAppendTags ... +func (c ThreatIntelligenceClient) IndicatorAppendTags(ctx context.Context, id IndicatorId, input ThreatIntelligenceAppendTags) (result IndicatorAppendTagsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/appendTags", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatorappendtags_autorest.go b/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatorappendtags_autorest.go deleted file mode 100644 index 18b86a166fe..00000000000 --- a/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatorappendtags_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package threatintelligence - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorAppendTagsOperationResponse struct { - HttpResponse *http.Response -} - -// IndicatorAppendTags ... -func (c ThreatIntelligenceClient) IndicatorAppendTags(ctx context.Context, id IndicatorId, input ThreatIntelligenceAppendTags) (result IndicatorAppendTagsOperationResponse, err error) { - req, err := c.preparerForIndicatorAppendTags(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorAppendTags", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorAppendTags", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorAppendTags(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorAppendTags", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorAppendTags prepares the IndicatorAppendTags request. -func (c ThreatIntelligenceClient) preparerForIndicatorAppendTags(ctx context.Context, id IndicatorId, input ThreatIntelligenceAppendTags) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/appendTags", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorAppendTags handles the response to the IndicatorAppendTags request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorAppendTags(resp *http.Response) (result IndicatorAppendTagsOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatorcreate.go b/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatorcreate.go new file mode 100644 index 00000000000..3cee598931c --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatorcreate.go @@ -0,0 +1,63 @@ +package threatintelligence + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorCreateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ThreatIntelligenceInformation +} + +// IndicatorCreate ... +func (c ThreatIntelligenceClient) IndicatorCreate(ctx context.Context, id IndicatorId, input ThreatIntelligenceIndicatorModel) (result IndicatorCreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatorcreate_autorest.go b/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatorcreate_autorest.go deleted file mode 100644 index 98609062b7f..00000000000 --- a/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatorcreate_autorest.go +++ /dev/null @@ -1,78 +0,0 @@ -package threatintelligence - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorCreateOperationResponse struct { - HttpResponse *http.Response - Model *ThreatIntelligenceInformation -} - -// IndicatorCreate ... -func (c ThreatIntelligenceClient) IndicatorCreate(ctx context.Context, id IndicatorId, input ThreatIntelligenceIndicatorModel) (result IndicatorCreateOperationResponse, err error) { - req, err := c.preparerForIndicatorCreate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorCreate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorCreate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorCreate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorCreate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorCreate prepares the IndicatorCreate request. -func (c ThreatIntelligenceClient) preparerForIndicatorCreate(ctx context.Context, id IndicatorId, input ThreatIntelligenceIndicatorModel) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorCreate handles the response to the IndicatorCreate request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorCreate(resp *http.Response) (result IndicatorCreateOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatorcreateindicator.go b/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatorcreateindicator.go new file mode 100644 index 00000000000..0f3ab94c4f5 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatorcreateindicator.go @@ -0,0 +1,63 @@ +package threatintelligence + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorCreateIndicatorOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ThreatIntelligenceInformation +} + +// IndicatorCreateIndicator ... +func (c ThreatIntelligenceClient) IndicatorCreateIndicator(ctx context.Context, id WorkspaceId, input ThreatIntelligenceIndicatorModel) (result IndicatorCreateIndicatorOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/createIndicator", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatorcreateindicator_autorest.go b/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatorcreateindicator_autorest.go deleted file mode 100644 index ecc76b88f5c..00000000000 --- a/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatorcreateindicator_autorest.go +++ /dev/null @@ -1,79 +0,0 @@ -package threatintelligence - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorCreateIndicatorOperationResponse struct { - HttpResponse *http.Response - Model *ThreatIntelligenceInformation -} - -// IndicatorCreateIndicator ... -func (c ThreatIntelligenceClient) IndicatorCreateIndicator(ctx context.Context, id WorkspaceId, input ThreatIntelligenceIndicatorModel) (result IndicatorCreateIndicatorOperationResponse, err error) { - req, err := c.preparerForIndicatorCreateIndicator(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorCreateIndicator", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorCreateIndicator", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorCreateIndicator(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorCreateIndicator", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorCreateIndicator prepares the IndicatorCreateIndicator request. -func (c ThreatIntelligenceClient) preparerForIndicatorCreateIndicator(ctx context.Context, id WorkspaceId, input ThreatIntelligenceIndicatorModel) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/createIndicator", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorCreateIndicator handles the response to the IndicatorCreateIndicator request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorCreateIndicator(resp *http.Response) (result IndicatorCreateIndicatorOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatordelete.go b/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatordelete.go new file mode 100644 index 00000000000..4de264524d5 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatordelete.go @@ -0,0 +1,47 @@ +package threatintelligence + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// IndicatorDelete ... +func (c ThreatIntelligenceClient) IndicatorDelete(ctx context.Context, id IndicatorId) (result IndicatorDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatordelete_autorest.go b/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatordelete_autorest.go deleted file mode 100644 index 825d3b911ce..00000000000 --- a/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatordelete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package threatintelligence - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorDeleteOperationResponse struct { - HttpResponse *http.Response -} - -// IndicatorDelete ... -func (c ThreatIntelligenceClient) IndicatorDelete(ctx context.Context, id IndicatorId) (result IndicatorDeleteOperationResponse, err error) { - req, err := c.preparerForIndicatorDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorDelete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorDelete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorDelete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorDelete prepares the IndicatorDelete request. -func (c ThreatIntelligenceClient) preparerForIndicatorDelete(ctx context.Context, id IndicatorId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorDelete handles the response to the IndicatorDelete request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorDelete(resp *http.Response) (result IndicatorDeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatorget.go b/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatorget.go new file mode 100644 index 00000000000..3358363f139 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatorget.go @@ -0,0 +1,58 @@ +package threatintelligence + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ThreatIntelligenceInformation +} + +// IndicatorGet ... +func (c ThreatIntelligenceClient) IndicatorGet(ctx context.Context, id IndicatorId) (result IndicatorGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatorget_autorest.go b/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatorget_autorest.go deleted file mode 100644 index ac1187fb285..00000000000 --- a/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatorget_autorest.go +++ /dev/null @@ -1,77 +0,0 @@ -package threatintelligence - -import ( - "context" - "encoding/json" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorGetOperationResponse struct { - HttpResponse *http.Response - Model *ThreatIntelligenceInformation -} - -// IndicatorGet ... -func (c ThreatIntelligenceClient) IndicatorGet(ctx context.Context, id IndicatorId) (result IndicatorGetOperationResponse, err error) { - req, err := c.preparerForIndicatorGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorGet", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorGet", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorGet", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorGet prepares the IndicatorGet request. -func (c ThreatIntelligenceClient) preparerForIndicatorGet(ctx context.Context, id IndicatorId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorGet handles the response to the IndicatorGet request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorGet(resp *http.Response) (result IndicatorGetOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatormetricslist.go b/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatormetricslist.go new file mode 100644 index 00000000000..688ff3c16d1 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatormetricslist.go @@ -0,0 +1,52 @@ +package threatintelligence + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorMetricsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ThreatIntelligenceMetricsList +} + +// IndicatorMetricsList ... +func (c ThreatIntelligenceClient) IndicatorMetricsList(ctx context.Context, id WorkspaceId) (result IndicatorMetricsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/metrics", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatormetricslist_autorest.go b/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatormetricslist_autorest.go deleted file mode 100644 index 1835c26ed96..00000000000 --- a/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatormetricslist_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package threatintelligence - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorMetricsListOperationResponse struct { - HttpResponse *http.Response - Model *ThreatIntelligenceMetricsList -} - -// IndicatorMetricsList ... -func (c ThreatIntelligenceClient) IndicatorMetricsList(ctx context.Context, id WorkspaceId) (result IndicatorMetricsListOperationResponse, err error) { - req, err := c.preparerForIndicatorMetricsList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorMetricsList", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorMetricsList", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorMetricsList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorMetricsList", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorMetricsList prepares the IndicatorMetricsList request. -func (c ThreatIntelligenceClient) preparerForIndicatorMetricsList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/metrics", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorMetricsList handles the response to the IndicatorMetricsList request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorMetricsList(resp *http.Response) (result IndicatorMetricsListOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatorqueryindicators.go b/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatorqueryindicators.go new file mode 100644 index 00000000000..8ce639f2623 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatorqueryindicators.go @@ -0,0 +1,103 @@ +package threatintelligence + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorQueryIndicatorsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ThreatIntelligenceInformation +} + +type IndicatorQueryIndicatorsCompleteResult struct { + LatestHttpResponse *http.Response + Items []ThreatIntelligenceInformation +} + +// IndicatorQueryIndicators ... +func (c ThreatIntelligenceClient) IndicatorQueryIndicators(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria) (result IndicatorQueryIndicatorsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/queryIndicators", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]ThreatIntelligenceInformation, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalThreatIntelligenceInformationImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for ThreatIntelligenceInformation (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// IndicatorQueryIndicatorsComplete retrieves all the results into a single object +func (c ThreatIntelligenceClient) IndicatorQueryIndicatorsComplete(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria) (IndicatorQueryIndicatorsCompleteResult, error) { + return c.IndicatorQueryIndicatorsCompleteMatchingPredicate(ctx, id, input, ThreatIntelligenceInformationOperationPredicate{}) +} + +// IndicatorQueryIndicatorsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ThreatIntelligenceClient) IndicatorQueryIndicatorsCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria, predicate ThreatIntelligenceInformationOperationPredicate) (result IndicatorQueryIndicatorsCompleteResult, err error) { + items := make([]ThreatIntelligenceInformation, 0) + + resp, err := c.IndicatorQueryIndicators(ctx, id, input) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = IndicatorQueryIndicatorsCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatorqueryindicators_autorest.go b/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatorqueryindicators_autorest.go deleted file mode 100644 index fcbe7c74758..00000000000 --- a/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatorqueryindicators_autorest.go +++ /dev/null @@ -1,197 +0,0 @@ -package threatintelligence - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorQueryIndicatorsOperationResponse struct { - HttpResponse *http.Response - Model *[]ThreatIntelligenceInformation - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (IndicatorQueryIndicatorsOperationResponse, error) -} - -type IndicatorQueryIndicatorsCompleteResult struct { - Items []ThreatIntelligenceInformation -} - -func (r IndicatorQueryIndicatorsOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r IndicatorQueryIndicatorsOperationResponse) LoadMore(ctx context.Context) (resp IndicatorQueryIndicatorsOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// IndicatorQueryIndicators ... -func (c ThreatIntelligenceClient) IndicatorQueryIndicators(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria) (resp IndicatorQueryIndicatorsOperationResponse, err error) { - req, err := c.preparerForIndicatorQueryIndicators(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorQueryIndicators", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorQueryIndicators", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForIndicatorQueryIndicators(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorQueryIndicators", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForIndicatorQueryIndicators prepares the IndicatorQueryIndicators request. -func (c ThreatIntelligenceClient) preparerForIndicatorQueryIndicators(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/queryIndicators", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForIndicatorQueryIndicatorsWithNextLink prepares the IndicatorQueryIndicators request with the given nextLink token. -func (c ThreatIntelligenceClient) preparerForIndicatorQueryIndicatorsWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorQueryIndicators handles the response to the IndicatorQueryIndicators request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorQueryIndicators(resp *http.Response) (result IndicatorQueryIndicatorsOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]ThreatIntelligenceInformation, 0) - for i, v := range respObj.Values { - val, err := unmarshalThreatIntelligenceInformationImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for ThreatIntelligenceInformation (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result IndicatorQueryIndicatorsOperationResponse, err error) { - req, err := c.preparerForIndicatorQueryIndicatorsWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorQueryIndicators", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorQueryIndicators", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorQueryIndicators(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorQueryIndicators", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// IndicatorQueryIndicatorsComplete retrieves all of the results into a single object -func (c ThreatIntelligenceClient) IndicatorQueryIndicatorsComplete(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria) (IndicatorQueryIndicatorsCompleteResult, error) { - return c.IndicatorQueryIndicatorsCompleteMatchingPredicate(ctx, id, input, ThreatIntelligenceInformationOperationPredicate{}) -} - -// IndicatorQueryIndicatorsCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c ThreatIntelligenceClient) IndicatorQueryIndicatorsCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria, predicate ThreatIntelligenceInformationOperationPredicate) (resp IndicatorQueryIndicatorsCompleteResult, err error) { - items := make([]ThreatIntelligenceInformation, 0) - - page, err := c.IndicatorQueryIndicators(ctx, id, input) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := IndicatorQueryIndicatorsCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatorreplacetags.go b/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatorreplacetags.go new file mode 100644 index 00000000000..052bbe7b66a --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatorreplacetags.go @@ -0,0 +1,63 @@ +package threatintelligence + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorReplaceTagsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ThreatIntelligenceInformation +} + +// IndicatorReplaceTags ... +func (c ThreatIntelligenceClient) IndicatorReplaceTags(ctx context.Context, id IndicatorId, input ThreatIntelligenceIndicatorModel) (result IndicatorReplaceTagsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/replaceTags", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatorreplacetags_autorest.go b/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatorreplacetags_autorest.go deleted file mode 100644 index 01efbe5b778..00000000000 --- a/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatorreplacetags_autorest.go +++ /dev/null @@ -1,79 +0,0 @@ -package threatintelligence - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorReplaceTagsOperationResponse struct { - HttpResponse *http.Response - Model *ThreatIntelligenceInformation -} - -// IndicatorReplaceTags ... -func (c ThreatIntelligenceClient) IndicatorReplaceTags(ctx context.Context, id IndicatorId, input ThreatIntelligenceIndicatorModel) (result IndicatorReplaceTagsOperationResponse, err error) { - req, err := c.preparerForIndicatorReplaceTags(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorReplaceTags", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorReplaceTags", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorReplaceTags(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorReplaceTags", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForIndicatorReplaceTags prepares the IndicatorReplaceTags request. -func (c ThreatIntelligenceClient) preparerForIndicatorReplaceTags(ctx context.Context, id IndicatorId, input ThreatIntelligenceIndicatorModel) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/replaceTags", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorReplaceTags handles the response to the IndicatorReplaceTags request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorReplaceTags(resp *http.Response) (result IndicatorReplaceTagsOperationResponse, err error) { - var respObj json.RawMessage - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - if err != nil { - return - } - model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) - if err != nil { - return - } - result.Model = &model - return -} diff --git a/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatorslist.go b/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatorslist.go new file mode 100644 index 00000000000..860ecd26255 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatorslist.go @@ -0,0 +1,139 @@ +package threatintelligence + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ThreatIntelligenceInformation +} + +type IndicatorsListCompleteResult struct { + LatestHttpResponse *http.Response + Items []ThreatIntelligenceInformation +} + +type IndicatorsListOperationOptions struct { + Filter *string + Orderby *string + Top *int64 +} + +func DefaultIndicatorsListOperationOptions() IndicatorsListOperationOptions { + return IndicatorsListOperationOptions{} +} + +func (o IndicatorsListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o IndicatorsListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o IndicatorsListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// IndicatorsList ... +func (c ThreatIntelligenceClient) IndicatorsList(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions) (result IndicatorsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/indicators", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]ThreatIntelligenceInformation, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalThreatIntelligenceInformationImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for ThreatIntelligenceInformation (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// IndicatorsListComplete retrieves all the results into a single object +func (c ThreatIntelligenceClient) IndicatorsListComplete(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions) (IndicatorsListCompleteResult, error) { + return c.IndicatorsListCompleteMatchingPredicate(ctx, id, options, ThreatIntelligenceInformationOperationPredicate{}) +} + +// IndicatorsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ThreatIntelligenceClient) IndicatorsListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions, predicate ThreatIntelligenceInformationOperationPredicate) (result IndicatorsListCompleteResult, err error) { + items := make([]ThreatIntelligenceInformation, 0) + + resp, err := c.IndicatorsList(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = IndicatorsListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatorslist_autorest.go b/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatorslist_autorest.go deleted file mode 100644 index 22ef9d7b193..00000000000 --- a/resource-manager/securityinsights/2023-11-01/threatintelligence/method_indicatorslist_autorest.go +++ /dev/null @@ -1,235 +0,0 @@ -package threatintelligence - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type IndicatorsListOperationResponse struct { - HttpResponse *http.Response - Model *[]ThreatIntelligenceInformation - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (IndicatorsListOperationResponse, error) -} - -type IndicatorsListCompleteResult struct { - Items []ThreatIntelligenceInformation -} - -func (r IndicatorsListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r IndicatorsListOperationResponse) LoadMore(ctx context.Context) (resp IndicatorsListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type IndicatorsListOperationOptions struct { - Filter *string - Orderby *string - Top *int64 -} - -func DefaultIndicatorsListOperationOptions() IndicatorsListOperationOptions { - return IndicatorsListOperationOptions{} -} - -func (o IndicatorsListOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o IndicatorsListOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Filter != nil { - out["$filter"] = *o.Filter - } - - if o.Orderby != nil { - out["$orderby"] = *o.Orderby - } - - if o.Top != nil { - out["$top"] = *o.Top - } - - return out -} - -// IndicatorsList ... -func (c ThreatIntelligenceClient) IndicatorsList(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions) (resp IndicatorsListOperationResponse, err error) { - req, err := c.preparerForIndicatorsList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForIndicatorsList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForIndicatorsList prepares the IndicatorsList request. -func (c ThreatIntelligenceClient) preparerForIndicatorsList(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/indicators", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForIndicatorsListWithNextLink prepares the IndicatorsList request with the given nextLink token. -func (c ThreatIntelligenceClient) preparerForIndicatorsListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForIndicatorsList handles the response to the IndicatorsList request. The method always -// closes the http.Response Body. -func (c ThreatIntelligenceClient) responderForIndicatorsList(resp *http.Response) (result IndicatorsListOperationResponse, err error) { - type page struct { - Values []json.RawMessage `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - temp := make([]ThreatIntelligenceInformation, 0) - for i, v := range respObj.Values { - val, err := unmarshalThreatIntelligenceInformationImplementation(v) - if err != nil { - err = fmt.Errorf("unmarshalling item %d for ThreatIntelligenceInformation (%q): %+v", i, v, err) - return result, err - } - temp = append(temp, val) - } - result.Model = &temp - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result IndicatorsListOperationResponse, err error) { - req, err := c.preparerForIndicatorsListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForIndicatorsList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "threatintelligence.ThreatIntelligenceClient", "IndicatorsList", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// IndicatorsListComplete retrieves all of the results into a single object -func (c ThreatIntelligenceClient) IndicatorsListComplete(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions) (IndicatorsListCompleteResult, error) { - return c.IndicatorsListCompleteMatchingPredicate(ctx, id, options, ThreatIntelligenceInformationOperationPredicate{}) -} - -// IndicatorsListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c ThreatIntelligenceClient) IndicatorsListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions, predicate ThreatIntelligenceInformationOperationPredicate) (resp IndicatorsListCompleteResult, err error) { - items := make([]ThreatIntelligenceInformation, 0) - - page, err := c.IndicatorsList(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := IndicatorsListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2023-11-01/watchlistitems/client.go b/resource-manager/securityinsights/2023-11-01/watchlistitems/client.go index 9403755456e..d3193694a48 100644 --- a/resource-manager/securityinsights/2023-11-01/watchlistitems/client.go +++ b/resource-manager/securityinsights/2023-11-01/watchlistitems/client.go @@ -1,18 +1,26 @@ package watchlistitems -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type WatchlistItemsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewWatchlistItemsClientWithBaseURI(endpoint string) WatchlistItemsClient { - return WatchlistItemsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewWatchlistItemsClientWithBaseURI(sdkApi sdkEnv.Api) (*WatchlistItemsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "watchlistitems", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating WatchlistItemsClient: %+v", err) } + + return &WatchlistItemsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2023-11-01/watchlistitems/method_createorupdate.go b/resource-manager/securityinsights/2023-11-01/watchlistitems/method_createorupdate.go new file mode 100644 index 00000000000..d02782f71bc --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/watchlistitems/method_createorupdate.go @@ -0,0 +1,56 @@ +package watchlistitems + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *WatchlistItem +} + +// CreateOrUpdate ... +func (c WatchlistItemsClient) CreateOrUpdate(ctx context.Context, id WatchlistItemId, input WatchlistItem) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/watchlistitems/method_createorupdate_autorest.go b/resource-manager/securityinsights/2023-11-01/watchlistitems/method_createorupdate_autorest.go deleted file mode 100644 index 15d8fdcc2be..00000000000 --- a/resource-manager/securityinsights/2023-11-01/watchlistitems/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package watchlistitems - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *WatchlistItem -} - -// CreateOrUpdate ... -func (c WatchlistItemsClient) CreateOrUpdate(ctx context.Context, id WatchlistItemId, input WatchlistItem) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c WatchlistItemsClient) preparerForCreateOrUpdate(ctx context.Context, id WatchlistItemId, input WatchlistItem) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c WatchlistItemsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/watchlistitems/method_delete.go b/resource-manager/securityinsights/2023-11-01/watchlistitems/method_delete.go new file mode 100644 index 00000000000..5565b767fa5 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/watchlistitems/method_delete.go @@ -0,0 +1,47 @@ +package watchlistitems + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c WatchlistItemsClient) Delete(ctx context.Context, id WatchlistItemId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/watchlistitems/method_delete_autorest.go b/resource-manager/securityinsights/2023-11-01/watchlistitems/method_delete_autorest.go deleted file mode 100644 index c9b8c46f9e5..00000000000 --- a/resource-manager/securityinsights/2023-11-01/watchlistitems/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package watchlistitems - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c WatchlistItemsClient) Delete(ctx context.Context, id WatchlistItemId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c WatchlistItemsClient) preparerForDelete(ctx context.Context, id WatchlistItemId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c WatchlistItemsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/watchlistitems/method_get.go b/resource-manager/securityinsights/2023-11-01/watchlistitems/method_get.go new file mode 100644 index 00000000000..ff9a8e143fa --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/watchlistitems/method_get.go @@ -0,0 +1,51 @@ +package watchlistitems + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *WatchlistItem +} + +// Get ... +func (c WatchlistItemsClient) Get(ctx context.Context, id WatchlistItemId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/watchlistitems/method_get_autorest.go b/resource-manager/securityinsights/2023-11-01/watchlistitems/method_get_autorest.go deleted file mode 100644 index b294f999f64..00000000000 --- a/resource-manager/securityinsights/2023-11-01/watchlistitems/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package watchlistitems - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *WatchlistItem -} - -// Get ... -func (c WatchlistItemsClient) Get(ctx context.Context, id WatchlistItemId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c WatchlistItemsClient) preparerForGet(ctx context.Context, id WatchlistItemId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c WatchlistItemsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/watchlistitems/method_list.go b/resource-manager/securityinsights/2023-11-01/watchlistitems/method_list.go new file mode 100644 index 00000000000..8a4d418ea0b --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/watchlistitems/method_list.go @@ -0,0 +1,91 @@ +package watchlistitems + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]WatchlistItem +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []WatchlistItem +} + +// List ... +func (c WatchlistItemsClient) List(ctx context.Context, id WatchlistId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/watchlistItems", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]WatchlistItem `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c WatchlistItemsClient) ListComplete(ctx context.Context, id WatchlistId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, WatchlistItemOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c WatchlistItemsClient) ListCompleteMatchingPredicate(ctx context.Context, id WatchlistId, predicate WatchlistItemOperationPredicate) (result ListCompleteResult, err error) { + items := make([]WatchlistItem, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2023-11-01/watchlistitems/method_list_autorest.go b/resource-manager/securityinsights/2023-11-01/watchlistitems/method_list_autorest.go deleted file mode 100644 index d8e4bf85bf1..00000000000 --- a/resource-manager/securityinsights/2023-11-01/watchlistitems/method_list_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package watchlistitems - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]WatchlistItem - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []WatchlistItem -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c WatchlistItemsClient) List(ctx context.Context, id WatchlistId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c WatchlistItemsClient) preparerForList(ctx context.Context, id WatchlistId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/watchlistItems", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c WatchlistItemsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c WatchlistItemsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []WatchlistItem `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlistitems.WatchlistItemsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c WatchlistItemsClient) ListComplete(ctx context.Context, id WatchlistId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, WatchlistItemOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c WatchlistItemsClient) ListCompleteMatchingPredicate(ctx context.Context, id WatchlistId, predicate WatchlistItemOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]WatchlistItem, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/securityinsights/2023-11-01/watchlists/client.go b/resource-manager/securityinsights/2023-11-01/watchlists/client.go index 61cfa3d0ac3..45211175054 100644 --- a/resource-manager/securityinsights/2023-11-01/watchlists/client.go +++ b/resource-manager/securityinsights/2023-11-01/watchlists/client.go @@ -1,18 +1,26 @@ package watchlists -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type WatchlistsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewWatchlistsClientWithBaseURI(endpoint string) WatchlistsClient { - return WatchlistsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewWatchlistsClientWithBaseURI(sdkApi sdkEnv.Api) (*WatchlistsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "watchlists", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating WatchlistsClient: %+v", err) } + + return &WatchlistsClient{ + Client: client, + }, nil } diff --git a/resource-manager/securityinsights/2023-11-01/watchlists/method_createorupdate.go b/resource-manager/securityinsights/2023-11-01/watchlists/method_createorupdate.go new file mode 100644 index 00000000000..cf0dc47e9d7 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/watchlists/method_createorupdate.go @@ -0,0 +1,56 @@ +package watchlists + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Watchlist +} + +// CreateOrUpdate ... +func (c WatchlistsClient) CreateOrUpdate(ctx context.Context, id WatchlistId, input Watchlist) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/watchlists/method_createorupdate_autorest.go b/resource-manager/securityinsights/2023-11-01/watchlists/method_createorupdate_autorest.go deleted file mode 100644 index e6d8a5976b8..00000000000 --- a/resource-manager/securityinsights/2023-11-01/watchlists/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package watchlists - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *Watchlist -} - -// CreateOrUpdate ... -func (c WatchlistsClient) CreateOrUpdate(ctx context.Context, id WatchlistId, input Watchlist) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c WatchlistsClient) preparerForCreateOrUpdate(ctx context.Context, id WatchlistId, input Watchlist) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c WatchlistsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/watchlists/method_delete.go b/resource-manager/securityinsights/2023-11-01/watchlists/method_delete.go new file mode 100644 index 00000000000..9d495f99c57 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/watchlists/method_delete.go @@ -0,0 +1,47 @@ +package watchlists + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c WatchlistsClient) Delete(ctx context.Context, id WatchlistId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/watchlists/method_delete_autorest.go b/resource-manager/securityinsights/2023-11-01/watchlists/method_delete_autorest.go deleted file mode 100644 index 56234124b82..00000000000 --- a/resource-manager/securityinsights/2023-11-01/watchlists/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package watchlists - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c WatchlistsClient) Delete(ctx context.Context, id WatchlistId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c WatchlistsClient) preparerForDelete(ctx context.Context, id WatchlistId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c WatchlistsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/watchlists/method_get.go b/resource-manager/securityinsights/2023-11-01/watchlists/method_get.go new file mode 100644 index 00000000000..39ec92feaeb --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/watchlists/method_get.go @@ -0,0 +1,51 @@ +package watchlists + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Watchlist +} + +// Get ... +func (c WatchlistsClient) Get(ctx context.Context, id WatchlistId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2023-11-01/watchlists/method_get_autorest.go b/resource-manager/securityinsights/2023-11-01/watchlists/method_get_autorest.go deleted file mode 100644 index d7253f62215..00000000000 --- a/resource-manager/securityinsights/2023-11-01/watchlists/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package watchlists - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *Watchlist -} - -// Get ... -func (c WatchlistsClient) Get(ctx context.Context, id WatchlistId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c WatchlistsClient) preparerForGet(ctx context.Context, id WatchlistId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c WatchlistsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/securityinsights/2023-11-01/watchlists/method_list.go b/resource-manager/securityinsights/2023-11-01/watchlists/method_list.go new file mode 100644 index 00000000000..9122b014815 --- /dev/null +++ b/resource-manager/securityinsights/2023-11-01/watchlists/method_list.go @@ -0,0 +1,91 @@ +package watchlists + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Watchlist +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Watchlist +} + +// List ... +func (c WatchlistsClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/watchlists", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Watchlist `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c WatchlistsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, WatchlistOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c WatchlistsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate WatchlistOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Watchlist, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2023-11-01/watchlists/method_list_autorest.go b/resource-manager/securityinsights/2023-11-01/watchlists/method_list_autorest.go deleted file mode 100644 index a3a2c27c15e..00000000000 --- a/resource-manager/securityinsights/2023-11-01/watchlists/method_list_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package watchlists - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]Watchlist - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []Watchlist -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c WatchlistsClient) List(ctx context.Context, id WorkspaceId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c WatchlistsClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/watchlists", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c WatchlistsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c WatchlistsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []Watchlist `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "watchlists.WatchlistsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c WatchlistsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, WatchlistOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c WatchlistsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate WatchlistOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]Watchlist, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -}